Skip to content

Commit

Permalink
erge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalcaliskan committed Dec 7, 2021
2 parents c72f228 + 37f79b5 commit b41e649
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 22 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,19 @@ Please check all the command line arguments on **Configuration** section. Requir
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 [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 run below command in the [deployment](deployment) directory, it will take following actions:
- Deploy varnish-cache-invalidator in the default namespace
- Deploy varnish instance with sample [default.vcl](deployment/varnish/default.vcl) for testing purposes in the default namespace
- Deploy nginx instance for testing purposes in the default namespace

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:
Here is the command:
```shell
$ kustomize build . | kubectl apply -f -
```

[deployment/varnish](deployment/varnish) directory will help you to spin up an in-cluster cache solution quickly. It will also deploy a sample
Nginx with 2 replicas. When you make a GET request to the varnish instance with proper header, you will get following response. Notice **X-Cache**
and **X-Cache-Hits** response headers. This indicates that our requests are successfully hitting the varnish:
After all of the deployments are succeeded, when you make a GET request to the varnish instance with proper header,
you will get following response. Notice **X-Cache** and **X-Cache-Hits** response headers. This indicates that our
requests are successfully hitting the varnish:
```shell
$ curl ${WORKER_NODE_IP}:${VARNISH_NODE_PORT} -H "Host: nginx.default.svc" -v
... omitted
Expand All @@ -63,6 +59,12 @@ X-Cache-Hits: 12
... omitted
```

And yes, you can deploy each component separately to the Kubernetes with previous command on relevant directory. For example
if you just want to deploy varnish-cache-invalidator, run below command in [deployment/invalidator](deployment/invalidator) directory:
```shell
$ kustomize build . | kubectl apply -f -
```

### Standalone
You can use binary method to manage standalone Varnish instances, not in Kubernetes. Binary can
be downloaded from [Releases](https://github.com/bilalcaliskan/nginx-conf-generator/releases) page.
Expand Down
2 changes: 1 addition & 1 deletion cmd/varnish-cache-invalidator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
// below check ensures that if our Varnish instances inside kubernetes or not
if opts.InCluster {
logger.Info("will use kubernetes pod instances, running pod informer to fetch pods")
// k8s.InitK8sTypes()
k8s.InitK8sTypes()
go k8s.RunPodInformer()
} else {
splitted := strings.Split(opts.TargetHosts, ",")
Expand Down
1 change: 0 additions & 1 deletion deployment/invalidator/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ roleRef:
subjects:
- kind: ServiceAccount
name: varnish-cache-invalidator
namespace: default
1 change: 0 additions & 1 deletion deployment/invalidator/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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

resources:
- serviceaccount.yaml
- clusterrolebinding.yaml
Expand Down
1 change: 0 additions & 1 deletion deployment/invalidator/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: varnish-cache-invalidator
namespace: default
9 changes: 9 additions & 0 deletions deployment/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: default
resources:
- ./invalidator
- ./varnish
- ./nginx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: default
labels:
app: nginx
spec:
Expand Down
7 changes: 7 additions & 0 deletions deployment/nginx/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yaml
14 changes: 14 additions & 0 deletions deployment/nginx/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---

apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
ports:
- name: "http"
port: 80
targetPort: 80
selector:
app: nginx
type: NodePort
1 change: 0 additions & 1 deletion deployment/varnish/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: varnish
namespace: default
spec:
replicas: 2
selector:
Expand Down
3 changes: 0 additions & 3 deletions deployment/varnish/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

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

resources:
- deployment.yaml
- service.yaml
- nginx_deployment.yaml
- nginx_service.yaml

configMapGenerator:
- name: varnish-config
Expand Down
1 change: 0 additions & 1 deletion deployment/varnish/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apiVersion: v1
kind: Service
metadata:
name: varnish
namespace: default
spec:
ports:
- name: "http"
Expand Down

0 comments on commit b41e649

Please sign in to comment.