From 88a7db28d154d446b9b57f7beef9a398e107c4a0 Mon Sep 17 00:00:00 2001 From: Ashley Schuett Date: Thu, 31 Oct 2019 10:50:00 +0100 Subject: [PATCH 1/2] add kubernets charts --- janus/.helmignore | 22 +++++++ janus/Chart.yaml | 5 ++ janus/templates/NOTES.txt | 21 ++++++ janus/templates/_helpers.tpl | 49 ++++++++++++++ janus/templates/deployment.yaml | 56 ++++++++++++++++ janus/templates/ingress.yaml | 36 +++++++++++ janus/templates/pdb.yaml | 12 ++++ janus/templates/service.yaml | 15 +++++ janus/templates/tests/test-connection.yaml | 15 +++++ janus/values.yaml | 75 ++++++++++++++++++++++ 10 files changed, 306 insertions(+) create mode 100644 janus/.helmignore create mode 100644 janus/Chart.yaml create mode 100644 janus/templates/NOTES.txt create mode 100644 janus/templates/_helpers.tpl create mode 100644 janus/templates/deployment.yaml create mode 100644 janus/templates/ingress.yaml create mode 100644 janus/templates/pdb.yaml create mode 100644 janus/templates/service.yaml create mode 100644 janus/templates/tests/test-connection.yaml create mode 100644 janus/values.yaml diff --git a/janus/.helmignore b/janus/.helmignore new file mode 100644 index 000000000..50af03172 --- /dev/null +++ b/janus/.helmignore @@ -0,0 +1,22 @@ +# 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 +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/janus/Chart.yaml b/janus/Chart.yaml new file mode 100644 index 000000000..cbf417ab4 --- /dev/null +++ b/janus/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: A Helm chart for Kubernetes +name: janus +version: 0.1.0 diff --git a/janus/templates/NOTES.txt b/janus/templates/NOTES.txt new file mode 100644 index 000000000..f4596a1ca --- /dev/null +++ b/janus/templates/NOTES.txt @@ -0,0 +1,21 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "janus.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "janus.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "janus.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "janus.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/janus/templates/_helpers.tpl b/janus/templates/_helpers.tpl new file mode 100644 index 000000000..9b7c55d10 --- /dev/null +++ b/janus/templates/_helpers.tpl @@ -0,0 +1,49 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "janus.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 "janus.fullname" -}} +{{- if .name -}} +{{- .name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- 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 -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "janus.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "janus.labels" -}} +app.kubernetes.io/name: {{ include "janus.name" . }} +helm.sh/chart: {{ include "janus.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} diff --git a/janus/templates/deployment.yaml b/janus/templates/deployment.yaml new file mode 100644 index 000000000..f9bd8aad4 --- /dev/null +++ b/janus/templates/deployment.yaml @@ -0,0 +1,56 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "janus.fullname" . }} + labels: +{{ include "janus.labels" . | indent 4 }} +spec: + replicas: {{ .Values.deployment.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "janus.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "janus.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + {{- with .Values.deployment.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + - containerPort: 8081 + name: http-private + protocol: TCP + env: + {{- if .Values.configMap }} + {{- range $key, $value := .Values.envConfig }} + - name: {{ $key | quote }} + value: {{ $value | quote }} + {{- end }} + {{- end }} + - name: "DATABASE_DSN" + value: "{{ .Values.databaseDSN }}" + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/janus/templates/ingress.yaml b/janus/templates/ingress.yaml new file mode 100644 index 000000000..895d5e5e4 --- /dev/null +++ b/janus/templates/ingress.yaml @@ -0,0 +1,36 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "janus.fullname" ( dict "name" .Values.ingress.name ) -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: +{{ include "janus.labels" . | indent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end -}} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ .port }} + {{- end }} + {{- end }} +{{- end }} diff --git a/janus/templates/pdb.yaml b/janus/templates/pdb.yaml new file mode 100644 index 000000000..25ab04deb --- /dev/null +++ b/janus/templates/pdb.yaml @@ -0,0 +1,12 @@ +apiVersion: policy/v1beta1 +kind: PodDisruptionBudget +metadata: + name: {{ include "janus.fullname" . }} + labels: +{{ include "janus.labels" . | indent 4 }} +spec: + minAvailable: {{ .Values.deployment.minAvailable }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "janus.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/janus/templates/service.yaml b/janus/templates/service.yaml new file mode 100644 index 000000000..ff3b49e18 --- /dev/null +++ b/janus/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "janus.fullname" ( dict "name" .Values.service.name ) }} + labels: +{{ include "janus.labels" . | indent 4 }} +spec: + type: {{ .Values.service.type }} + {{- with .Values.service.ports }} + ports: + {{- toYaml . | nindent 4 }} + {{- end }} + selector: + app.kubernetes.io/name: {{ include "janus.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/janus/templates/tests/test-connection.yaml b/janus/templates/tests/test-connection.yaml new file mode 100644 index 000000000..e11e1fd70 --- /dev/null +++ b/janus/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "janus.fullname" ( dict "Values" .Values "Chart" .Chart "Release" .Release "name" .Values.name ) }}-test-connection" + labels: +{{ include "janus.labels" . | indent 4 }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "janus.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/janus/values.yaml b/janus/values.yaml new file mode 100644 index 000000000..bbb00f97c --- /dev/null +++ b/janus/values.yaml @@ -0,0 +1,75 @@ +# Default values for janus. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +nameOverride: "" +fullnameOverride: "" + +deployment: + replicaCount: 2 + minAvailable: 1 + databaseDSN: "mongodb://janus-database:27017/janus" + +imagePullSecrets: [] + +image: + repository: quay.io/hellofresh/janus + tag: latest + pullPolicy: IfNotPresent + +service: + name: ops-gateway + type: ClusterIP + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + name: http + - protocol: TCP + port: 443 + targetPort: 8080 + name: https + - protocol: TCP + port: 8081 + targetPort: 8081 + name: http-private + +ingress: + enabled: false + name: ops-gateway + annotations: + kubernetes.io/ingress.class: "nginx" + disable-external-dns: "true" + nginx.ingress.kubernetes.io/force-ssl-redirect: "true" + hosts: + - host: gateway.sample.com + paths: + - path: / + port: 80 + - host: admin-gateway.sample.com + paths: + - path: / + port: 8081 + + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} From 222e3ba4c9cbbf56815652374813d4c9a66186b3 Mon Sep 17 00:00:00 2001 From: Ashley Schuett Date: Thu, 31 Oct 2019 12:08:21 +0100 Subject: [PATCH 2/2] add Janus Helm README.md --- janus/README.md | 57 +++++++++++++++++++++++++++++++++ janus/templates/deployment.yaml | 4 +-- janus/templates/ingress.yaml | 2 +- janus/values.yaml | 4 +-- 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 janus/README.md diff --git a/janus/README.md b/janus/README.md new file mode 100644 index 000000000..3ce07bddd --- /dev/null +++ b/janus/README.md @@ -0,0 +1,57 @@ +## Prerequisites + +- Kubernetes 1.12+ +- Helm 2.11+ + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```console +$ helm install --name my-release janus +``` + +The command deploys Janus on the Kubernetes cluster in the default configuration. The [Parameters](#parameters) section lists the parameters that can be configured during installation. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```console +$ helm delete my-release +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Parameters + +The following table lists the configurable parameters of the Janus chart and their default values. + +| Parameter | Description | Default | +|-------------------------------------|---------------------------------------------------------------|----------------------------------------------------------| +| `image.repository` | Janus Image name | `quay.io/hellofresh/janus` | +| `image.tag` | Janus Image tag | `latest` | +| `image.pullPolicy` | Janus pull policy | `IfNotPresent` | +| `image.pullSecrets` | Specify docker-registry secret names as an array | `[]` (does not add image pull secrets to deployed pods) | +| `nameOverride` | String to partially override janus.fullname template with a string (will prepend the release name) | `nil` | +| `fullnameOverride` | String to fully override janus.fullname template with a string | `nil` | +| `allowEmptyPassword` | Allow DB blank passwords | `yes` | +| `deployment.replicaCount` | Number of Janus pod replicas | `2` | +| `deployment.minAvailable` | Creates PDB is min available (must be less than replicaCount) | `1` | +| `deployment.databaseDSN` | Database connection string | `mongodb://janus-database:27017/janus` | +| `service.type` | Kubernetes Service type | `LoadBalancer` | +| `service.name` | Override service name | `` | +| `service.ports[0].protocol` | Service HTTP protocol | `TCP` | +| `service.ports[0].port` | Service HTTP port | `80` | +| `service.ports[0].targetPort` | Service HTTP target container port | `8080` | +| `service.ports[0].name` | Service HTTP port name | `http` | +| `ingress.enabled` | Enable ingress controller resource | `false` | +| `ingress.annotations` | Ingress annotations | `[]` | +| `ingress.name` | Override ingress name | `` | +| `ingress.hosts[0].name` | Hostname to your Janus installation | `janus.local` | +| `ingress.hosts[0].paths[0].port` | Port to service | `80` | +| `ingress.hosts[0].paths[0].path` | Path within the url structure | `/` | +| `resources` | CPU/Memory resource requests/limits | Memory: `512Mi`, CPU: `300m` | +| `affinity` | Map of node/pod affinities | `{}` | diff --git a/janus/templates/deployment.yaml b/janus/templates/deployment.yaml index f9bd8aad4..d468799b7 100644 --- a/janus/templates/deployment.yaml +++ b/janus/templates/deployment.yaml @@ -32,14 +32,14 @@ spec: name: http-private protocol: TCP env: - {{- if .Values.configMap }} + {{- if .Values.envConfig }} {{- range $key, $value := .Values.envConfig }} - name: {{ $key | quote }} value: {{ $value | quote }} {{- end }} {{- end }} - name: "DATABASE_DSN" - value: "{{ .Values.databaseDSN }}" + value: "{{ .Values.deployment.databaseDSN }}" resources: {{- toYaml .Values.resources | nindent 12 }} {{- with .Values.nodeSelector }} diff --git a/janus/templates/ingress.yaml b/janus/templates/ingress.yaml index 895d5e5e4..4a44d1bd9 100644 --- a/janus/templates/ingress.yaml +++ b/janus/templates/ingress.yaml @@ -9,7 +9,7 @@ metadata: {{- with .Values.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} - {{- end -}} + {{- end }} spec: {{- if .Values.ingress.tls }} tls: diff --git a/janus/values.yaml b/janus/values.yaml index bbb00f97c..b589c8a8b 100644 --- a/janus/values.yaml +++ b/janus/values.yaml @@ -15,7 +15,7 @@ imagePullSecrets: [] image: repository: quay.io/hellofresh/janus tag: latest - pullPolicy: IfNotPresent + pullPolicy: Always service: name: ops-gateway @@ -38,8 +38,6 @@ ingress: enabled: false name: ops-gateway annotations: - kubernetes.io/ingress.class: "nginx" - disable-external-dns: "true" nginx.ingress.kubernetes.io/force-ssl-redirect: "true" hosts: - host: gateway.sample.com