From 3048694ed1353ad7e09a14237c6e025fbf99f572 Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Tue, 12 Oct 2021 20:29:24 -0400 Subject: [PATCH] Working demo with basic template --- .../demo-helm/templates/backend-service.yaml | 7 ++-- charts/demo-helm/templates/backend.yaml | 27 ++++++++----- charts/demo-helm/templates/ingress.yaml | 13 ++++--- charts/demo-helm/values.schema.json | 38 +++++++++++++++++++ charts/demo-helm/values.yaml | 7 ++++ 5 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 charts/demo-helm/values.schema.json create mode 100644 charts/demo-helm/values.yaml diff --git a/charts/demo-helm/templates/backend-service.yaml b/charts/demo-helm/templates/backend-service.yaml index e91ce27..ab6b666 100644 --- a/charts/demo-helm/templates/backend-service.yaml +++ b/charts/demo-helm/templates/backend-service.yaml @@ -1,13 +1,14 @@ apiVersion: v1 kind: Service +# https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata metadata: labels: - name: backend - name: backend + name: {{ $.Release.Name }}-{{ $.Chart.Name}}-backend-service + name: {{ $.Release.Name }}-{{ $.Chart.Name}}-backend-service spec: ports: - protocol: 'TCP' port: 80 targetPort: 5000 selector: - app: backend + app: {{ $.Release.Name }}-{{ $.Chart.Name}}-backend diff --git a/charts/demo-helm/templates/backend.yaml b/charts/demo-helm/templates/backend.yaml index 3b43f66..251dc15 100644 --- a/charts/demo-helm/templates/backend.yaml +++ b/charts/demo-helm/templates/backend.yaml @@ -1,23 +1,32 @@ apiVersion: apps/v1 kind: Deployment + # https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata metadata: - name: backend + # This allows us to ensure we have a unique config name. Which means we could have two of the same service + # in the same namespace. + name: {{ .Release.Name }}-{{ .Chart.Name}}-deployment + labels: + app: {{ .Release.Name }}-{{ .Chart.Name}}-backend spec: - replicas: 1 + {{- with .Values.services.backend }} + replicas: {{ .replicas }} selector: matchLabels: - app: backend + app: {{ $.Release.Name }}-{{ $.Chart.Name}}-backend template: metadata: labels: - app: backend + app: {{ $.Release.Name }}-{{ $.Chart.Name}}-backend + # Here I am just demonstrating that you can pull values from Chart.yaml or Releases. + # Note the capital first letter in accessing the values + app_version: {{ $.Chart.AppVersion }} spec: containers: - - image: registry.runcible.io/demo-helm:1.1.0 + - name: {{ $.Release.Name }}-{{ $.Chart.Name}}-backend + image: {{ .image_name }}:{{ .image_version }} imagePullPolicy: Always - name: backend ports: - - name: backend - containerPort: 5000 + - containerPort: 5000 imagePullSecrets: - - name: regcred \ No newline at end of file + - name: {{ $.Values.image_pull_secret }} + {{- end }} \ No newline at end of file diff --git a/charts/demo-helm/templates/ingress.yaml b/charts/demo-helm/templates/ingress.yaml index 22fa287..b669f57 100644 --- a/charts/demo-helm/templates/ingress.yaml +++ b/charts/demo-helm/templates/ingress.yaml @@ -1,14 +1,17 @@ -apiVersion: extensions/v1beta1 -# apiVersion: networking.k8s.io/v1 # Supposed to be the new API but of course the spec structure has changed. +apiVersion: networking.k8s.io/v1 kind: Ingress +# https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata metadata: - name: demo-helm-ingress + name: {{ .Release.Name }}-{{ .Chart.Name}}-backend-ingress spec: rules: - host: backend.runcible.io http: paths: - path: / + pathType: Prefix backend: - serviceName: backend - servicePort: 80 + service: + name: {{ $.Release.Name }}-{{ $.Chart.Name}}-backend-service + port: + number: 80 diff --git a/charts/demo-helm/values.schema.json b/charts/demo-helm/values.schema.json new file mode 100644 index 0000000..ca6d767 --- /dev/null +++ b/charts/demo-helm/values.schema.json @@ -0,0 +1,38 @@ +{ + "definitions": {}, + "$schema": "http://json.schema.org/draft-07/schema#", + "type": "object", + "required": ["image_pull_secret", "services"], + "properties": { + "image_pull_secret": { + "type": "string" + }, + "services": { + "type": "object", + "required": [ + "backend" + ], + "properties": { + "backend": { + "type": "object", + "required": [ + "image_name", + "image_version", + "replicas" + ], + "properties": { + "image_name": { + "type": "string" + }, + "image_version": { + "type": "string" + }, + "replicas": { + "type": "integer" + } + } + } + } + } + } +} \ No newline at end of file diff --git a/charts/demo-helm/values.yaml b/charts/demo-helm/values.yaml new file mode 100644 index 0000000..c149ca6 --- /dev/null +++ b/charts/demo-helm/values.yaml @@ -0,0 +1,7 @@ +--- +image_pull_secret: regcred +services: + backend: + image_name: "registry.runcible.io/demo-helm" + image_version: "1.1.0" + replicas: 1