Create a Helm chart to deploy a multi-container application.
Customize a multi-container application for different environments with Kustomize.
Outcomes
Create a Helm chart from manifest files.
Use Kustomize for local updates on a Helm chart.
As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.
[student@workstation ~]$ lab start multicontainer-review
Instructions
The lab script copies the Helm chart files for the famous-quotes application, which uses a Redis data store.
In this lab, you are asked to create a Helm chart by using the files that the exercise provides and later using Kustomize to apply customization to the rendered chart. You are expected to work with Helm locally, without the need for a Helm repository.
Log in to Red Hat OpenShift.
Log in to OpenShift as the developer user.
[student@workstation ~]$ oc login -u developer -p developer \
https://api.ocp4.example.com:6443
Login successful.
...output omitted...Ensure that you use the multicontainer-review project.
[student@workstation ~]$ oc project multicontainer-review
Already on project "multicontainer-review" on server "https://api.ocp4.example.com:6443".Create a Helm chart from the files in the ~/DO288/labs/multicontainer-review/famous-quotes directory.
In a terminal window, change to the famous-quotes application directory.
[student@workstation ~]$ cd ~/DO288/labs/multicontainer-review/famous-quotesMove the files in the famous-quotes directory according to the Helm chart layout.
First, move the chart template files to the templates directory.
[student@workstation famous-quotes]$ mv \
configmap.yaml \
deployment.yaml \
route.yaml \
service.yaml \
templates/Then, move the pre-downloaded chart dependency to the charts directory.
[student@workstation famous-quotes]$ mv redis-persistent-0.0.1.tgz charts/When you run the tree command you must get the following output:
[student@workstation famous-quotes]$ tree ./
./
├── charts
│ └── redis-persistent-0.0.1.tgz
├── Chart.yaml
├── templates
│ ├── configmap.yaml
│ ├── deployment.yaml
│ ├── route.yaml
│ └── service.yaml
└── values.yaml
3 directories, 7 filesVerify that the famous-quotes templates and the Redis chart are in the correct location.
[student@workstation famous-quotes]$ helm template ./ | grep "# Source:" | sort
# Source: famous-quotes/charts/redis/templates/deploymentconfig.yaml
# Source: famous-quotes/charts/redis/templates/persistentvolumeclaim.yaml
# Source: famous-quotes/charts/redis/templates/secret.yaml
# Source: famous-quotes/charts/redis/templates/service.yaml
# Source: famous-quotes/charts/redis/templates/tests/test-redis-connection.yaml
# Source: famous-quotes/templates/configmap.yaml
# Source: famous-quotes/templates/deployment.yaml
# Source: famous-quotes/templates/route.yaml
# Source: famous-quotes/templates/service.yamlUpdate the Helm templates to use the values in the quotes key of the values.yaml file.
Add the following features to the chart:
Parameterize the famous-quotes image name.
Use the quotes.import.enabled value to optionally add the volume and the import configuration to the famous-quotes deployment.
Use the quotes.import.enabled value to optionally create the configuration map that contains the import data.
Edit the templates/deployment.yaml template to use the quotes.image value.
...output omitted...
spec:
containers:
- name: famous-quotes
image: {{ .Values.quotes.image }}
...output omitted...Edit the templates/deployment.yaml template to make the data import configuration and volume optional.
...output omitted... - name: DATASTORE_PASS valueFrom: secretKeyRef: key: database-password name: {{ .Values.redis.database_service_name }}{{- if .Values.quotes.import.enabled }}- name: QUOTES_IMPORT_PATH value: /tmp/quotes/import_quotes.csv volumeMounts: - name: import-volume mountPath: /tmp/quotes volumes: - name: import-volume configMap: name: quotes-import-data{{- end }}
Verify that the updates to the templates/deployment.yaml file render correctly.
Verify that the image value displays and that there is no data import configuration.
[student@workstation famous-quotes]$helm template ./ \ --set quotes.import.enabled=false \ | grep -A 28 "famous-quotes/templates/deployment.yaml"# Source: famous-quotes/templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: famous-quotes ...output omitted... containers: - name: famous-quotes image:registry.ocp4.example.com:8443/redhattraining/ocpdev-redis-quotes:4.12imagePullPolicy: Always env: - name: DATASTORE_HOST value: quotes-store - name: DATASTORE_PASS valueFrom: secretKeyRef: key: database-password name: quotes-store --- # Source: famous-quotes/charts/redis/templates/deploymentconfig.yaml
Edit the templates/configmap.yaml template to use the quotes.import.enabled value to conditionally create the quotes-import-data configuration map.
{{- if .Values.quotes.import.enabled }}apiVersion: v1 kind: ConfigMap metadata: name: quotes-import-data data: import_quotes.csv: |- id|quote|author ...output omitted... 8|Those who can imagine anything, can create the impossible.|Alan Turing{{- end }}
Run the helm template with the quotes.import.enabled parameter set to false to verify that the configuration map does not render.
[student@workstation famous-quotes]$ helm template ./ \
--set quotes.import.enabled=false \
| grep "# Source\|templates/configmap.yaml"
# Source: famous-quotes/charts/redis/templates/secret.yaml
# Source: famous-quotes/charts/redis/templates/persistentvolumeclaim.yaml
# Source: famous-quotes/charts/redis/templates/service.yaml
# Source: famous-quotes/templates/service.yaml
# Source: famous-quotes/templates/deployment.yaml
# Source: famous-quotes/charts/redis/templates/deploymentconfig.yaml
# Source: famous-quotes/templates/route.yaml
# Source: famous-quotes/charts/redis/templates/tests/test-redis-connection.yamlOptionally, run the previous command with the quotes.import.enabled=true parameter to verify that the configuration map shows in the output.
Use the output of the local famous-quotes chart render to create the ~/DO288/labs/multicontainer-review/kustomized-quotes/base/app.yaml file.
Use the --skip-tests option for the helm template command to avoid rendering the chart in the app.yaml file.
Add the required files to the kustomized-quotes directory to have working staging and production customizations for the famous-quotes application.
The ~/DO288/labs/multicontainer-review/kustomized-quotes directory contains the base and overlays directory convention, but is missing some files that Kustomize requires.
kustomized-quotes
├── base
│ └── app.yaml # Generated in the Helm part of the exercise
└── overlays
├── production
│ └── app_dimensioning.yaml
└── staging
└── app_dimensioning.yamlChange to the kustomized-quotes directory.
[student@workstation famous-quotes]$ cd \
~/DO288/labs/multicontainer-review/kustomized-quotesCreate the base/kustomization.yaml file with the following content:
resources: - app.yaml
Verify that you can run oc kustomize with the base directory.
[student@workstation kustomized-quotes]$ oc kustomize base/
apiVersion: v1
data:
import_quotes.csv: |-
...output omitted...Create the overlays/staging/kustomization.yaml file with the following content:
bases: - ../../base patches: - staging_dimensioning.yaml
Verify that you can run oc kustomize with the overlays/staging directory.
[student@workstation kustomized-quotes]$ oc kustomize overlays/staging
apiVersion: v1
data:
import_quotes.csv: |-
id|quote|author
...output omitted...Create the overlays/production/kustomization.yaml file with the following content:
bases: - ../../base patches: - prod_dimensioning.yaml
Verify that you can run oc kustomize with the overlays/production directory.
[student@workstation kustomized-quotes]$ oc kustomize overlays/production
apiVersion: v1
data:
import_quotes.csv: |-
id|quote|author
...output omitted...Verify the directory structure.
[student@workstation kustomized-quotes]$ tree ./
./
├── base
│ ├── app.yaml
│ └── kustomization.yaml
└── overlays
├── production
│ ├── kustomization.yaml
│ └── prod_dimensioning.yaml
└── staging
├── kustomization.yaml
└── staging_dimensioning.yaml
4 directories, 6 filesDeploy the staging version of the application.
Run the following command to deploy the staging version of the application.
[student@workstation kustomized-quotes]$ oc apply -k overlays/stagingVerify that the application and the Redis pods are running.
[student@workstation kustomized-quotes]$ oc get po
NAME READY STATUS RESTARTS AGE
famous-quotes-d64ffc75f-kwzgw 1/1 Running 2 (36s ago) 59s
quotes-store-1-deploy 0/1 Completed 0 58s
quotes-store-1-sjv7p 1/1 Running 0 55sUse the curl command to test that the application works.
[student@workstation kustomized-quotes]$ curl \
famous-quotes-multicontainer-review.apps.ocp4.example.com/quotes/5
{
"quote" : "Imagination is more important than knowledge.",
"author" : "Albert Einstein",
"_links" : {
"self" : {
"href" : "http://famous-quotes-multicontainer-review.apps.ocp4.example.com/quotes/5"
},
"quote" : {
"href" : "http://famous-quotes-multicontainer-review.apps.ocp4.example.com/quotes/5"
}
}
}