Skip to content

Commit

Permalink
varnish deployment files are added, closes #23
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalcaliskan committed Dec 6, 2021
1 parent 2a98dc1 commit 145c324
Show file tree
Hide file tree
Showing 12 changed files with 387 additions and 98 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Go version](https://img.shields.io/github/go-mod/go-version/bilalcaliskan/varnish-cache-invalidator)](https://github.com/bilalcaliskan/varnish-cache-invalidator)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

This tool basically multiplexes **BAN** and **PURGE** requests on [Varnish Cache](https://github.com/varnishcache/varnish-cache)
This tool basically multiplexes **PURGE** requests on [Varnish Cache](https://github.com/varnishcache/varnish-cache)
instances at the same time to manage the cache properly. If you are using Varnish Enterprise, you already have that feature.

varnish-cache-invalidator can be used for standalone Varnish instances or Varnish pods inside a Kubernetes cluster.
Expand All @@ -25,7 +25,7 @@ Please check all the command line arguments on **Configuration** section. Requir

**Kubernetes mode**
In that mode, varnish-cache-invalidator discovers kube-apiserver for running [Varnish](https://github.com/varnishcache/varnish-cache) pods inside
Kubernetes and multiplexes **BAN** and **PURGE** requests on them at the same time to manage the cache properly.
Kubernetes and multiplexes **PURGE** requests on them at the same time to manage the cache properly.

Please check all the command line arguments on **Configuration** section. Required args for Kubernetes mode:
```
Expand All @@ -34,11 +34,21 @@ Please check all the command line arguments on **Configuration** section. Requir

## Installation
### Kubernetes
varnish-cache invalidator requires Kustomize for in-kubernetes installations. You can refer [here](https://kustomize.io/) for
Kustomize installation.

Varnish-cache-invalidator can be run inside a Kubernetes cluster to multiplex requests for in-cluster Varnish containers.
You can use [sample deployment file](deployment/sample.yaml) to deploy your Kubernetes cluster.
You can use [deployment/invalidator](deployment/invalidator) folder to deploy it with sample configuration. For that, please
run below command in the [deployment/invalidator](deployment/invalidator) directory:
```shell
$ kustomize build . | kubectl apply -f -
```

If you need to also deploy Varnish on Kubernetes, you can use [deployment/varnish](deployment/varnish) folder to deploy it
with sample [default.vcl](deployment/varnish/default.vcl). For that, please run below command in the [deployment/varnish](deployment/varnish)
directory:
```shell
$ kubectl create -f config/sample.yaml
$ kustomize build . | kubectl apply -f -
```

### Standalone
Expand All @@ -52,7 +62,7 @@ $ ./varnish-cache-invalidator --inCluster=false --targetHosts 10.0.0.100:6081,10

## Configuration
Varnish-cache-invalidator can be customized with several command line arguments. You can pass command line arguments via
[sample deployment file](deployment/sample.yaml). Here is the list of arguments you can pass:
[sample deployment file](deployment/invalidator/sample.yaml). Here is the list of arguments you can pass:

```
--inCluster bool InCluster is the boolean flag if varnish-cache-invalidator is running inside cluster or not,
Expand Down Expand Up @@ -85,7 +95,7 @@ varnish-cache-invalidator uses [client-go](https://github.com/kubernetes/client-
with `kube-apiserver`. [client-go](https://github.com/kubernetes/client-go) uses the [service account token](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/)
mounted inside the Pod at the `/var/run/secrets/kubernetes.io/serviceaccount` path while initializing the client.

If you have RBAC enabled on your cluster, when you applied the sample deployment file [deployment/sample.yaml](deployment/sample.yaml),
If you have RBAC enabled on your cluster, when you applied the sample deployment file [deployment/sample.yaml](deployment/invalidator/sample.yaml),
it will create required serviceaccount and clusterrolebinding and then use that serviceaccount to be used
by our varnish-cache-invalidator pods.

Expand Down
14 changes: 14 additions & 0 deletions deployment/invalidator/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: varnish-cache-invalidator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: view
subjects:
- kind: ServiceAccount
name: varnish-cache-invalidator
namespace: default
53 changes: 3 additions & 50 deletions deployment/sample.yaml → deployment/invalidator/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
---

apiVersion: v1
kind: ServiceAccount
metadata:
name: varnish-cache-invalidator
namespace: default

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: varnish-cache-invalidator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: view
subjects:
- kind: ServiceAccount
name: varnish-cache-invalidator
namespace: default

---

apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -46,9 +23,9 @@ spec:
containers:
- command: [ "./main" ]
args: [
"--varnishNamespace", "default",
"--varnishLabel", "'app=varnish'",
"--inCluster=true"
"--varnishNamespace", "default",
"--varnishLabel", "'app=varnish'",
"--inCluster=true"
]
image: 'docker.io/bilalcaliskan/varnish-cache-invalidator:latest'
imagePullPolicy: Always
Expand All @@ -74,27 +51,3 @@ spec:
tcpSocket:
port: 3000
timeoutSeconds: 10

---

apiVersion: v1
kind: Service
metadata:
labels:
app: varnish-cache-invalidator
name: varnish-cache-invalidator
spec:
ports:
- name: 3000-tcp
port: 3000
protocol: TCP
targetPort: 3000
- name: 3001-tcp
port: 3001
protocol: TCP
targetPort: 3001
selector:
app: varnish-cache-invalidator
deployment: varnish-cache-invalidator
sessionAffinity: None
type: NodePort
10 changes: 10 additions & 0 deletions deployment/invalidator/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- serviceaccount.yaml
- clusterrolebinding.yaml
- deployment.yaml
- service.yaml
23 changes: 23 additions & 0 deletions deployment/invalidator/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

apiVersion: v1
kind: Service
metadata:
labels:
app: varnish-cache-invalidator
name: varnish-cache-invalidator
spec:
ports:
- name: 3000-tcp
port: 3000
protocol: TCP
targetPort: 3000
- name: 3001-tcp
port: 3001
protocol: TCP
targetPort: 3001
selector:
app: varnish-cache-invalidator
deployment: varnish-cache-invalidator
sessionAffinity: None
type: NodePort
7 changes: 7 additions & 0 deletions deployment/invalidator/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

apiVersion: v1
kind: ServiceAccount
metadata:
name: varnish-cache-invalidator
namespace: default
Loading

0 comments on commit 145c324

Please sign in to comment.