Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Helm Chart #51

Merged
merged 18 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This repository contains a controller that allows you to operate a [Varnish cach
- [Detailed how-tos](#detailed-how-tos)
- [Using built in signaller component](#using-built-in-signaller-component)
- [Proxying to external services](#proxying-to-external-services)
- [Helm Chart Intallation](#helm-chart-installation)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -384,3 +385,47 @@ data:
```

When starting kube-httpcache, remember to set the `--backend-watch=false` flag to disable watching the (non-existent) backend endpoints.

## Helm Chart installation

Using [HELM](chart/) to rollout an instance of kube-httpcache.

Ensure your defined frontend and backend services have a port
name `http`:
eumel8 marked this conversation as resolved.
Show resolved Hide resolved

```
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
type: ClusterIP
```

An ingress points to the kube-httpcache service which cached
your backend service:

```
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
spec:
rules:
- host: www.example.com
http:
paths:
- backend:
serviceName: kube-httpcache
servicePort: 80
path: /
```

Look at the [Varnish Go Template file](chart/varnish.tpl) to define
your own Varnish cluster rules or load the file as initContainer.
eumel8 marked this conversation as resolved.
Show resolved Hide resolved

23 changes: 23 additions & 0 deletions chart/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
8 changes: 8 additions & 0 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: kube-httpcache
description: Varnish on Kubernetes Helm Chart
version: 0.0.1
appVersion: 0.0.1
home: https://varnish-cache.org
icon: https://varnish-cache.org/_static/varnish-bunny.png
sources:
- https://github.com/mittwald/kube-httpcache
3 changes: 3 additions & 0 deletions chart/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Ensure your backend-service has a port name 'http' and create an ingress
point to the kube-httpcache service. Enjoy your Varnish cache!

62 changes: 62 additions & 0 deletions chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "kube-httpcache.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "kube-httpcache.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "kube-httpcache.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "kube-httpcache.labels" -}}
helm.sh/chart: {{ include "kube-httpcache.chart" . }}
{{ include "kube-httpcache.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "kube-httpcache.selectorLabels" -}}
app.kubernetes.io/name: {{ include "kube-httpcache.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "kube-httpcache.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "kube-httpcache.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
9 changes: 9 additions & 0 deletions chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- if .Values.configmap.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.cache.configmapname }}
data:
default.vcl.tmpl: |
{{ .Files.Get .Values.cache.template | indent 4}}
{{- end }}
120 changes: 120 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{{- if .Values.deployment.enabled -}}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "kube-httpcache.fullname" . }}
labels:
{{- include "kube-httpcache.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "kube-httpcache.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "kube-httpcache.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "kube-httpcache.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- if .Values.extraInitContainers }}
initContainers:
{{- with .Values.extraInitContainers }}
{{- tpl . $ | nindent 8 }}
{{- end }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.livenessprobe }}
livenessProbe:
{{- with .Values.livenessprobe }}
{{- tpl . $ | trim | nindent 12 }}
{{- end }}
{{- end }}
{{- if .Values.readinessprobe }}
readinessProbe:
{{- with .Values.readinessprobe }}
{{- tpl . $ | trim | nindent 12 }}
{{- end }}
{{- end }}
args:
- -admin-addr=0.0.0.0
- -admin-port=6083
- -signaller-enable
- -signaller-port=8090
- -frontend-watch
- -frontend-namespace=$(NAMESPACE)
- -frontend-service={{ .Values.cache.frontendservice }}
- -backend-watch
martin-helmich marked this conversation as resolved.
Show resolved Hide resolved
- -backend-namespace=$(NAMESPACE)
- -backend-service={{ .Values.cache.backendservice }}
- -varnish-secret-file=/etc/varnish/k8s-secret/secret
- -varnish-vcl-template=/etc/varnish/tmpl/default.vcl.tmpl
- -varnish-storage={{ .Values.cache.varnishstorage }},{{ .Values.cache.storagesize }}
{{- if .Values.cacheextraargs }}
{{- with .Values.cacheextraargs }}
{{- tpl . $ | trim | nindent 10 }}
{{- end }}
{{- end }}
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumeMounts:
- name: template
mountPath: /etc/varnish/tmpl
eumel8 marked this conversation as resolved.
Show resolved Hide resolved
- name: secret
mountPath: /etc/varnish/k8s-secret
{{- if .Values.extraMounts }}
{{- with .Values.extraMounts }}
{{- tpl . $ | trim | nindent 10 }}
{{- end }}
{{- end }}
{{- if .Values.resources }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- end }}
volumes:
{{- if .Values.configmap.enabled }}
- name: template
configMap:
name: {{ .Values.cache.configmapname }}
{{- end }}
- name: secret
secret:
secretName: {{ .Values.cache.secretname}}
{{- if .Values.extraVolumes -}}
{{- with .Values.extraVolumes -}}
{{- tpl . $ | trim | nindent 6 }}
{{- end }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
28 changes: 28 additions & 0 deletions chart/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "kube-httpcache.fullname" . }}
labels:
{{- include "kube-httpcache.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
eumel8 marked this conversation as resolved.
Show resolved Hide resolved
name: {{ include "kube-httpcache.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
39 changes: 39 additions & 0 deletions chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{- if .Values.ingress.enabled -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
eumel8 marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}
kind: Ingress
metadata:
name: {{ include "kube-httpcache.fullname" . }}
labels:
{{- include "kube-httpcache.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
backend:
serviceName: {{ .backend.serviceName }}
servicePort: {{ .backend.servicePort }}
{{- end }}
eumel8 marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}
{{- end }}
Loading