Search
Varnish Helm Chart

Deployment

Deployment sets up Varnish as an ephemeral Pod, which may be scheduled to any nodes within the Kubernetes cluster.

This is suitable for caching scenarios where cache persistency is not required. For example, as a reverse proxy or an HTTP accelerator.

Basic configuration

To use Varnish as a Deployment, set server.kind to Deployment:

---
global:
  imagePullSecrets:
    - name: my-pull-secret

server:
  replicas: 3
  kind: "Deployment"
  vclConfig: |
    vcl 4.1;

    backend default {
      .host = "127.0.0.1";
      .port = "8080";
    }

  secret: "my-super-secret"

Enabling MSE

Since Deployment has no backing disks, MSE is only available in non-persistence mode. To enable MSE, set server.mse.enabled to true and configure server.mse.memoryTarget:

---
server:
  # ...previous configurations

  mse:
    enabled: true
    memoryTarget: "64Gi"

Running a single Varnish instance per node

It’s important to note that Varnish is designed to run on a dedicated node. Kubernetes’ scheduler may assign multiple Varnish pods to the same node, possibly affecting performance.

To ensure Kubernetes only schedules a single Varnish instance in a single node, configure server.affinity:

server:
  # ...previous configurations

  affinity: |
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchLabels:
              app.kubernetes.io/name: {{ include "varnish-enterprise.name" . }}
              app.kubernetes.io/instance: {{ .Release.Name }}
          topologyKey: kubernetes.io/hostname

Note: The number of server.replicas must be, at most, (number of nodes - 1) for a rolling deploy of new versions. requiredDuringSchedulingIgnoredDuringExecution can’t schedule a new version to a node that already has Varnish Enterprise running.

If this isn’t feasible, use preferredDuringSchedulingIgnoredDuringExecution to allow scheduling if the affinity rules can’t be fulfilled:

server:
  # ...previous configurations

  affinity: |
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 100
          podAffinityTerm:
            labelSelector:
              matchLabels:
                app.kubernetes.io/name: {{ include "varnish-enterprise.name" . }}
                app.kubernetes.io/instance: {{ .Release.Name }}
            topologyKey: kubernetes.io/hostname