varnish-cache

by Varnish Software

Helm chartv1.10.0App 9.1.0Verified publisher

Varnish Cache Helm chart

About this chart

Varnish Cache Helm Chart

Varnish Cache is a high-performance web application accelerator (also known as a caching HTTP reverse proxy).

This repository provides an easy way to install Varnish Cache on Kubernetes using Helm.

For Varnish Enterprise customers, please see Varnish Enterprise Helm Chart.

Usage

To install the chart as release-name in the current namespace:

helm install release-name oci://registry-1.docker.io/varnish/varnish-cache

Configuring

To configure a Helm chart, create values.yaml to override the default values:

---
server:
  replicas: 3

Then install or upgrade using the overridden values, e.g.:

helm upgrade -f values.yaml release-name oci://registry-1.docker.io/varnish/varnish-cache

Varnish Cache Helm Chart is designed to be highly configurable while requiring minimal configuration for common operations. Listed below are the common configurations for a Varnish Cache deployment. For a full list of configurations, see the Configurations section below.

Changing the default VCL

Varnish Cache Helm Chart does not provide any VCL by default. Instead, it uses the default VCL located at /etc/varnish/default.vcl provided within the Docker image. From varnish:7.5.0 onward, it is possible to configure the default backend via an environment variable:

server:
  extraEnvs:
    VARNISH_BACKEND_HOST: "localhost"
    VARNISH_BACKEND_PORT: "8080"

If a more advanced customization is required, it is also possible to override the default VCL with server.vclConfig:

---
server:
  vclConfig: |
    vcl 4.1;

    backend default {
      .host = "example.default.svc.cluster.local";
      .port = "8080";
    }

    sub vcl_backend_fetch {
      set bereq.http.Host = "www.example.com";
    }

Workload types

Varnish Cache Helm Chart supports deploying with the following workload types by modifying server.kind variable with the respective values:

  • Deployment for general use-case of Varnish Cache
  • StatefulSet for Varnish Cache deployment where persistency is needed
  • DaemonSet for ensuring Varnish Cache is run on every node

Extra listens and extra services

Varnish Cache Helm Chart supports deploying Varnish Cache with custom ports. For example, opening another HTTP port with PROXY protocol support for integration with an upstream Load Balancer. To do so, configures server.extraListens and server.service.extraServices respectively:

---
server:
  extraListens:
    - name: proxy
      port: 8088
      proto: "PROXY"

  service:
    extraServices:
      - name: proxy
        targetPort: 8088
        port: 8088

Setting server.extraListens will configure both the Varnish Cache and the Pod template to expose the given ports.

Using external ConfigMap

Often, it may be preferable to have VCL deployed as a ConfigMap in a separate Kubernetes deployment. In this case, configure server.vclConfig, server.extraVolumes, and server.extraVolumeMounts accordingly:

---
server:
  vclConfig: ""  # It is necessary to unset this value to override default.vcl

  extraVolumes:
    - name: external
      configMap:
        name: external-vcl

  extraVolumeMounts:
    - name: external
      mountPath: /etc/varnish/default.vcl
      subPath: default.vcl

In the case where server.vclConfigPath was configured to any value apart from the default, mountPath also needed to be changed to match that value.

Serving multiple domains

To serve multiple domains with Varnish Cache, it is highly recommended to use multiple VCL files and use cmdfile to load them. To do this with Varnish Cache Helm Chart, set server.cmdfileConfig, and server.vclConfigs accordingly:

---
server:
  vclConfigs:
    # We need an entrypoint VCL separately from default.vcl (which is now used as a fallback VCL)
    main.vcl: |
      vcl 4.1

      import std;

      sub vcl_recv {
        set req.http.host = std.tolower(req.http.host);
        if (req.http.host ~ "(^|\.)example\.com(\:[0-9]+)?$") {
          return (vcl(label_example));
        } elseif (req.http.host ~ "(^|\.)home\.arpa(\:[0-9]+)?$") {
          return (vcl(label_home));
        }
      }

    # Define VCL for each domains
    example.vcl: |
      # ...

    home.vcl: |
      # ...

  cmdfileConfig: |
    vcl.load vcl_example /etc/varnish/example.vcl
    vcl.label label_example
    vcl.load vcl_home /etc/varnish/home.vcl
    vcl.label label_home
    vcl.load vcl_main /etc/varnish/main.vcl
    vcl.use vcl_main

Instead of using server.vclConfigs, it is also possible to use external VCL for each domains by adapting the configuration from Using external ConfigMap section:

---
server:
  # ...omit...

  extraVolumes:
    - name: example
      configMap:
        name: example-vcl

    - name: home
      configMap:
        name: home-vcl

  extraVolumeMounts:
    - name: example
      mountPath: /etc/varnish/example.vcl
      subPath: example.vcl

    - name: home
      mountPath: /etc/varnish/home.vcl
      subPath: home.vcl

Using as a subchart

varnish-cache and varnish-enterprise share their named templates (varnish-common.*), and Helm keeps only one definition per template name. When both are dependencies of the same parent chart, depend on the same version of both: the two charts are always released together from the same sources, with the same version.

Upgrading

To 1.9.0: user and group changed from 999 to 1000

The chart version jumps from 0.1.x to 1.9.0, as varnish-cache and varnish-enterprise are now released together, with the same version.

The containers now run as user 1000 with fsGroup 1000, the varnish user and group of the official image, instead of 999.

Kubernetes changes the group ownership of most volumes to the new fsGroup (emptyDir, ConfigMaps, Secrets and most block-backed PersistentVolumeClaims), but not of hostPath volumes, in-tree nfs volumes or CSI volumes whose driver ignores fsGroup. If you mount such volumes with server.extraVolumes and they hold files written by user 999, either change their ownership before upgrading (chown -R 1000:1000 <path>), or keep the previous IDs:

global:
  podSecurityContext:
    fsGroup: 999
  securityContext:
    runAsUser: 999

The otel sidecar (server.otel) does not start with user 999, as it does not exist in the image.

On large PersistentVolumeClaims, setting global.podSecurityContext.fsGroupChangePolicy: OnRootMismatch avoids changing the ownership of every file each time a Pod starts.

Support

Community support for Varnish Helm Chart is provided via GitHub.

Please contact Varnish Software for a commercial support.

Configurations

Data types

string

A string. While the YAML spec does not require strings to be quoted, it is highly recommended to quote strings to prevent YAML type coercion (e.g., values such as country: NO are treated as country: false by YAML).

Example:

key1: "value"

## or multi-line
key2: |
  value

number

A number.

key1: 42

## or float
key2: 3.14

boolean

A true or false. While the YAML spec also treats keywords such as "yes" and "no" as true and false, respectively, it is highly recommended to use explicit true and false as the value for maintainability.

key1: true

object

A pair of key value.

key1:
  subkey1: "string"
  subkey2: 3.14
  subkey3: true

## alternatively, using JSON syntax
key2: { "subkey1": "string", "subkey2": 3.14, "subkey3": true }

array of objects

An array of objects.

key1:
  - name: "value1"
    subkey: "value"
  - name: "value2"
    subkey: "value"

array of strings

An array of strings.

key1:
  - "string1"
  - "string2"
  - "string3"

## alternatively, using JSON syntax
key1: ["string1", "string2", "string3"]

template string

A pair of key value as a string. Template functions exposed by Helm are available in this type.

key1: |
  subkey1: {{ .Release.Name | quote }}
  subkey2: "hello, world"

## in array of objects
key2: |
  - name: {{ .Release.Name | quote }}
    subkey1: "hello, world"

Chart configurations

nameOverride

  • Type: string
  • Default: name of the cart (e.g., varnish-cache)

Overrides the name of the chart (without the release name). For example, setting nameOverride to "hello" would produce a deployment named "release-name-hello". Containers within a pod derive their name from this setting.

By default, the name of the chart is used (i.e., "varnish-cache")

fullnameOverride

  • Type: string
  • Default: composition of a release name and name of the chart (e.g., "release-name-varnish-cache")

Overrides the full name of the chart (with the release name). This setting allows overriding both the release name and the deployment name altogether. For example, setting fullnameOverride to "hello" would produce a deployment named "hello".

Global configurations

global.imagePullSecrets

  • Type: array of object

An array of objects that conforms to the Kubernetes [imagePullSecrets][k8s-pod-v1-containers] definition. When set, each item in an array must consist of an object with a key name referencing the Kubernetes secret

For example:

global:
  imagePullSecrets:
    - name: registry-quay-k7c2f4m2d5

global.podSecurityContext

  • Type: object

An object that conforms to the Kubernetes [securityContext][k8s-pod-v1-pods] definition of a Pod

For example:

global:
  podSecurityContext:
    fsGroup: 1000

This securityContext will be set on all Pods within this chart. For setting securityContext on all containers, see global.securityContext.

global.securityContext

  • Type: object

An object that conforms to the Kubernetes [securityContext][k8s-pod-v1-containers] definition of a Container

For example:

global:
  securityContext:
    runAsUser: 1000
    runAsNonRoot: true

This securityContext will be set on all containers within this chart. For setting securityContext on the Pod itself, see global.podSecurityContext.

Service Account configurations

serviceAccount.create

  • Type: boolean
  • Default: true

Create a Kubernetes service account to use with the deployment.

serviceAccount.labels

  • Type: object or template string

Applies extra labels to the service account. The value can be set as either an object or a template string.

serviceAccount.annotations

  • Type: object or template string

Applies extra annotations to the service account. The value can be set as either an object or a template string.

serviceAccount.name

  • Type: string

Overrides the name of the service account. By default, the full name of the chart is used.

Server configurations

server.replicas

  • Type: number
  • Default: 1

Specifies the number of replicas to deploy Varnish Cache server. The value is ignored if server.autoscaling.enabled is set to true, or server.kind is "DaemonSet".

server.kind

  • Type: string
  • Default: Deployment

Specifies the type of deployment to deploy Varnish Cache server. The value can be one of Deployment, DaemonSet, or StatefulSet depending on usage scenarios (see examples).

server.labels

  • Type: object or template string

Applies extra labels to the deployment. The value can be set as either an object or a template string. Labels specified here will be applied to the deployment itself. To apply labels on the Pod, use server.podLabels.

server.annotations

  • Type: object or template string

Applies extra annotations to the deployment. The value can be set as either an object or a template string. Deployment annotations can be used to for applying additional metadata or for integrating with external tooling. The annotations specified here will be applied to the deployment itself. To apply labels on the Pod, use server.podAnnotations.

server.strategy

  • Type: object or template string

Configures [deployment strategy][k8s-deployment-strategy] to replace existing Pod with a new one. This configuration is only available when server.kind is set to Deployment. For StatefulSet and DaemonSet, see server.updateStrategy.

server.updateStrategy

  • Type: object or template string

Configures update strategy for updating Pods when a change is made to the manifest. This configuration is only available when server.kind is set to StatefulSet or DaemonSet. For Deployment, see server.strategy.

Note: While both StatefulSet and DaemonSet share the same updateStrategy configuration key, its applicable values are different. See [updateStrategy on StatefulSet][k8s-statefulset-updatestrategy] and [updateStrategy on DaemonSet][k8s-daemonset-updatestrategy].

server.shareProcessNamespace

  • Type: boolean

Whether to enable shared PID namespace between all containers in a Pod. This is useful for a scenario where it is necessary to send a signal to a process across a container.

server.workDir

  • Type: string
  • Default: ""

Sets the Varnish working directory (the -n argument of varnishd), relative to /var/lib/varnish. When set to "-", the Pod name is used. When empty, varnishd runs without -n and uses the Varnish default, so varnishstat, varnishadm and varnishlog work without -n in kubectl exec and in extra containers.

server.http.enabled

  • Type: boolean
  • Default: true

Configures Varnish to listen for HTTP traffic.

server.http.port

  • Type: number
  • Default: 6081

Configures the TCP port on which Varnish will listen for HTTP traffic. This port is used for Varnish to bin

Deploy varnish-cache with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has varnish-cache on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartvarnish-cache is pinned at v1.10.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply