diff --git a/ch07/bgdh/.helmignore b/ch07/bgdh/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/ch07/bgdh/.helmignore @@ -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/ diff --git a/ch07/bgdh/Chart.yaml b/ch07/bgdh/Chart.yaml new file mode 100644 index 0000000..1c36ccc --- /dev/null +++ b/ch07/bgdh/Chart.yaml @@ -0,0 +1,7 @@ +apiVersion: v2 +name: bgdh +description: Blue Green Deployment with Helm + +type: application +version: 0.1.0 +appVersion: "1.16.0" diff --git a/ch07/bgdh/templates/NOTES.txt b/ch07/bgdh/templates/NOTES.txt new file mode 100644 index 0000000..9f118d0 --- /dev/null +++ b/ch07/bgdh/templates/NOTES.txt @@ -0,0 +1,8 @@ +1. Get the application URL by running these commands: + +{{- if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "bgdh.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} \ No newline at end of file diff --git a/ch07/bgdh/templates/_helpers.tpl b/ch07/bgdh/templates/_helpers.tpl new file mode 100644 index 0000000..c278db1 --- /dev/null +++ b/ch07/bgdh/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "bgdh.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 "bgdh.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 "bgdh.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "bgdh.labels" -}} +helm.sh/chart: {{ include "bgdh.chart" . }} +{{ include "bgdh.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "bgdh.selectorLabels" -}} +app.kubernetes.io/name: {{ include "bgdh.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "bgdh.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "bgdh.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/ch07/bgdh/templates/deployment.yaml b/ch07/bgdh/templates/deployment.yaml new file mode 100644 index 0000000..fabf478 --- /dev/null +++ b/ch07/bgdh/templates/deployment.yaml @@ -0,0 +1,51 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "bgdh.fullname" . }} + labels: + {{- include "bgdh.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "bgdh.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "bgdh.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "bgdh.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + 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/ch07/bgdh/templates/service.yaml b/ch07/bgdh/templates/service.yaml new file mode 100644 index 0000000..a071e34 --- /dev/null +++ b/ch07/bgdh/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "bgdh.fullname" . }} + labels: + {{- include "bgdh.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "bgdh.selectorLabels" . | nindent 4 }} diff --git a/ch07/bgdh/templates/serviceaccount.yaml b/ch07/bgdh/templates/serviceaccount.yaml new file mode 100644 index 0000000..6581247 --- /dev/null +++ b/ch07/bgdh/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "bgdh.serviceAccountName" . }} + labels: + {{- include "bgdh.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/ch07/bgdh/templates/tests/test-connection.yaml b/ch07/bgdh/templates/tests/test-connection.yaml new file mode 100644 index 0000000..242c02a --- /dev/null +++ b/ch07/bgdh/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "bgdh.fullname" . }}-test-connection" + labels: + {{- include "bgdh.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "bgdh.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/ch07/bgdh/values.yaml b/ch07/bgdh/values.yaml new file mode 100644 index 0000000..7896267 --- /dev/null +++ b/ch07/bgdh/values.yaml @@ -0,0 +1,31 @@ +replicaCount: 1 + +image: + repository: quay.io/redhatworkshops/bgd + pullPolicy: IfNotPresent + tag: latest + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: true + annotations: {} + name: "" + +podAnnotations: {} + +podSecurityContext: {} + +securityContext: {} + +service: + type: ClusterIP + port: 80 + +resources: {} + +nodeSelector: {} +tolerations: [] +affinity: {}