diff --git a/README.md b/README.md index 93aa0527..a4cbb1a1 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ This repository contains a controller that allows you to operate a [Varnish cach - [Detailed how-tos](#detailed-how-tos) - [Using built in signaller component](#using-built-in-signaller-component) - [Proxying to external services](#proxying-to-external-services) +- [Helm Chart Intallation](#helm-chart-installation) @@ -384,3 +385,50 @@ data: ``` When starting kube-httpcache, remember to set the `--backend-watch=false` flag to disable watching the (non-existent) backend endpoints. + +## Helm Chart installation + +Using [HELM](chart/) to rollout an instance of kube-httpcache. + +Ensure your defined backen services have a port +name `http`: + +``` +apiVersion: v1 +kind: Service +metadata: + name: backend-service +spec: + ports: + - name: http + port: 80 + protocol: TCP + targetPort: 8080 + type: ClusterIP +``` + +An ingress points to the kube-httpcache service which cached +your backend service: + +``` +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: example-ingress +spec: + rules: + - host: www.example.com + http: + paths: + - backend: + service: + name: kube-httpcache + port: + number: 80 + path: / + pathType: Prefix +``` + +Look at the `vclTemplate` property in [chart/values.yaml](chart/values.yaml) to define +your own Varnish cluster rules or load with `extraVolume` an extra file +as initContainer if your ruleset is really big. diff --git a/chart/.helmignore b/chart/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/chart/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/chart/Chart.yaml b/chart/Chart.yaml new file mode 100644 index 00000000..36c97321 --- /dev/null +++ b/chart/Chart.yaml @@ -0,0 +1,8 @@ +name: kube-httpcache +description: Varnish on Kubernetes Helm Chart +version: 0.0.1 +appVersion: 0.0.1 +home: https://varnish-cache.org +icon: https://varnish-cache.org/_static/varnish-bunny.png +sources: + - https://github.com/mittwald/kube-httpcache diff --git a/chart/templates/NOTES.txt b/chart/templates/NOTES.txt new file mode 100644 index 00000000..6c58eb37 --- /dev/null +++ b/chart/templates/NOTES.txt @@ -0,0 +1,3 @@ +Ensure your backend-service has a port name 'http' and create an ingress +point to the kube-httpcache service. Enjoy your Varnish cache! + diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl new file mode 100644 index 00000000..05e5125c --- /dev/null +++ b/chart/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "kube-httpcache.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "kube-httpcache.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "kube-httpcache.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "kube-httpcache.labels" -}} +helm.sh/chart: {{ include "kube-httpcache.chart" . }} +{{ include "kube-httpcache.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "kube-httpcache.selectorLabels" -}} +app.kubernetes.io/name: {{ include "kube-httpcache.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "kube-httpcache.serviceAccountName" -}} +{{- if .Values.serviceAccount.enabled }} +{{- default (include "kube-httpcache.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/chart/templates/configmap.yaml b/chart/templates/configmap.yaml new file mode 100644 index 00000000..ce59a5ad --- /dev/null +++ b/chart/templates/configmap.yaml @@ -0,0 +1,9 @@ +{{- if .Values.configmap.enabled -}} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "kube-httpcache.fullname" . }} +data: + default.vcl.tmpl: | +{{ .Values.vclTemplate | indent 4}} +{{- end }} diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml new file mode 100644 index 00000000..586001b1 --- /dev/null +++ b/chart/templates/deployment.yaml @@ -0,0 +1,112 @@ +{{- if not .Values.useStatefulset.enabled -}} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "kube-httpcache.fullname" . }} + labels: + {{- include "kube-httpcache.labels" . | nindent 4 }} +spec: +{{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} +{{- end }} + selector: + matchLabels: + {{- include "kube-httpcache.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "kube-httpcache.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "kube-httpcache.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- if .Values.initContainers }} + initContainers: + {{- with .Values.initContainers }} + {{- tpl . $ | nindent 8 }} + {{- end }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- if .Values.livenessProbe }} + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + {{- end }} + {{- if .Values.readinessProbe }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + {{- end }} + args: + - -admin-addr=0.0.0.0 + - -admin-port=6083 + - -signaller-enable + - -signaller-port=8090 + - -frontend-watch + - -frontend-namespace={{ "$(NAMESPACE)" }} + - -frontend-service={{ include "kube-httpcache.fullname" . }} + - -backend-watch + - -backend-service={{ .Values.cache.backendService }} + - -backend-namespace={{ .Values.cache.backendServiceNamespace | default "$(NAMESPACE)" }} + - -varnish-secret-file=/etc/varnish/k8s-secret/secret + - -varnish-vcl-template=/etc/varnish/tmpl/default.vcl.tmpl + - -varnish-storage={{ .Values.cache.varnishStorage }},{{ .Values.cache.storageSize }} + {{- if .Values.cacheExtraArgs }} + {{- with .Values.cacheExtraArgs }} + {{- tpl . $ | trim | nindent 10 }} + {{- end }} + {{- end }} + env: + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + volumeMounts: + - name: template + mountPath: /etc/varnish/tmpl + - name: secret + mountPath: /etc/varnish/k8s-secret + {{- if .Values.extraMounts }} + {{- toYaml .Values.extraMounts | nindent 10 }} + {{- end }} + {{- if .Values.resources }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- end }} + volumes: + {{- if .Values.configmap.enabled }} + - name: template + configMap: + name: {{ include "kube-httpcache.fullname" . }} + {{- end }} + - name: secret + secret: + secretName: {{ include "kube-httpcache.fullname" . }} + {{- if .Values.extraVolumes -}} + {{- toYaml .Values.extraVolumes | nindent 6 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end }} diff --git a/chart/templates/hpa.yaml b/chart/templates/hpa.yaml new file mode 100644 index 00000000..3409ae2d --- /dev/null +++ b/chart/templates/hpa.yaml @@ -0,0 +1,30 @@ +{{- if not .Values.useStatefulset.enabled -}} +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "kube-httpcache.fullname" . }} + labels: + {{- include "kube-httpcache.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "kube-httpcache.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} +{{- end }} diff --git a/chart/templates/ingress.yaml b/chart/templates/ingress.yaml new file mode 100644 index 00000000..eac9c6e8 --- /dev/null +++ b/chart/templates/ingress.yaml @@ -0,0 +1,29 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "kube-httpcache.fullname" . }} + labels: + {{- include "kube-httpcache.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host }} + http: + paths: {{ .paths | toYaml | nindent 10 }} + {{- end }} + {{- end }} diff --git a/chart/templates/rbac.yaml b/chart/templates/rbac.yaml new file mode 100644 index 00000000..f1bef8a1 --- /dev/null +++ b/chart/templates/rbac.yaml @@ -0,0 +1,48 @@ +{{- if .Values.rbac.enabled -}} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ include "kube-httpcache.fullname" . }} +rules: +- apiGroups: + - "" + resources: + - endpoints + - pods + verbs: + - watch + - get +{{- if .Values.podSecurityPolicy.enabled -}} +- apiGroups: + - "" + resources: + - endpoints + - pods + verbs: + - watch + - get +- apiGroups: + - extensions + resourceNames: + - {{ .Values.podSecurityPolicy.name }} + resources: + - podsecuritypolicies + verbs: + - use +{{- end }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + labels: + {{- include "kube-httpcache.labels" . | nindent 4 }} + name: {{ include "kube-httpcache.fullname" . }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ include "kube-httpcache.fullname" . }} +subjects: + - kind: ServiceAccount + name: {{ include "kube-httpcache.serviceAccountName" . }} +{{- end }} diff --git a/chart/templates/secret.yaml b/chart/templates/secret.yaml new file mode 100644 index 00000000..ba51ac00 --- /dev/null +++ b/chart/templates/secret.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "kube-httpcache.fullname" . }} + labels: + {{- include "kube-httpcache.labels" . | nindent 4 }} +type: Opaque +data: + secret: {{ .Values.cache.secret | default (randAlphaNum 32) | b64enc | quote }} diff --git a/chart/templates/service.yaml b/chart/templates/service.yaml new file mode 100644 index 00000000..69147596 --- /dev/null +++ b/chart/templates/service.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "kube-httpcache.fullname" . }} + labels: + {{- include "kube-httpcache.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - name: http + port: {{ .Values.service.port }} + targetPort: {{ .Values.service.target }} + protocol: TCP + - name: "signaller" + port: 8090 + targetPort: 8090 + selector: + {{- include "kube-httpcache.selectorLabels" . | nindent 4 }} diff --git a/chart/templates/serviceaccount.yaml b/chart/templates/serviceaccount.yaml new file mode 100644 index 00000000..963caaad --- /dev/null +++ b/chart/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.enabled -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "kube-httpcache.serviceAccountName" . }} + labels: + {{- include "kube-httpcache.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/chart/templates/statefulset.yaml b/chart/templates/statefulset.yaml new file mode 100644 index 00000000..025b02f3 --- /dev/null +++ b/chart/templates/statefulset.yaml @@ -0,0 +1,113 @@ +{{- if .Values.useStatefulset.enabled -}} +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "kube-httpcache.fullname" . }} + labels: + {{- include "kube-httpcache.labels" . | nindent 4 }} +spec: + serviceName: {{ include "kube-httpcache.fullname" . }} +{{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} +{{- end }} + selector: + matchLabels: + {{- include "kube-httpcache.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "kube-httpcache.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "kube-httpcache.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- if .Values.initContainers }} + initContainers: + {{- with .Values.initContainers }} + {{- tpl . $ | nindent 8 }} + {{- end }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + - -admin-addr=0.0.0.0 + - -admin-port=6083 + - -signaller-enable + - -signaller-port=8090 + - -frontend-watch + - -frontend-namespace={{ "$(NAMESPACE)" }} + - -frontend-service={{ include "kube-httpcache.fullname" . }} + - -backend-watch + - -backend-namespace={{ .Values.cache.backendServiceNamespace | default "$(NAMESPACE)" }} + - -backend-service={{ .Values.cache.backendService }} + - -varnish-secret-file=/etc/varnish/k8s-secret/secret + - -varnish-vcl-template=/etc/varnish/tmpl/default.vcl.tmpl + - -varnish-storage={{ .Values.cache.varnishStorage }},{{ .Values.cache.storageSize }} + {{- if .Values.cacheExtraArgs }} + {{- with .Values.cacheExtraArgs }} + {{- tpl . $ | trim | nindent 10 }} + {{- end }} + {{- end }} + env: + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + volumeMounts: + - name: template + mountPath: /etc/varnish/tmpl + - name: secret + mountPath: /etc/varnish/k8s-secret + {{- if .Values.extraMounts }} + {{- toYaml .Values.extraMounts | nindent 10 }} + {{- end }} + {{- if .Values.livenessProbe }} + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + {{- end }} + {{- if .Values.readinessProbe }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + {{- end }} + {{- if .Values.resources }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- end }} + volumes: + {{- if .Values.configmap.enabled }} + - name: template + configMap: + name: {{ include "kube-httpcache.fullname" . }} + {{- end }} + - name: secret + secret: + secretName: {{ include "kube-httpcache.fullname" . }} + {{- if .Values.extraVolumes }} + {{- toYaml .Values.extraVolumes | nindent 6 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end }} diff --git a/chart/values.yaml b/chart/values.yaml new file mode 100644 index 00000000..ac0f51d4 --- /dev/null +++ b/chart/values.yaml @@ -0,0 +1,233 @@ +# Default values for kube-httpcache. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: quay.io/mittwald/kube-httpcache + pullPolicy: IfNotPresent + tag: "stable" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +# Enable StatefulSet (Deployment is default) +useStatefulset: + enabled: true + +# Enable configMap for Varnish Template File (see below vclTemplate) +# OR use extravolume with name "template" if the file is too big +configmap: + enabled: true + +# kube-httpcache specific configuration +cache: + # name of backend service + backendService: backend-service + # name of backend service namespace + # backendServiceNamespace: backend-service-namespace + # Varnish storage backend type (https://varnish-cache.org/docs/trunk/users-guide/storage-backends.html) + varnishStorage: malloc # default,malloc,umem,file... + # Varnish storage backend size + storageSize: 128M # K(ibibytes), M(ebibytes), G(ibibytes), T(ebibytes) ... unlimited + # Secret for Varnish admin credentials + #secret: "12345678" + # File name for Varnish template + template: varnish.tpl + +cacheExtraArgs: {} +# cacheExtraArgs: | + # - -v=8 + # - -varnish-additional-parameters=vcc_allow_inline_c=on + +serviceAccount: + # Specifies whether a service account should be created + enabled: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +rbac: + enabled: true + +podSecurityPolicy: + enabled: false + # name: unrestricted-psp + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +initContainers: {} +# initContainers: | +# - args: +# - -c +# - | +# echo "Copying external varnish template from..." +# command: +# - sh +# image: busybox:latest +# imagePullPolicy: IfNotPresent +# name: varnishtemplate +# resources: {} +# terminationMessagePath: /dev/termination-log +# terminationMessagePolicy: File +# volumeMounts: +# - name: template +# mountPath: /etc/varnish/tmpl +# +extraVolumes: {} +# extraVolumes: +# - emptyDir: {} +# name: template + +extraMounts: {} +# extraMounts: +# - name: geoip +# mountPath: /var/lib/geoip + +service: + type: ClusterIP + port: 80 + target: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: [] + # hosts: + # - host: www.example.com + # paths: + # - path: / + # pathType: Prefix + # backend: + # service: + # name: kube-httpcache + # port: + # number: 80 + # - path: /backend + # backend: + # name: backend-service + # port: + # number: 8080 + # - host: www2.example.com + # paths: + # - path: / + # pathType: Prefix + # backend: + # name: kube-httpcache + # port: + # number: 80 + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +livenessProbe: {} +# livenessProbe: +# httpGet: +# path: / +# port: 6083 +readinessProbe: {} + +vclTemplate: | + vcl 4.0; + + import std; + import directors; + + // ".Frontends" is a slice that contains all known Varnish instances + // (as selected by the service specified by -frontend-service). + // The backend name needs to be the Pod name, since this value is compared + // to the server identity ("server.identity" [1]) later. + // + // [1]: https://varnish-cache.org/docs/6.4/reference/vcl.html#local-server-remote-and-client + {{ range .Frontends }} + backend {{ .Name }} { + .host = "{{ .Host }}"; + .port = "{{ .Port }}"; + } + {{- end }} + + {{ range .Backends }} + backend be-{{ .Name }} { + .host = "{{ .Host }}"; + .port = "{{ .Port }}"; + } + {{- end }} + + sub vcl_init { + new cluster = directors.hash(); + + {{ range .Frontends -}} + cluster.add_backend({{ .Name }}, 1); + {{ end }} + + new lb = directors.round_robin(); + + {{ range .Backends -}} + lb.add_backend(be-{{ .Name }}); + {{ end }} + } + + sub vcl_recv + { + # Set backend hint for non cachable objects. + set req.backend_hint = lb.backend(); + + # ... + + # Routing logic. Pass a request to an appropriate Varnish node. + # See https://info.varnish-software.com/blog/creating-self-routing-varnish-cluster for more info. + 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); + }