├── README.md ├── cloudacademy-webapp-0.1.0.tgz ├── cloudacademy-webapp ├── .helmignore ├── Chart.yaml ├── templates │ ├── _helpers.tpl │ ├── configmap.yaml │ ├── deployment.yaml │ └── service.yaml └── values.yaml └── doc ├── HelmKubernetesDistro.png └── HelmTemplate1.png /README.md: -------------------------------------------------------------------------------- 1 | # Helm Chart Demonstration Resources 2 | 3 | The following instructions are used to demonstrate how to build, package, and install a Helm 3 custom chart. 4 | 5 | ![Helm](./doc/HelmKubernetesDistro.png) 6 | 7 | The custom ```cloudacademy-webapp``` Helm chart when installed creates the following cluster resources: 8 | 9 | ![CloudAcademyWebapp](./doc/HelmTemplate1.png) 10 | 11 | :metal: 12 | 13 | # STEP 1: 14 | Package the ```cloudacademy-webapp``` chart 15 | 16 | ``` 17 | helm package cloudacademy-webapp 18 | ``` 19 | 20 | # STEP 2: 21 | Install the ```cloudacademy-webapp``` chart into Kubernetes cluster 22 | 23 | Note: assumes that you have a cluster credentials configured within your local ```~/.kube/config``` file 24 | 25 | ``` 26 | helm install ca-demo1 cloudacademy-webapp-0.1.0.tgz 27 | ``` 28 | 29 | # STEP 3: 30 | Examine newly created Helm chart release, and all cluster created resources 31 | 32 | ``` 33 | helm ls 34 | 35 | kubectl get all 36 | ``` 37 | 38 | # STEP 4: 39 | Perform an HTTP GET request, send it to the newly created cluster service and confirm that the response containse the ```CloudAcademy DevOps 2020 v1``` message stored in the ```values.yaml``` file 40 | 41 | ``` 42 | kubectl run --image=busybox bbox1 --rm -it --restart=Never \ 43 | -- /bin/sh -c "wget -qO- http://ca-demo1-cloudacademy-webapp" 44 | ``` 45 | 46 | # STEP 5: 47 | Perform a Helm upgrade on the ```ca-demo1``` release 48 | 49 | ``` 50 | helm upgrade ca-demo1 cloudacademy-webapp-0.1.0.tgz \ 51 | --set nginx.conf.message="Helm Rocks" 52 | ``` 53 | 54 | # STEP 6: 55 | Perform another HTTP GET request. Confirm that the response now has the updated message ```Helm Rocks``` 56 | 57 | ``` 58 | kubectl run --image=busybox bbox1 --rm -it --restart=Never \ 59 | -- /bin/sh -c "wget -qO- http://ca-demo1-cloudacademy-webapp" 60 | ``` 61 | 62 | # STEP 7: 63 | Examine the ```ca-demo1``` release history 64 | 65 | ``` 66 | helm history ca-demo1 67 | ``` 68 | 69 | # STEP 8: 70 | Rollback the ```ca-demo1``` release to previous version 71 | 72 | ``` 73 | helm rollback ca-demo1 74 | ``` 75 | 76 | # STEP 9: 77 | Perform another HTTP GET request. Confirm that the response has now been reset to the ```CloudAcademy DevOps 2020 v1``` message stored in the ```values.yaml``` file 78 | 79 | ``` 80 | kubectl run --image=busybox bbox1 --rm -it --restart=Never \ 81 | -- /bin/sh -c "wget -qO- http://ca-demo1-cloudacademy-webapp" 82 | ``` 83 | 84 | # STEP 10: 85 | Uninstall the ```ca-demo1``` release 86 | 87 | ``` 88 | helm uninstall ca-demo1 89 | ``` -------------------------------------------------------------------------------- /cloudacademy-webapp-0.1.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudacademy/helm-demo/c04c0120f7fe92d71da9b65437afabbd6b89decf/cloudacademy-webapp-0.1.0.tgz -------------------------------------------------------------------------------- /cloudacademy-webapp/.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *.orig 18 | *~ 19 | # Various IDEs 20 | .project 21 | .idea/ 22 | *.tmproj 23 | .vscode/ 24 | -------------------------------------------------------------------------------- /cloudacademy-webapp/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | name: cloudacademy-webapp 3 | description: A Helm chart for Kubernetes 4 | 5 | # A chart can be either an 'application' or a 'library' chart. 6 | # 7 | # Application charts are a collection of templates that can be packaged into versioned archives 8 | # to be deployed. 9 | # 10 | # Library charts provide useful utilities or functions for the chart developer. They're included as 11 | # a dependency of application charts to inject those utilities and functions into the rendering 12 | # pipeline. Library charts do not define any templates and therefore cannot be deployed. 13 | type: application 14 | 15 | # This is the chart version. This version number should be incremented each time you make changes 16 | # to the chart and its templates, including the app version. 17 | # Versions are expected to follow Semantic Versioning (https://semver.org/) 18 | version: 0.1.0 19 | 20 | # This is the version number of the application being deployed. This version number should be 21 | # incremented each time you make changes to the application. Versions are not expected to 22 | # follow Semantic Versioning. They should reflect the version the application is using. 23 | appVersion: 1.16.0 24 | -------------------------------------------------------------------------------- /cloudacademy-webapp/templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{/* vim: set filetype=mustache: */}} 2 | {{/* 3 | Expand the name of the chart. 4 | */}} 5 | {{- define "webserver.name" -}} 6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} 7 | {{- end }} 8 | 9 | {{/* 10 | Create a default fully qualified app name. 11 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 12 | If release name contains chart name it will be used as a full name. 13 | */}} 14 | {{- define "webserver.fullname" -}} 15 | {{- if .Values.fullnameOverride }} 16 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} 17 | {{- else }} 18 | {{- $name := default .Chart.Name .Values.nameOverride }} 19 | {{- if contains $name .Release.Name }} 20 | {{- .Release.Name | trunc 63 | trimSuffix "-" }} 21 | {{- else }} 22 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} 23 | {{- end }} 24 | {{- end }} 25 | {{- end }} 26 | 27 | {{/* 28 | Create chart name and version as used by the chart label. 29 | */}} 30 | {{- define "webserver.chart" -}} 31 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} 32 | {{- end }} 33 | 34 | {{/* 35 | Common labels 36 | */}} 37 | {{- define "webserver.labels" -}} 38 | helm.sh/chart: {{ include "webserver.chart" . }} 39 | {{ include "webserver.selectorLabels" . }} 40 | {{- if .Chart.AppVersion }} 41 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} 42 | {{- end }} 43 | app.kubernetes.io/managed-by: {{ .Release.Service }} 44 | {{- end }} 45 | 46 | {{/* 47 | Selector labels 48 | */}} 49 | {{- define "webserver.selectorLabels" -}} 50 | app.kubernetes.io/name: {{ include "webserver.name" . }} 51 | app.kubernetes.io/instance: {{ .Release.Name }} 52 | {{- end }} -------------------------------------------------------------------------------- /cloudacademy-webapp/templates/configmap.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: {{ include "webserver.fullname" . }}-config 5 | namespace: cloudacademy 6 | data: 7 | nginx.conf: |- 8 | server { 9 | listen 80; 10 | server_name localhost; 11 | 12 | location / { 13 | return 200 '{{ .Values.nginx.conf.message }}\n'; 14 | add_header Content-Type text/plain; 15 | } 16 | 17 | location /release/name { 18 | return 200 '{{ .Release.Name }}\n'; 19 | add_header Content-Type text/plain; 20 | } 21 | 22 | location /release/revision { 23 | return 200 '{{ .Release.Revision }}\n'; 24 | add_header Content-Type text/plain; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cloudacademy-webapp/templates/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: {{ include "webserver.fullname" . }} 5 | labels: 6 | {{- include "webserver.labels" . | nindent 4 }} 7 | spec: 8 | {{- if not .Values.autoscaling.enabled }} 9 | replicas: {{ .Values.replicaCount }} 10 | {{- end }} 11 | selector: 12 | matchLabels: 13 | {{- include "webserver.selectorLabels" . | nindent 6 }} 14 | template: 15 | metadata: 16 | annotations: 17 | checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} 18 | labels: 19 | {{- include "webserver.selectorLabels" . | nindent 8 }} 20 | spec: 21 | containers: 22 | - name: {{ .Chart.Name }} 23 | image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" 24 | imagePullPolicy: {{ .Values.image.pullPolicy }} 25 | volumeMounts: 26 | - name: nginx-config 27 | mountPath: /etc/nginx/conf.d/default.conf 28 | subPath: nginx.conf 29 | ports: 30 | - name: http 31 | containerPort: 80 32 | protocol: TCP 33 | volumes: 34 | - name: nginx-config 35 | configMap: 36 | name: {{ include "webserver.fullname" . }}-config -------------------------------------------------------------------------------- /cloudacademy-webapp/templates/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: {{ include "webserver.fullname" . }} 5 | labels: 6 | {{- include "webserver.labels" . | nindent 4 }} 7 | spec: 8 | type: {{ .Values.service.type }} 9 | ports: 10 | - port: {{ .Values.service.port }} 11 | targetPort: http 12 | protocol: TCP 13 | name: http 14 | selector: 15 | {{- include "webserver.selectorLabels" . | nindent 4 }} -------------------------------------------------------------------------------- /cloudacademy-webapp/values.yaml: -------------------------------------------------------------------------------- 1 | replicaCount: 2 2 | 3 | image: 4 | repository: nginx 5 | pullPolicy: IfNotPresent 6 | tag: "" 7 | 8 | service: 9 | type: ClusterIP 10 | port: 80 11 | 12 | autoscaling: 13 | enabled: false 14 | 15 | nginx: 16 | conf: 17 | message: "CloudAcademy DevOps 2020 v1" 18 | -------------------------------------------------------------------------------- /doc/HelmKubernetesDistro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudacademy/helm-demo/c04c0120f7fe92d71da9b65437afabbd6b89decf/doc/HelmKubernetesDistro.png -------------------------------------------------------------------------------- /doc/HelmTemplate1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudacademy/helm-demo/c04c0120f7fe92d71da9b65437afabbd6b89decf/doc/HelmTemplate1.png --------------------------------------------------------------------------------