Now that we know how to install/upgrade/delete and rollback a release from a 3rd party chart, it is time to build our own.
We will build a simple helm chart for a helm-echoserver. The chart will deploy a helm-echoserver container and perform a small post-installation task. This task is to wait for a configurable amount of time and then make a POST request to the helm-echoserver with a message to be stored in the file system of the helm-echoserver container.
A set of static kubernetes manifests are provided for guidance in helm-echoserver directory.
Whenever the text below mentions the
provided
files, it refers to the files provided in helm-echoserver/ in this repo.
You can run
helm lint
after each step below to detect some of the common syntax errors.
- Start by creating a new chart named
echoserver
by runninghelm create echoserver
. This will create some default templates. - Now, in the generated chart, edit the
Chart.yaml
file. Hint: check here for the possible options. - Render the output from the chart templates by running
helm install echoserver --dry-run --debug --tiller-namespace <your-namespace>
Now, we want to customize the default chart to our needs.
- Replace the values file in the new chart with the provided one. Now you have your input parameters.
We want to customize the deployment template in the chart so that it can render deployment manifest similar to the provided one.
-
Inspect the name of the deployment. Try to understand how it's generated.
-
Similarly, inspect the labels. Which built-in helm objects are used?
-
On line 11 in deployment.yaml,
replicaCount
is read from input. Make it such that it defaults to 2 replicas when there is no user input for that value. Hint: use pipes and check the Go Sprig functions -
Replace the hard-coded container port in line 28 with a Go template reading input from values.
-
In the
container
section, add environment variables such that an infinite number of environment variables can be defined by the user in the values file and get rendered in the deployment manifest. In addition to the user-provided variables a set of variables have to be added as well. Copy these from the provided deployment.yaml. Hint: Use a loop! -
Replace the hard-coded values of the environment variables [HELM_CHART_NAME, HELM_CHART_VERSION, HELM_RELEASE] in deployment.yaml with values from the helm built-in objects.
-
Similar to the deployment, replace hard-coded values with dynamic ones and follow the comments in the provided service.yaml file.
-
Make sure the service is created only if the service section in the values file is not empty.
- Again, follow the instructions in the comments in the provided ingress.yaml to make it dynamic.
This job is intended to be run each time helm-echoserver is deployed/upgraded. It simply sends a curl request posting a text message.
-
As before, follow the comments in the provided
post_install_job.yaml
to make the job dynamic. -
Now, let's make this a Helm life cycle hook. Check life cycle hooks
- Add some message to the user with dynamic content. Example: how the user can access the app in the browser based on the service configurations they choose. Hint: get inspired from the Jenkins chart
helm package echoserver/.
If no errors are found, the above command generates the compressed chart <chart-name>-<chart-version>.tgz
- Horray! Our chart is ready. Let's install :
helm install --name echoserver echoserver-0.1.0.tgz --set post_install.delay=50,post_install.message="<your custom message here>" --tiller-namespace <your-namespace> --wait
The
--wait
forces any post-install hooks to wait for all other resources to be in ready state. Thepost_install.delay=50
defines how long the post-install pod will wait (in seconds) before sending the message.
If all goes well, the last command results in a list of resources created by the chart and instructions to access the helm-echoserver (these instructions come from echoserver/templates/NOTES.txt).
Before we move to the next exercise, let's clean our cluster by deleting all the releases we installed so far:
helm delete --purge $(helm list --all -q)