From 6fb685e6dafd433dc02006a1335d32bbdfaa2264 Mon Sep 17 00:00:00 2001 From: Milos Pejanovic Date: Sat, 11 Apr 2020 21:21:46 +0200 Subject: [PATCH] Add a chart for db services --- example/configurd/charts/db/.helmignore | 22 +++++ example/configurd/charts/db/Chart.yaml | 5 ++ .../charts/db/templates/_helpers.tpl | 32 +++++++ .../charts/db/templates/deployment.yaml | 65 +++++++++++++++ example/configurd/charts/db/templates/pv.yaml | 20 +++++ .../configurd/charts/db/templates/pvc.yaml | 18 ++++ .../charts/db/templates/service.yaml | 15 ++++ .../db/templates/tests/test-connection.yaml | 18 ++++ example/configurd/charts/db/values.yaml | 83 +++++++++++++++++++ .../charts/example/templates/deployment.yaml | 2 +- 10 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 example/configurd/charts/db/.helmignore create mode 100644 example/configurd/charts/db/Chart.yaml create mode 100644 example/configurd/charts/db/templates/_helpers.tpl create mode 100644 example/configurd/charts/db/templates/deployment.yaml create mode 100644 example/configurd/charts/db/templates/pv.yaml create mode 100644 example/configurd/charts/db/templates/pvc.yaml create mode 100644 example/configurd/charts/db/templates/service.yaml create mode 100644 example/configurd/charts/db/templates/tests/test-connection.yaml create mode 100644 example/configurd/charts/db/values.yaml diff --git a/example/configurd/charts/db/.helmignore b/example/configurd/charts/db/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/example/configurd/charts/db/.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/example/configurd/charts/db/Chart.yaml b/example/configurd/charts/db/Chart.yaml new file mode 100644 index 0000000..1acec27 --- /dev/null +++ b/example/configurd/charts/db/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: An Example Chart for Configurd +name: db +version: 0.1.0 diff --git a/example/configurd/charts/db/templates/_helpers.tpl b/example/configurd/charts/db/templates/_helpers.tpl new file mode 100644 index 0000000..e2907af --- /dev/null +++ b/example/configurd/charts/db/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "example.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 "example.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 "example.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/example/configurd/charts/db/templates/deployment.yaml b/example/configurd/charts/db/templates/deployment.yaml new file mode 100644 index 0000000..d9fade1 --- /dev/null +++ b/example/configurd/charts/db/templates/deployment.yaml @@ -0,0 +1,65 @@ +{{- $pvc := printf "%s-pvc" .Release.Name }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: "{{ .Release.Name }}" + labels: + app.kubernetes.io/name: {{ .Release.Name }} + app.kubernetes.io/part-of: {{ .Values.group }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + helm.sh/chart: "{{ .Release.Name }}-{{ .Release.Revision }}" +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ .Release.Name }} + app.kubernetes.io/part-of: {{ .Values.group }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ .Release.Name }} + app.kubernetes.io/part-of: {{ .Values.group }} + spec: + containers: + - name: {{ .Release.Name }} + image: {{ .Values.image.repository }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + {{- toYaml .Values.args | nindent 12 }} + env: + {{- toYaml .Values.env | nindent 12 }} + ports: + - name: container-port + containerPort: {{ .Values.service.containerPort }} + protocol: TCP + livenessProbe: + tcpSocket: + port: container-port + readinessProbe: + tcpSocket: + port: container-port + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + {{- range .Values.volumeMounts }} + - name: {{ .name }} + mountPath: {{ .path }} + {{- end }} + volumes: + {{- range .Values.volumeMounts }} + - name: {{ .name }} + persistentVolumeClaim: + claimName: {{ $pvc }} + {{- 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 }} diff --git a/example/configurd/charts/db/templates/pv.yaml b/example/configurd/charts/db/templates/pv.yaml new file mode 100644 index 0000000..b271159 --- /dev/null +++ b/example/configurd/charts/db/templates/pv.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: "{{ .Release.Name }}-pv" + labels: + app.kubernetes.io/name: {{ .Release.Name }} + app.kubernetes.io/part-of: {{ .Values.group }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + helm.sh/chart: "{{ .Release.Name }}-{{ .Release.Revision }}" +spec: + storageClassName: manual + capacity: + storage: {{ .Values.persistentVolume.size }} + {{- with .Values.persistentVolume.accessModes }} + accessModes: + {{- toYaml . | nindent 4 }} + {{- end }} + persistentVolumeReclaimPolicy: {{ .Values.persistentVolume.ReclaimPolicy }} + hostPath: + path: {{ .Values.persistentVolume.path }} \ No newline at end of file diff --git a/example/configurd/charts/db/templates/pvc.yaml b/example/configurd/charts/db/templates/pvc.yaml new file mode 100644 index 0000000..391b1cf --- /dev/null +++ b/example/configurd/charts/db/templates/pvc.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: "{{ .Release.Name }}-pvc" + labels: + app.kubernetes.io/name: {{ .Release.Name }} + app.kubernetes.io/part-of: {{ .Values.group }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + helm.sh/chart: "{{ .Release.Name }}-{{ .Release.Revision }}" +spec: + storageClassName: manual + {{- with .Values.persistentVolume.accessModes }} + accessModes: + {{- toYaml . | nindent 4 }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistentVolume.size }} diff --git a/example/configurd/charts/db/templates/service.yaml b/example/configurd/charts/db/templates/service.yaml new file mode 100644 index 0000000..7a26667 --- /dev/null +++ b/example/configurd/charts/db/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }} + labels: + app.kubernetes.io/name: {{ .Release.Name }} + app.kubernetes.io/part-of: {{ .Values.group }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + helm.sh/chart: "{{ .Release.Name }}-{{ .Release.Revision }}" +spec: + selector: + app.kubernetes.io/name: {{ .Release.Name }} + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.containerPort }} \ No newline at end of file diff --git a/example/configurd/charts/db/templates/tests/test-connection.yaml b/example/configurd/charts/db/templates/tests/test-connection.yaml new file mode 100644 index 0000000..29c7bec --- /dev/null +++ b/example/configurd/charts/db/templates/tests/test-connection.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "example.fullname" . }}-test-connection" + labels: + app.kubernetes.io/name: {{ include "example.name" . }} + helm.sh/chart: {{ include "example.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "example.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/example/configurd/charts/db/values.yaml b/example/configurd/charts/db/values.yaml new file mode 100644 index 0000000..e85c8a8 --- /dev/null +++ b/example/configurd/charts/db/values.yaml @@ -0,0 +1,83 @@ +# Default values for test. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + containerPort: 3000 + +group: test + +env: [] + # - name: TEST + # value: "test" + +args: [] + # - "arg1==one" + +persistentVolume: + size: 1Gi + path: /tmp + reclaimPolicy: Delete + accessModes: + - ReadWriteOnce + +volumeMounts: + - name: data + path: /var/lib/mysql + +ingress: + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + host: "" + path: "" + secretName: "" + +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: {} diff --git a/example/configurd/charts/example/templates/deployment.yaml b/example/configurd/charts/example/templates/deployment.yaml index 38be279..27abef1 100644 --- a/example/configurd/charts/example/templates/deployment.yaml +++ b/example/configurd/charts/example/templates/deployment.yaml @@ -1,7 +1,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: "{{ .Release.Name }}-deployment" + name: "{{ .Release.Name }}" labels: app.kubernetes.io/name: {{ .Release.Name }} app.kubernetes.io/part-of: {{ .Values.group }}