Code Monkey home page Code Monkey logo

varnish-cache-invalidator's Introduction

Varnish Cache Invalidator

CI Docker pulls Go Report Card Quality Gate Status Reliability Rating Maintainability Rating Security Rating Coverage Release Go version License

This tool basically multiplexes PURGE requests on 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.

Standalone mode In that mode, varnish-cache-invalidator multiplexes requests on static standalone Varnish instances which are provided with --targetHosts flag. This flag gets comma seperated list of hosts.

Please check all the command line arguments on Configuration section. Required args for standalone mode:

--inCluster=false
--targetHosts

Kubernetes mode In that mode, varnish-cache-invalidator discovers kube-apiserver for running Varnish pods inside 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:

--inCluster=true

Installation

Kubernetes

varnish-cache invalidator requires Kustomize for in-kubernetes installations. You can refer here for Kustomize installation.

If you run below command in the deployment directory, it will take following actions:

  • Deploy varnish-cache-invalidator in the default namespace
  • Deploy varnish instance with sample default.vcl for testing purposes in the default namespace
  • Deploy nginx instance for testing purposes in the default namespace

Here is the command:

$ kustomize build . | kubectl apply -f -

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:

$ curl ${WORKER_NODE_IP}:${VARNISH_NODE_PORT} -H "Host: nginx.default.svc" -v
... omitted
Age: 22
X-Cache: HIT
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 directory:

$ 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 page.

After then, you can simply run binary by providing required command line arguments:

$ ./varnish-cache-invalidator --inCluster=false --targetHosts 10.0.0.100:6081,10.0.0.101:6081,10.0.0.102:6081

Configuration

Varnish-cache-invalidator can be customized with several command line arguments. You can check sample in-Kubernetes deployment file for how it goes. 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,
                                        defaults to true
--varnishNamespace          string      VarnishNamespace is the namespace of the target Varnish pods, defaults to default namespace
--varnishLabel              string      VarnishLabel is the label to select proper Varnish pods, defaults to app=varnish
--targetHosts               string      TargetHosts used when our Varnish instances(comma seperated) are not running in Kubernetes as
                                        a pod, required for standalone Varnish instances, defaults to 'http://127.0.0.1:6081'
--serverPort                int         ServerPort is the web server port of the varnish-cache-invalidator, defaults to 3000
--metricsPort               int         MetricsPort is the port of the metrics server, defaults to 3001
--writeTimeoutSeconds       int         WriteTimeoutSeconds is the write timeout of the both web server and metrics server, defaults to 10
--readTimeoutSeconds        int         ReadTimeoutSeconds is the read timeout of the both web server and metrics server, defaults to 10

Examples

TBD

Development

This project requires below tools while developing:

After you installed pre-commit, simply run below command to prepare your development environment:

$ pre-commit install -c build/ci/.pre-commit-config.yaml

License

Apache License 2.0

How varnish-cache-invalidator handles authentication with kube-apiserver in Kubernetes mode?

varnish-cache-invalidator uses client-go to interact with kube-apiserver. client-go uses the service account token 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 followed the deployment steps on Kubernetes section, it will create required serviceaccount and clusterrolebinding and then use that serviceaccount to be used by our varnish-cache-invalidator pods.

If RBAC is not enabled on your cluster, please follow that documentation to enable it.

varnish-cache-invalidator's People

Contributors

bilalcaliskan avatar dependabot[bot] avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

0xfrej

varnish-cache-invalidator's Issues

maintenance of the project

  • cobra integration
  • refactor the coding style
  • refactor business flow
  • check if everything is working as expected
  • return json response from API
  • increase coverage
  • generate custom metrics if needed
  • examples section on readme for example requests for each function

sonarcloud integration

  • create a project from sonarcloud UI
  • get the token and add as secret on Github
  • get the badge and add to README.md
  • create sonar-project.properties
  • remove windows from everywhere
  • add sonarcloud job
  • add "types: [opened, synchronize, reopened]โ€ on pr.yml
  • create a PR over devel branch
  • squash and merge if everything is OK

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.