Search
Varnish Helm Chart

StatefulSet

StatefulSet is a deployment type in Kubernetes where the operator can request a persistent backing disk. Kubernetes will reserve, mount, and release these persistent backing disks during Pod lifecycle.

This type of deployment is suitable for a general use of Varnish that needs cache persistency.

Basic Configuration

To deploy Varnish as a StatefulSet, set server.kind to StatefulSet:

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

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

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

  secret: "my-super-secret"

Enabling MSE

In this type of deployment, it’s possible to use MSE with StatefulSet in both non-persistence and persistence mode. To enable MSE in non-persistence mode, set server.mse.enabled to true, and configure server.mse.memoryTarget:

---
server:
  # ...previous configurations

  mse:
    enabled: true
    memoryTarget: "64Gi"

Enabling MSE with Persistence

Enabling MSE in persistence mode can be done by enabling server.mse.persistence.enabled and setting the server.mse.persistence.storageSize:

---
server:
  # ...previous configurations

  mse:
    enabled: true
    memoryTarget: "80%"

    config: |
      env: {
        id = "env";
        memcache_size = "auto";
        books = ( {
          id = "book1";
          directory = "{{ .Values.server.mse.persistence.mountPath }}/book1";
          database_size = "1G";
          stores = ( {
            id = "store";
            filename = "{{ .Values.server.mse.persistence.mountPath }}/store1.dat";
            size = "9G";
          } );
        } );
      };

    persistence:
      enabled: true
      storageSize: "10Gi"

Note: the persistent storage provider must provision an ext4 volume.

Choosing a Persistence Storage Provider

Network latency can affect the performance of software that requires low-latency storage, such as Varnish. It is recommended to use a low-latency, local-attached storage (such as NVMe) instead of network-attached storage (such as Ceph, iSCSI, or NFS) when possible.

In case multiple persistent storage providers are available, use server.mse.persistence.storageClassName to select the appropriate provider:

---
server:
  # ...previous configurations

  persistence:
    enabled: true
    storageSize: "100Gi"
    storageClassName: "local-storage"