kustomization.yaml file:
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yaml
configMapGenerator:
- name: varnish-config
files:
- default.vcl
Varnish deployment.yaml:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dev-justynio-ghost-varnish-deployment
labels:
app: ghost-varnish
domain: dev.justyn.io
spec:
replicas: 1
selector:
matchLabels:
app: ghost-varnish
domain: dev.justyn.io
template:
metadata:
labels:
app: ghost-varnish
domain: dev.justyn.io
spec:
containers:
- name: varnish
image: varnish:6.4
imagePullPolicy: Always
ports:
- containerPort: 80
volumeMounts:
- mountPath: /etc/varnish/default.vcl
name: varnish-config
subPath: default.vcl
volumes:
- name: varnish-config
configMap:
name: varnish-config
items:
- key: default.vcl
path: default.vcl
Varnish service.yaml:
---
kind: Service
apiVersion: v1
metadata:
name: dev-justynio-ghost-varnish-svc
spec:
selector:
app: ghost-varnish
domain: dev.justyn.io
ports:
- protocol: TCP
port: 80
targetPort: 80
Example Varnish configuration file, default.vcl, used in the above kustomization.yaml:
vcl 4.0;
backend default {
.host = "dev-justynio-ghost-svc:80";
}
Not shown: The above examples are copied from a deployment where I have Varnish sitting in front of Ghost. The traffic flows from nginx-ingress to Varnish and then to ghost. My ingress definition points to the Varnish service, but the varnish configuration itself points to the Ghost service.
References