Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North America 2021

Ovadiah Myrgorod
Ovadiah MyrgorodDevOps Engineer at Georgetown University
Create a Varnish cluster in Kubernetes
for Drupal caching
Vadym Myrgorod
Slides: http://bit.ly/k8s-varnish-drupal
Vadym Myrgorod
Using Drupal since 2008
Web App Developer
Howard Hughes Medical Institute
@dealancer1
https://www.myrgorod.net
I will make a quick intro into Varnish and Kubernetes.
We will learn how to configure Varnish cluster for Drupal 8
and run it on Kubernetes platform.
In this session
what is
Varnish?
More users means slower website
Slower website means bigger bounce rate
1. Cutting visitors off
2. Arranging visitors in an online queue
3. Buying more hardware
Approaches we won’t cover in this session
In computing, a cache is a hardware or software
component that stores data so that future requests for
that data can be served faster; the data stored in a cache
might be the result of an earlier computation or a copy of
data stored elsewhere.
Caching
Levels of caching
1
Opcode Caching
Compile PHP script into opcode and cache it.
Examples: OPcache extension.
3
Drupal Caching
Store blocks, views and other Drupal
components in memory.
Examples: Memcache, Redis.
5
Content Delivery Network
Store static assets in geographically
distributed caching system.
Examples: Cloudflare, Fastly, Akamai.
2
Database Caching
Store results of SQL queries in memory.
Examples: memcached.
4
Static Content Caching
Store static assets in memory.
Examples: Varnish, Nginx.
● Aggregated CSS files
● Aggregated JS files
● Images of various image styles
● HTML pages (for anonymous users)
Static content generated by Drupal
● Caching HTTP reverse proxy
● Speeds up delivery with a factor of 300 - 1000x
● Varnish Configuration Language (VCL)
● Can be scaled into Varnish Cluster
Backend - server which is providing
the content Varnish will accelerate.
Frontend - client facing Varnish
server.
Terms
Backend
Frontend
vcl 4.0;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.http.host == "www.example.com") {
set req.backend_hint = default;
}
}
See following VCL example for Drupal 8 and 7:
https://www.varnish-software.com/wiki/content/tutorials/drupal/drupal_vcl.html
Minimal Varnish VCL
/etc/varnish/default.vcl
now let’s talk about
Kubernetes
1. You want to manage services you are running e.g. MySQL,
Varnish, Redis, Apache Solr, Elasticsearch...
2. You want to have an ability to migrate from one cloud
provider to another quickly.
3. You have on-premises infrastructure you need to utilize.
4. You want to use multicloud or hybrid-cloud approaches.
5. You want to have some of the cool features that
Kubernetes provides.
When using Kubernetes is a good idea
1. Scaling: runs more containers if needed.
2. Healing: restarts containers when they are down.
3. Deployment strategies: rolling updates, blue/green, canary...
4. Service discovery and load balancing: distributes access to
containers by service name.
5. Security: secret management, security policies.
6. Storage orchestration: cloud, NFS, or storage providers.
7. Flexibility and extensibility: Go is widely used in k8s world.
Things Kubernetes is good at
● Resource - endpoint in k8s API that stores a
collection of certain kind. Declared using YAML
syntax. Example: config map, secret, volume, volume
claim, pod, deployment, stateful set, service, ingress,
etc...
● Config map - stores software configuration that can
be mounted as files or passed as env variables.
● Volume - used to preserve file system after container
is restarted.
● Pod - k8s resource that represents running
container (or set set of containers).
Kubernetes resources
Config map
Pod
Deployment
Service
Ingress
Stateful Set
Volume
● Deployment - ensures certain amount of pods are
up and running.
● Stateful Set - acts as deployment for stateful
services that have specific requirements to storage
and pod identity.
● Service - provides a way to access deployments or
stateful sets using different behaviours. Creates a
common DNS record that can be used to access
pods and does load balancing.
● Ingress - manages external access to services using
various routing rules.
Kubernetes resources
Config map
Pod
Deployment
Service
Ingress
Stateful Set
Volume
nginx-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Minimal Kubernetes deployment and service
nginx-service.yaml:
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
type: NodePort
ports:
- protocol: TCP
port: 8080
targetPort: 80
nodePort: 30080
1. Apply deployment
$ kubectl apply -f nginx-deployment.yaml
2. Check deployments
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 0/2 0 0 1s
3. Check pods
$ kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nginx-deployment-75675f5897-7ci7o 1/1 Running 0 18s app=nginx,pod-template-hash=3123191453
nginx-deployment-75675f5897-kzszj 1/1 Running 0 18s app=nginx,pod-template-hash=3123191453
Minimal Kubernetes deployment and service
4. Apply service
$ kubectl apply -f nginx-service.yaml
5. Check services
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 41d
nginx-service NodePort 10.98.115.133 <none> 8080:30080/TCP 5m11s
6. Access nginx using node port
$ curl localhost:30080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
Minimal Kubernetes deployment and service
running
Varnish in Kubernetes
To run Varnish in k8s we need to declare app deployment, app
service, Varnish deployment, Varnish service, config maps and
ingress.
Example: https://github.com/dealancer/k8s-varnish-test.
The simplest approach
varnish-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: varnish-deployment
labels:
app: varnish
spec:
replicas: 1
selector:
matchLabels:
app: varnish
template:
metadata:
labels:
app: varnish
The simplest approach
spec:
containers:
- name: varnish
image: varnish:6.6.0
env:
- name: CACHE_SIZE
value: 128m
- name: VCL_CONFIG
value: /etc/varnish/configmap/default.vcl
volumeMounts:
- name: varnish-config
mountPath: /etc/varnish/configmap
ports:
- containerPort: 80
volumes:
- name: varnish-config
configMap:
name: varnish-configmap
varnish-configmap.yaml:
apiVersion: v1
kind: ConfigMap
metadata:
name: varnish-configmap
labels:
app: varnish
data:
default.vcl: |
vcl 4.0;
backend default {
.host = "nginx-service";
.port = "8080";
}
sub vcl_recv {
set req.backend_hint = default;
}
The simplest approach
varnish-service.yaml:
apiVersion: v1
kind: Service
metadata:
name: varnish-service
spec:
selector:
app: nginx
type: NodePort
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30081
Questions to this approach:
1. Can we eliminate App Service and let Varnish talk to
application pods (backends) directly?
2. How do we scale Varnish pods (frontends)?
3. How do we shard cache across multiple Varnish pods?
4. How do we invalidate cache in multiple Varnish pods?
The simplest approach
kube-httpcache is an open Source Kubernetes controller written in Go to run Varnish
cluster. It is a free solution comparing to Varnish Cache Plus, but it requires to configure
Varnish in certain way using VCL.
GitHub: https://github.com/mittwald/kube-httpcache.
Features:
● Monitors backend (app) and frontend (Varnish) pods.
● Dynamically update Varnish VCL and reload it on the the fly in all Varnish pods.
● Supports Go-template syntax in VCL file.
● Sends cache invalidation requests to all Varnish pods using Signaller component.
kube-httpcache
spec:
containers:
- name: cache
image: quay.io/mittwald/kube-httpcache:stable
imagePullPolicy: Always
args:
- -admin-addr=0.0.0.0
- -admin-port=6083
- -signaller-enable
- -signaller-port=8090
- -frontend-watch
- -frontend-namespace=$(NAMESPACE)
- -frontend-service=frontend-service
- -backend-watch
- -backend-namespace=$(NAMESPACE)
- -backend-service=backend-service
- -varnish-secret-file=/etc/varnish/k8s-secret/secret
- -varnish-vcl-template=/etc/varnish/tmpl/default.vcl.tmpl
- -varnish-storage=malloc,128M
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumeMounts:
- name: template
mountPath: /etc/varnish/tmpl
- name: secret
mountPath: /etc/varnish/k8s-secret
varnish-service.yaml (part)
{{ range .Backends }}
backend be-{{ .Name }} {
.host = "{{ .Host }}";
.port = "{{ .Port }}";
}
{{- end }}
{{ range .Frontends }}
backend {{ .Name }} {
.host = "{{ .Host }}";
.port = "{{ .Port }}";
}
{{- end }}
sub vcl_init {
new lb = directors.round_robin();
{{ range .Backends -}}
lb.add_backend(be-{{ .Name }});
{{ end }}
}
sub vcl_recv {
set req.backend_hint = lb.backend();
}
Eliminate the need in backend service
In this approach cache is sharded across multiple Varnish frontends.
1. Varnish Service routes requests to a random Varnish frontend.
2. A corresponding Varnish frontend (x-shard) determined based on the
URL using hash director:
a. http://example.com/foo -> frontend 1
b. http://example.com/bar -> frontend 2
c. http://example.com/bar2 -> frontend 1
3. If x-shard is not the current Varnish frontend, request is forwarded to
x-shard.
4. Otherwise, request is handled by the current Varnish node:
a. If request is cacheable and cache exist, cached content is returned.
b. If cache does not exists, Varnish requests a backend to save cache
and serve cached content.
c. If request is cacheable request is routed to a backend.
See https://info.varnish-software.com/blog/creating-self-routing-varnish-cluster
Running Varnish cluster (sharded cache)
sub vcl_init {
# ...
new cluster = directors.hash();
{{ range .Frontends -}}
cluster.add_backend({{ .Name }}, 1);
{{ end }}
}
sub vcl_recv {
set req.backend_hint = lb.backend();
# ...
unset req.http.x-cache;
set req.backend_hint = cluster.backend(req.url);
set req.http.x-shard = req.backend_hint;
if (req.http.x-shard != server.identity) {
return(pass);
}
set req.backend_hint = lb.backend();
# ...
return(hash);
}
Running Varnish cluster (sharded cache)
Problem
In case if you horizontally scale your Varnish cluster, a
hash director will recalculate hashes for existing URLs
and will route requests to different Varnish frontends
which do not store cached content for these URLs.
Thus users will experience slowdown.
Solution
Consistent caching mechanism is provided by Varnish
through shard director. Consistent caching represents
URLs and frontends as points on the ring. Adding new
frontend, simply adds a new point on the ring.
Scaling Varnish cluster
sub vcl_init {
# ...
new cluster = directors.shard();
{{ range .Frontends -}}
cluster.add_backend({{ .Name }});
{{ end }}
cluster.set_warmup(180);
}
sub vcl_recv {
set req.backend_hint = lb.backend();
# ...
unset req.http.x-cache;
set req.backend_hint = cluster.backend(by=URL);
set req.http.x-shard = req.backend_hint;
if (req.http.x-shard != server.identity) {
return(pass);
}
set req.backend_hint = lb.backend();
# ...
return(hash);
}
Scaling Varnish cluster
Varnish Signaller:
● Is aware of all Varnish frontends running
● acts similarly to Varnish Broadcaster (component of Varnish Plus)
● broadcasts flush cache request to all Varnish frontends
● runs on port 8090
BAN requests
$ curl -H "X-Url: /path" -X BAN http://cache-service:8090
$ curl -H "Cache-Tags: node-1" -X BAN http://cache-service:8090
PURGE requests
$ curl -H "X-Host: www.example.com" -X PURGE http://cache-service:8090/path
Invalidating cache
sub vcl_recv {
# ...
if (req.method == "PURGE") {
if (client.ip !~ privileged) {
return (synth(403, "Not allowed."));
}
if (req.http.X-Host) {
set req.http.host = req.http.X-Host;
}
return (purge);
}
if (req.method == "BAN") {
if (client.ip !~ privileged) {
return (synth(403, "Not allowed."));
}
if (req.http.Cache-Tags) {
ban("obj.http.Cache-Tags ~ " + req.http.Cache-Tags);
return (synth(200, "Ban added " + req.http.host));
}
if (req.http.X-Url) {
ban("obj.http.X-Url == " + req.http.X-Url);
return (synth(200, "Ban added " + req.http.host));
}
return (synth(403, "Cache-Tags or X-Url header missing."));
}
# ...
}
Invalidating cache
1. Kubernetes Playground
https://www.katacoda.com/courses/kubernetes/playground
2. Kubernetes Patterns Book
https://www.redhat.com/cms/managed-files/cm-oreilly-kubernetes-patterns-ebook-f19824-2
01910-en.pdf
3. Article this presentation is based on
https://dealancer.medium.com/creating-a-scalable-and-resilient-varnish-cluster-using-kuber
netes-853f03ec9731
4. kube-httpcache project
https://github.com/mittwald/kube-httpcache
5. Complete VCL file for Drupal 8 and 9 (IMPORTANT)
https://gist.github.com/dealancer/968297d6ddd93df80d012af7f4093294
Resources
configuring
Drupal
1. Purge module - https://www.drupal.org/project/purge
Clreans external caching systems, reverse proxies and CDNs
2. Varnish purger - https://www.drupal.org/project/varnish_purge
Extension of Purge module to clear Varnish cache
3. Configuration URL: /admin/config/development/performance/purge
Configuring Drupal
Configuring Drupal
Configuring Drupal
Configuring Drupal
Q&A?
Slides: http://bit.ly/k8s-varnish-drupal
Please, take a survey!
Thanks!
Slides: http://bit.ly/k8s-varnish-drupal
Please, take a survey!
1 of 43

Recommended

Kubernetes Introduction by
Kubernetes IntroductionKubernetes Introduction
Kubernetes IntroductionEric Gustafson
1.9K views24 slides
Kubernetes extensibility: crd & operators by
Kubernetes extensibility: crd & operators Kubernetes extensibility: crd & operators
Kubernetes extensibility: crd & operators Giacomo Tirabassi
105 views34 slides
GitOps - Operation By Pull Request by
GitOps - Operation By Pull RequestGitOps - Operation By Pull Request
GitOps - Operation By Pull RequestKasper Nissen
1.4K views85 slides
Kubernetes Networking 101 by
Kubernetes Networking 101Kubernetes Networking 101
Kubernetes Networking 101Weaveworks
6.6K views30 slides
Kubernetes Architecture and Introduction by
Kubernetes Architecture and IntroductionKubernetes Architecture and Introduction
Kubernetes Architecture and IntroductionStefan Schimanski
6K views45 slides
Kubernetes - introduction by
Kubernetes - introductionKubernetes - introduction
Kubernetes - introductionSparkbit
460 views27 slides

More Related Content

What's hot

Kubernetes by
KubernetesKubernetes
Kuberneteserialc_w
3K views19 slides
Kubernetes 101 by
Kubernetes 101Kubernetes 101
Kubernetes 101Crevise Technologies
1.6K views38 slides
Container Network Interface: Network Plugins for Kubernetes and beyond by
Container Network Interface: Network Plugins for Kubernetes and beyondContainer Network Interface: Network Plugins for Kubernetes and beyond
Container Network Interface: Network Plugins for Kubernetes and beyondKubeAcademy
14.1K views20 slides
DevOps with Kubernetes by
DevOps with KubernetesDevOps with Kubernetes
DevOps with KubernetesEastBanc Tachnologies
6.8K views45 slides
쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD) by
쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD)쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD)
쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD)충섭 김
12K views85 slides
Kubernetes: A Short Introduction (2019) by
Kubernetes: A Short Introduction (2019)Kubernetes: A Short Introduction (2019)
Kubernetes: A Short Introduction (2019)Megan O'Keefe
7.9K views25 slides

What's hot(20)

Kubernetes by erialc_w
KubernetesKubernetes
Kubernetes
erialc_w3K views
Container Network Interface: Network Plugins for Kubernetes and beyond by KubeAcademy
Container Network Interface: Network Plugins for Kubernetes and beyondContainer Network Interface: Network Plugins for Kubernetes and beyond
Container Network Interface: Network Plugins for Kubernetes and beyond
KubeAcademy14.1K views
쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD) by 충섭 김
쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD)쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD)
쿠버네티스를 이용한 기능 브랜치별 테스트 서버 만들기 (GitOps CI/CD)
충섭 김12K views
Kubernetes: A Short Introduction (2019) by Megan O'Keefe
Kubernetes: A Short Introduction (2019)Kubernetes: A Short Introduction (2019)
Kubernetes: A Short Introduction (2019)
Megan O'Keefe7.9K views
An intro to Kubernetes operators by J On The Beach
An intro to Kubernetes operatorsAn intro to Kubernetes operators
An intro to Kubernetes operators
J On The Beach2.5K views
Monitoring_with_Prometheus_Grafana_Tutorial by Tim Vaillancourt
Monitoring_with_Prometheus_Grafana_TutorialMonitoring_with_Prometheus_Grafana_Tutorial
Monitoring_with_Prometheus_Grafana_Tutorial
Tim Vaillancourt9.1K views
Hands-On Introduction to Kubernetes at LISA17 by Ryan Jarvinen
Hands-On Introduction to Kubernetes at LISA17Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17
Ryan Jarvinen1.1K views
Cilium - BPF & XDP for containers by Docker, Inc.
 Cilium - BPF & XDP for containers Cilium - BPF & XDP for containers
Cilium - BPF & XDP for containers
Docker, Inc.5.7K views
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCD by Sunnyvale
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCDKubernetes GitOps featuring GitHub, Kustomize and ArgoCD
Kubernetes GitOps featuring GitHub, Kustomize and ArgoCD
Sunnyvale455 views
Kubernetes Workshop by loodse
Kubernetes WorkshopKubernetes Workshop
Kubernetes Workshop
loodse855 views
Introduction to Kubernetes with demo by Opsta
Introduction to Kubernetes with demoIntroduction to Kubernetes with demo
Introduction to Kubernetes with demo
Opsta2.5K views
BPF & Cilium - Turning Linux into a Microservices-aware Operating System by Thomas Graf
BPF  & Cilium - Turning Linux into a Microservices-aware Operating SystemBPF  & Cilium - Turning Linux into a Microservices-aware Operating System
BPF & Cilium - Turning Linux into a Microservices-aware Operating System
Thomas Graf2.9K views
Deep dive into Kubernetes Networking by Sreenivas Makam
Deep dive into Kubernetes NetworkingDeep dive into Kubernetes Networking
Deep dive into Kubernetes Networking
Sreenivas Makam9.3K views
Kubernetes extensibility: CRDs & Operators by SIGHUP
Kubernetes extensibility: CRDs & OperatorsKubernetes extensibility: CRDs & Operators
Kubernetes extensibility: CRDs & Operators
SIGHUP1.4K views
Kubernetes architecture by Janakiram MSV
Kubernetes architectureKubernetes architecture
Kubernetes architecture
Janakiram MSV13.6K views
Kubernetes #4 volume &amp; stateful set by Terry Cho
Kubernetes #4   volume &amp; stateful setKubernetes #4   volume &amp; stateful set
Kubernetes #4 volume &amp; stateful set
Terry Cho2.3K views

Similar to Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North America 2021

Gluster Contenarized Storage for Cloud Applications by
Gluster Contenarized Storage for Cloud ApplicationsGluster Contenarized Storage for Cloud Applications
Gluster Contenarized Storage for Cloud ApplicationsHumble Chirammal
629 views37 slides
Gluster Containerized Storage for Cloud Applications by
Gluster Containerized Storage for Cloud ApplicationsGluster Containerized Storage for Cloud Applications
Gluster Containerized Storage for Cloud ApplicationsGluster.org
1.6K views37 slides
Web scale infrastructures with kubernetes and flannel by
Web scale infrastructures with kubernetes and flannelWeb scale infrastructures with kubernetes and flannel
Web scale infrastructures with kubernetes and flannelpurpleocean
948 views36 slides
Drupalcamp es 2013 drupal with lxc docker and vagrant by
Drupalcamp es 2013  drupal with lxc docker and vagrant Drupalcamp es 2013  drupal with lxc docker and vagrant
Drupalcamp es 2013 drupal with lxc docker and vagrant Ricardo Amaro
3.8K views45 slides
Digital Forensics and Incident Response in The Cloud Part 3 by
Digital Forensics and Incident Response in The Cloud Part 3Digital Forensics and Incident Response in The Cloud Part 3
Digital Forensics and Incident Response in The Cloud Part 3Velocidex Enterprises
811 views63 slides
Scaling docker with kubernetes by
Scaling docker with kubernetesScaling docker with kubernetes
Scaling docker with kubernetesLiran Cohen
2.4K views79 slides

Similar to Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North America 2021(20)

Gluster Contenarized Storage for Cloud Applications by Humble Chirammal
Gluster Contenarized Storage for Cloud ApplicationsGluster Contenarized Storage for Cloud Applications
Gluster Contenarized Storage for Cloud Applications
Humble Chirammal629 views
Gluster Containerized Storage for Cloud Applications by Gluster.org
Gluster Containerized Storage for Cloud ApplicationsGluster Containerized Storage for Cloud Applications
Gluster Containerized Storage for Cloud Applications
Gluster.org1.6K views
Web scale infrastructures with kubernetes and flannel by purpleocean
Web scale infrastructures with kubernetes and flannelWeb scale infrastructures with kubernetes and flannel
Web scale infrastructures with kubernetes and flannel
purpleocean948 views
Drupalcamp es 2013 drupal with lxc docker and vagrant by Ricardo Amaro
Drupalcamp es 2013  drupal with lxc docker and vagrant Drupalcamp es 2013  drupal with lxc docker and vagrant
Drupalcamp es 2013 drupal with lxc docker and vagrant
Ricardo Amaro3.8K views
Digital Forensics and Incident Response in The Cloud Part 3 by Velocidex Enterprises
Digital Forensics and Incident Response in The Cloud Part 3Digital Forensics and Incident Response in The Cloud Part 3
Digital Forensics and Incident Response in The Cloud Part 3
Scaling docker with kubernetes by Liran Cohen
Scaling docker with kubernetesScaling docker with kubernetes
Scaling docker with kubernetes
Liran Cohen2.4K views
5 - Hands-on Kubernetes Workshop: by Kangaroot
5 - Hands-on Kubernetes Workshop:5 - Hands-on Kubernetes Workshop:
5 - Hands-on Kubernetes Workshop:
Kangaroot218 views
A Hitchhiker’s Guide to the Cloud Native Stack. #CDS17 by Mario-Leander Reimer
A Hitchhiker’s Guide to the Cloud Native Stack. #CDS17A Hitchhiker’s Guide to the Cloud Native Stack. #CDS17
A Hitchhiker’s Guide to the Cloud Native Stack. #CDS17
A hitchhiker‘s guide to the cloud native stack by QAware GmbH
A hitchhiker‘s guide to the cloud native stackA hitchhiker‘s guide to the cloud native stack
A hitchhiker‘s guide to the cloud native stack
QAware GmbH946 views
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud by Dropsolid
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google CloudDrupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
Dropsolid3.5K views
Automate drupal deployments with linux containers, docker and vagrant by Ricardo Amaro
Automate drupal deployments with linux containers, docker and vagrant Automate drupal deployments with linux containers, docker and vagrant
Automate drupal deployments with linux containers, docker and vagrant
Ricardo Amaro9.8K views
Scaleable PHP Applications in Kubernetes by Robert Lemke
Scaleable PHP Applications in KubernetesScaleable PHP Applications in Kubernetes
Scaleable PHP Applications in Kubernetes
Robert Lemke51 views
Automating Your CloudStack Cloud with Puppet by buildacloud
Automating Your CloudStack Cloud with PuppetAutomating Your CloudStack Cloud with Puppet
Automating Your CloudStack Cloud with Puppet
buildacloud981 views
Kubernetes Architecture and Introduction – Paris Kubernetes Meetup by Stefan Schimanski
Kubernetes Architecture and Introduction – Paris Kubernetes MeetupKubernetes Architecture and Introduction – Paris Kubernetes Meetup
Kubernetes Architecture and Introduction – Paris Kubernetes Meetup
Stefan Schimanski5.5K views
Containerizing your Security Operations Center by Jimmy Mesta
Containerizing your Security Operations CenterContainerizing your Security Operations Center
Containerizing your Security Operations Center
Jimmy Mesta985 views
Laravel, docker, kubernetes by Peter Mein
Laravel, docker, kubernetesLaravel, docker, kubernetes
Laravel, docker, kubernetes
Peter Mein1.1K views
Build Your Own CaaS (Container as a Service) by HungWei Chiu
Build Your Own CaaS (Container as a Service)Build Your Own CaaS (Container as a Service)
Build Your Own CaaS (Container as a Service)
HungWei Chiu726 views
Kubernetes for the PHP developer by Paul Czarkowski
Kubernetes for the PHP developerKubernetes for the PHP developer
Kubernetes for the PHP developer
Paul Czarkowski362 views
Automating CloudStack with Puppet - David Nalley by Puppet
Automating CloudStack with Puppet - David NalleyAutomating CloudStack with Puppet - David Nalley
Automating CloudStack with Puppet - David Nalley
Puppet2.9K views

More from Ovadiah Myrgorod

How we maintain 200+ Drupal sites in Georgetown University by
How we maintain 200+ Drupal sites in Georgetown UniversityHow we maintain 200+ Drupal sites in Georgetown University
How we maintain 200+ Drupal sites in Georgetown UniversityOvadiah Myrgorod
2.5K views53 slides
Using Backbone.js with Drupal 7 and 8 by
Using Backbone.js with Drupal 7 and 8Using Backbone.js with Drupal 7 and 8
Using Backbone.js with Drupal 7 and 8Ovadiah Myrgorod
2.4K views58 slides
Drupal code sprint для новичков by
Drupal code sprint для новичковDrupal code sprint для новичков
Drupal code sprint для новичковOvadiah Myrgorod
2.1K views35 slides
Open source and You. DrupalForum ZP. by
Open source and You. DrupalForum ZP.Open source and You. DrupalForum ZP.
Open source and You. DrupalForum ZP.Ovadiah Myrgorod
17.6K views32 slides
Создаем Drupal дистрибутив: от идеи до сопровождения by
Создаем Drupal дистрибутив: от идеи до сопровожденияСоздаем Drupal дистрибутив: от идеи до сопровождения
Создаем Drupal дистрибутив: от идеи до сопровожденияOvadiah Myrgorod
1.3K views32 slides
Системы управления взаимоотношениями с клиентами. Drupal CRM Core. by
Системы управления взаимоотношениями с клиентами. Drupal CRM Core. Системы управления взаимоотношениями с клиентами. Drupal CRM Core.
Системы управления взаимоотношениями с клиентами. Drupal CRM Core. Ovadiah Myrgorod
1.5K views22 slides

More from Ovadiah Myrgorod(8)

How we maintain 200+ Drupal sites in Georgetown University by Ovadiah Myrgorod
How we maintain 200+ Drupal sites in Georgetown UniversityHow we maintain 200+ Drupal sites in Georgetown University
How we maintain 200+ Drupal sites in Georgetown University
Ovadiah Myrgorod2.5K views
Using Backbone.js with Drupal 7 and 8 by Ovadiah Myrgorod
Using Backbone.js with Drupal 7 and 8Using Backbone.js with Drupal 7 and 8
Using Backbone.js with Drupal 7 and 8
Ovadiah Myrgorod2.4K views
Drupal code sprint для новичков by Ovadiah Myrgorod
Drupal code sprint для новичковDrupal code sprint для новичков
Drupal code sprint для новичков
Ovadiah Myrgorod2.1K views
Open source and You. DrupalForum ZP. by Ovadiah Myrgorod
Open source and You. DrupalForum ZP.Open source and You. DrupalForum ZP.
Open source and You. DrupalForum ZP.
Ovadiah Myrgorod17.6K views
Создаем Drupal дистрибутив: от идеи до сопровождения by Ovadiah Myrgorod
Создаем Drupal дистрибутив: от идеи до сопровожденияСоздаем Drupal дистрибутив: от идеи до сопровождения
Создаем Drupal дистрибутив: от идеи до сопровождения
Ovadiah Myrgorod1.3K views
Системы управления взаимоотношениями с клиентами. Drupal CRM Core. by Ovadiah Myrgorod
Системы управления взаимоотношениями с клиентами. Drupal CRM Core. Системы управления взаимоотношениями с клиентами. Drupal CRM Core.
Системы управления взаимоотношениями с клиентами. Drupal CRM Core.
Ovadiah Myrgorod1.5K views
Drupal Camp Kyiv 2011 - OpenAcaDept – Drupal distribution for building academ... by Ovadiah Myrgorod
Drupal Camp Kyiv 2011 - OpenAcaDept – Drupal distribution for building academ...Drupal Camp Kyiv 2011 - OpenAcaDept – Drupal distribution for building academ...
Drupal Camp Kyiv 2011 - OpenAcaDept – Drupal distribution for building academ...
Ovadiah Myrgorod1.9K views
DrupalCon Chicago - Best practices for cross-browser compatibility of Drupal ... by Ovadiah Myrgorod
DrupalCon Chicago - Best practices for cross-browser compatibility of Drupal ...DrupalCon Chicago - Best practices for cross-browser compatibility of Drupal ...
DrupalCon Chicago - Best practices for cross-browser compatibility of Drupal ...
Ovadiah Myrgorod2.5K views

Recently uploaded

Roadmap y Novedades de producto by
Roadmap y Novedades de productoRoadmap y Novedades de producto
Roadmap y Novedades de productoNeo4j
43 views33 slides
Software evolution understanding: Automatic extraction of software identifier... by
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...Ra'Fat Al-Msie'deen
7 views33 slides
HarshithAkkapelli_Presentation.pdf by
HarshithAkkapelli_Presentation.pdfHarshithAkkapelli_Presentation.pdf
HarshithAkkapelli_Presentation.pdfharshithakkapelli
11 views16 slides
DSD-INT 2023 Baseline studies for Strategic Coastal protection for Long Islan... by
DSD-INT 2023 Baseline studies for Strategic Coastal protection for Long Islan...DSD-INT 2023 Baseline studies for Strategic Coastal protection for Long Islan...
DSD-INT 2023 Baseline studies for Strategic Coastal protection for Long Islan...Deltares
10 views30 slides
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida by
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - PridaDSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - PridaDeltares
17 views9 slides
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon by
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDeltares
11 views43 slides

Recently uploaded(20)

Roadmap y Novedades de producto by Neo4j
Roadmap y Novedades de productoRoadmap y Novedades de producto
Roadmap y Novedades de producto
Neo4j43 views
Software evolution understanding: Automatic extraction of software identifier... by Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
DSD-INT 2023 Baseline studies for Strategic Coastal protection for Long Islan... by Deltares
DSD-INT 2023 Baseline studies for Strategic Coastal protection for Long Islan...DSD-INT 2023 Baseline studies for Strategic Coastal protection for Long Islan...
DSD-INT 2023 Baseline studies for Strategic Coastal protection for Long Islan...
Deltares10 views
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida by Deltares
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - PridaDSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida
DSD-INT 2023 Dam break simulation in Derna (Libya) using HydroMT_SFINCS - Prida
Deltares17 views
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon by Deltares
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
Deltares11 views
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM... by Deltares
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...
DSD-INT 2023 Next-Generation Flood Inundation Mapping for Taiwan - Delft3D FM...
Deltares7 views
Cycleops - Automate deployments on top of bare metal.pptx by Thanassis Parathyras
Cycleops - Automate deployments on top of bare metal.pptxCycleops - Automate deployments on top of bare metal.pptx
Cycleops - Automate deployments on top of bare metal.pptx
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut... by HCLSoftware
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
Elevate your SAP landscape's efficiency and performance with HCL Workload Aut...
HCLSoftware6 views
How to Install and Activate Email-Researcher by eGrabber
How to Install and Activate Email-ResearcherHow to Install and Activate Email-Researcher
How to Install and Activate Email-Researcher
eGrabber19 views
Software testing company in India.pptx by SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 views
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... by Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 views
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... by Deltares
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
Deltares6 views
SUGCON ANZ Presentation V2.1 Final.pptx by Jack Spektor
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptx
Jack Spektor21 views
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
Deltares12 views
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea... by Safe Software
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...
Safe Software391 views

Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North America 2021

  • 1. Create a Varnish cluster in Kubernetes for Drupal caching Vadym Myrgorod Slides: http://bit.ly/k8s-varnish-drupal
  • 2. Vadym Myrgorod Using Drupal since 2008 Web App Developer Howard Hughes Medical Institute @dealancer1 https://www.myrgorod.net
  • 3. I will make a quick intro into Varnish and Kubernetes. We will learn how to configure Varnish cluster for Drupal 8 and run it on Kubernetes platform. In this session
  • 5. More users means slower website
  • 6. Slower website means bigger bounce rate
  • 7. 1. Cutting visitors off 2. Arranging visitors in an online queue 3. Buying more hardware Approaches we won’t cover in this session
  • 8. In computing, a cache is a hardware or software component that stores data so that future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere. Caching
  • 9. Levels of caching 1 Opcode Caching Compile PHP script into opcode and cache it. Examples: OPcache extension. 3 Drupal Caching Store blocks, views and other Drupal components in memory. Examples: Memcache, Redis. 5 Content Delivery Network Store static assets in geographically distributed caching system. Examples: Cloudflare, Fastly, Akamai. 2 Database Caching Store results of SQL queries in memory. Examples: memcached. 4 Static Content Caching Store static assets in memory. Examples: Varnish, Nginx.
  • 10. ● Aggregated CSS files ● Aggregated JS files ● Images of various image styles ● HTML pages (for anonymous users) Static content generated by Drupal
  • 11. ● Caching HTTP reverse proxy ● Speeds up delivery with a factor of 300 - 1000x ● Varnish Configuration Language (VCL) ● Can be scaled into Varnish Cluster
  • 12. Backend - server which is providing the content Varnish will accelerate. Frontend - client facing Varnish server. Terms Backend Frontend
  • 13. vcl 4.0; backend default { .host = "127.0.0.1"; .port = "8080"; } sub vcl_recv { if (req.http.host == "www.example.com") { set req.backend_hint = default; } } See following VCL example for Drupal 8 and 7: https://www.varnish-software.com/wiki/content/tutorials/drupal/drupal_vcl.html Minimal Varnish VCL /etc/varnish/default.vcl
  • 14. now let’s talk about Kubernetes
  • 15. 1. You want to manage services you are running e.g. MySQL, Varnish, Redis, Apache Solr, Elasticsearch... 2. You want to have an ability to migrate from one cloud provider to another quickly. 3. You have on-premises infrastructure you need to utilize. 4. You want to use multicloud or hybrid-cloud approaches. 5. You want to have some of the cool features that Kubernetes provides. When using Kubernetes is a good idea
  • 16. 1. Scaling: runs more containers if needed. 2. Healing: restarts containers when they are down. 3. Deployment strategies: rolling updates, blue/green, canary... 4. Service discovery and load balancing: distributes access to containers by service name. 5. Security: secret management, security policies. 6. Storage orchestration: cloud, NFS, or storage providers. 7. Flexibility and extensibility: Go is widely used in k8s world. Things Kubernetes is good at
  • 17. ● Resource - endpoint in k8s API that stores a collection of certain kind. Declared using YAML syntax. Example: config map, secret, volume, volume claim, pod, deployment, stateful set, service, ingress, etc... ● Config map - stores software configuration that can be mounted as files or passed as env variables. ● Volume - used to preserve file system after container is restarted. ● Pod - k8s resource that represents running container (or set set of containers). Kubernetes resources Config map Pod Deployment Service Ingress Stateful Set Volume
  • 18. ● Deployment - ensures certain amount of pods are up and running. ● Stateful Set - acts as deployment for stateful services that have specific requirements to storage and pod identity. ● Service - provides a way to access deployments or stateful sets using different behaviours. Creates a common DNS record that can be used to access pods and does load balancing. ● Ingress - manages external access to services using various routing rules. Kubernetes resources Config map Pod Deployment Service Ingress Stateful Set Volume
  • 19. nginx-deployment.yaml: apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80 Minimal Kubernetes deployment and service nginx-service.yaml: apiVersion: v1 kind: Service metadata: name: nginx-service spec: selector: app: nginx type: NodePort ports: - protocol: TCP port: 8080 targetPort: 80 nodePort: 30080
  • 20. 1. Apply deployment $ kubectl apply -f nginx-deployment.yaml 2. Check deployments $ kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE nginx-deployment 0/2 0 0 1s 3. Check pods $ kubectl get pods --show-labels NAME READY STATUS RESTARTS AGE LABELS nginx-deployment-75675f5897-7ci7o 1/1 Running 0 18s app=nginx,pod-template-hash=3123191453 nginx-deployment-75675f5897-kzszj 1/1 Running 0 18s app=nginx,pod-template-hash=3123191453 Minimal Kubernetes deployment and service
  • 21. 4. Apply service $ kubectl apply -f nginx-service.yaml 5. Check services $ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 41d nginx-service NodePort 10.98.115.133 <none> 8080:30080/TCP 5m11s 6. Access nginx using node port $ curl localhost:30080 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> ... Minimal Kubernetes deployment and service
  • 23. To run Varnish in k8s we need to declare app deployment, app service, Varnish deployment, Varnish service, config maps and ingress. Example: https://github.com/dealancer/k8s-varnish-test. The simplest approach
  • 24. varnish-deployment.yaml: apiVersion: apps/v1 kind: Deployment metadata: name: varnish-deployment labels: app: varnish spec: replicas: 1 selector: matchLabels: app: varnish template: metadata: labels: app: varnish The simplest approach spec: containers: - name: varnish image: varnish:6.6.0 env: - name: CACHE_SIZE value: 128m - name: VCL_CONFIG value: /etc/varnish/configmap/default.vcl volumeMounts: - name: varnish-config mountPath: /etc/varnish/configmap ports: - containerPort: 80 volumes: - name: varnish-config configMap: name: varnish-configmap
  • 25. varnish-configmap.yaml: apiVersion: v1 kind: ConfigMap metadata: name: varnish-configmap labels: app: varnish data: default.vcl: | vcl 4.0; backend default { .host = "nginx-service"; .port = "8080"; } sub vcl_recv { set req.backend_hint = default; } The simplest approach varnish-service.yaml: apiVersion: v1 kind: Service metadata: name: varnish-service spec: selector: app: nginx type: NodePort ports: - protocol: TCP port: 80 targetPort: 80 nodePort: 30081
  • 26. Questions to this approach: 1. Can we eliminate App Service and let Varnish talk to application pods (backends) directly? 2. How do we scale Varnish pods (frontends)? 3. How do we shard cache across multiple Varnish pods? 4. How do we invalidate cache in multiple Varnish pods? The simplest approach
  • 27. kube-httpcache is an open Source Kubernetes controller written in Go to run Varnish cluster. It is a free solution comparing to Varnish Cache Plus, but it requires to configure Varnish in certain way using VCL. GitHub: https://github.com/mittwald/kube-httpcache. Features: ● Monitors backend (app) and frontend (Varnish) pods. ● Dynamically update Varnish VCL and reload it on the the fly in all Varnish pods. ● Supports Go-template syntax in VCL file. ● Sends cache invalidation requests to all Varnish pods using Signaller component. kube-httpcache
  • 28. spec: containers: - name: cache image: quay.io/mittwald/kube-httpcache:stable imagePullPolicy: Always args: - -admin-addr=0.0.0.0 - -admin-port=6083 - -signaller-enable - -signaller-port=8090 - -frontend-watch - -frontend-namespace=$(NAMESPACE) - -frontend-service=frontend-service - -backend-watch - -backend-namespace=$(NAMESPACE) - -backend-service=backend-service - -varnish-secret-file=/etc/varnish/k8s-secret/secret - -varnish-vcl-template=/etc/varnish/tmpl/default.vcl.tmpl - -varnish-storage=malloc,128M env: - name: NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace volumeMounts: - name: template mountPath: /etc/varnish/tmpl - name: secret mountPath: /etc/varnish/k8s-secret varnish-service.yaml (part)
  • 29. {{ range .Backends }} backend be-{{ .Name }} { .host = "{{ .Host }}"; .port = "{{ .Port }}"; } {{- end }} {{ range .Frontends }} backend {{ .Name }} { .host = "{{ .Host }}"; .port = "{{ .Port }}"; } {{- end }} sub vcl_init { new lb = directors.round_robin(); {{ range .Backends -}} lb.add_backend(be-{{ .Name }}); {{ end }} } sub vcl_recv { set req.backend_hint = lb.backend(); } Eliminate the need in backend service
  • 30. In this approach cache is sharded across multiple Varnish frontends. 1. Varnish Service routes requests to a random Varnish frontend. 2. A corresponding Varnish frontend (x-shard) determined based on the URL using hash director: a. http://example.com/foo -> frontend 1 b. http://example.com/bar -> frontend 2 c. http://example.com/bar2 -> frontend 1 3. If x-shard is not the current Varnish frontend, request is forwarded to x-shard. 4. Otherwise, request is handled by the current Varnish node: a. If request is cacheable and cache exist, cached content is returned. b. If cache does not exists, Varnish requests a backend to save cache and serve cached content. c. If request is cacheable request is routed to a backend. See https://info.varnish-software.com/blog/creating-self-routing-varnish-cluster Running Varnish cluster (sharded cache)
  • 31. sub vcl_init { # ... new cluster = directors.hash(); {{ range .Frontends -}} cluster.add_backend({{ .Name }}, 1); {{ end }} } sub vcl_recv { set req.backend_hint = lb.backend(); # ... unset req.http.x-cache; set req.backend_hint = cluster.backend(req.url); set req.http.x-shard = req.backend_hint; if (req.http.x-shard != server.identity) { return(pass); } set req.backend_hint = lb.backend(); # ... return(hash); } Running Varnish cluster (sharded cache)
  • 32. Problem In case if you horizontally scale your Varnish cluster, a hash director will recalculate hashes for existing URLs and will route requests to different Varnish frontends which do not store cached content for these URLs. Thus users will experience slowdown. Solution Consistent caching mechanism is provided by Varnish through shard director. Consistent caching represents URLs and frontends as points on the ring. Adding new frontend, simply adds a new point on the ring. Scaling Varnish cluster
  • 33. sub vcl_init { # ... new cluster = directors.shard(); {{ range .Frontends -}} cluster.add_backend({{ .Name }}); {{ end }} cluster.set_warmup(180); } sub vcl_recv { set req.backend_hint = lb.backend(); # ... unset req.http.x-cache; set req.backend_hint = cluster.backend(by=URL); set req.http.x-shard = req.backend_hint; if (req.http.x-shard != server.identity) { return(pass); } set req.backend_hint = lb.backend(); # ... return(hash); } Scaling Varnish cluster
  • 34. Varnish Signaller: ● Is aware of all Varnish frontends running ● acts similarly to Varnish Broadcaster (component of Varnish Plus) ● broadcasts flush cache request to all Varnish frontends ● runs on port 8090 BAN requests $ curl -H "X-Url: /path" -X BAN http://cache-service:8090 $ curl -H "Cache-Tags: node-1" -X BAN http://cache-service:8090 PURGE requests $ curl -H "X-Host: www.example.com" -X PURGE http://cache-service:8090/path Invalidating cache
  • 35. sub vcl_recv { # ... if (req.method == "PURGE") { if (client.ip !~ privileged) { return (synth(403, "Not allowed.")); } if (req.http.X-Host) { set req.http.host = req.http.X-Host; } return (purge); } if (req.method == "BAN") { if (client.ip !~ privileged) { return (synth(403, "Not allowed.")); } if (req.http.Cache-Tags) { ban("obj.http.Cache-Tags ~ " + req.http.Cache-Tags); return (synth(200, "Ban added " + req.http.host)); } if (req.http.X-Url) { ban("obj.http.X-Url == " + req.http.X-Url); return (synth(200, "Ban added " + req.http.host)); } return (synth(403, "Cache-Tags or X-Url header missing.")); } # ... } Invalidating cache
  • 36. 1. Kubernetes Playground https://www.katacoda.com/courses/kubernetes/playground 2. Kubernetes Patterns Book https://www.redhat.com/cms/managed-files/cm-oreilly-kubernetes-patterns-ebook-f19824-2 01910-en.pdf 3. Article this presentation is based on https://dealancer.medium.com/creating-a-scalable-and-resilient-varnish-cluster-using-kuber netes-853f03ec9731 4. kube-httpcache project https://github.com/mittwald/kube-httpcache 5. Complete VCL file for Drupal 8 and 9 (IMPORTANT) https://gist.github.com/dealancer/968297d6ddd93df80d012af7f4093294 Resources
  • 38. 1. Purge module - https://www.drupal.org/project/purge Clreans external caching systems, reverse proxies and CDNs 2. Varnish purger - https://www.drupal.org/project/varnish_purge Extension of Purge module to clear Varnish cache 3. Configuration URL: /admin/config/development/performance/purge Configuring Drupal