Understanding Helm dry run for template debugging
Debugging and troubleshooting Helm Template in the complex production environment can be really daunting if you do
not use helm install --dry-run --debug
or helm template
command for debugging the Helm Templates.
helm install --dry-run --debug
:- It will validate and verify your chart by connecting to kubernetes api server and after successful validation it will render the manifest in the form of YAMLs(kubernetes resources)
helm template
:- It will do the validation and generate the YAML manifest but it can not guarantee that generated kubernetes resource(YAMLs) is valid or not.
Deep dive into : - helm install --dry-run --debug
Lets create Helm Chart - helloworld
1helm create helloworld
Since it is very basic helloworld helm chart but still we can verify and validate.
Run the following command -
1helm install myreleasename --debug --dry-run helloworld
Here is what will happen behind the scene -
- First the chart will be sent to kubernetes API server
- In the second step kubernetes API server will validate and verify the chart manifest
- Third step it will generate the template and return you back, so that you can see the final rendered template.
Is --dry-run option require for connecting to Kubernetes cluster?
Yes, you should have active and running Kubernetes Cluster before you use --debug --dry-run
.
In case if you do not have kubernetes cluster up and running then it will throw you following error
1Error: Kubernetes cluster unreachable: Get "http://localhost:8080/version?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused
So make sure your kubernetes cluster is in healthy state before running --debug --dry-run
.
Deep dive into : - helm template
Helm template will help you to validate your chart manifest(YAMLs), but it will not connect to kubernetes API server for kubernetes resource validation.
It will help you to generate the complete kubernetes resource manifest(YAMLs) by replacing the placeholders with actual values.
Run the following command -
1helm template helloworld
You should be to see the following output
1---
2# Source: helloworld/templates/serviceaccount.yaml
3apiVersion: v1
4kind: ServiceAccount
5metadata:
6 name: RELEASE-NAME-helloworld
7 labels:
8 helm.sh/chart: helloworld-0.1.0
9 app.kubernetes.io/name: helloworld
10 app.kubernetes.io/instance: RELEASE-NAME
11 app.kubernetes.io/version: "1.16.0"
12 app.kubernetes.io/managed-by: Helm
13---
14# Source: helloworld/templates/service.yaml
15apiVersion: v1
16kind: Service
17metadata:
18 name: RELEASE-NAME-helloworld
19 labels:
20 helm.sh/chart: helloworld-0.1.0
21 app.kubernetes.io/name: helloworld
22 app.kubernetes.io/instance: RELEASE-NAME
23 app.kubernetes.io/version: "1.16.0"
24 app.kubernetes.io/managed-by: Helm
25spec:
26 type: ClusterIP
27 ports:
28 - port: 8080
29 targetPort: http
30 protocol: TCP
31 name: http
32 selector:
33 app.kubernetes.io/name: helloworld
34 app.kubernetes.io/instance: RELEASE-NAME
35---
36# Source: helloworld/templates/deployment.yaml
37apiVersion: apps/v1
38kind: Deployment
39metadata:
40 name: RELEASE-NAME-helloworld
41 labels:
42 helm.sh/chart: helloworld-0.1.0
43 app.kubernetes.io/name: helloworld
44 app.kubernetes.io/instance: RELEASE-NAME
45 app.kubernetes.io/version: "1.16.0"
46 app.kubernetes.io/managed-by: Helm
47spec:
48 replicas: 1
49 selector:
50 matchLabels:
51 app.kubernetes.io/name: helloworld
52 app.kubernetes.io/instance: RELEASE-NAME
53 template:
54 metadata:
55 labels:
56 app.kubernetes.io/name: helloworld
57 app.kubernetes.io/instance: RELEASE-NAME
58 spec:
59 serviceAccountName: RELEASE-NAME-helloworld
60 securityContext:
61 {}
62 containers:
63 - name: helloworld
64 securityContext:
65 {}
66 image: "rahulwagh17/kubernetes:jhooq-k8s-helloworld"
67 imagePullPolicy: IfNotPresent
68 ports:
69 - name: http
70 containerPort: 8080
71 protocol: TCP
72 resources:
73 {}
74---
75# Source: helloworld/templates/tests/test-connection.yaml
76apiVersion: v1
77kind: Pod
78metadata:
79 name: "RELEASE-NAME-helloworld-test-connection"
80 labels:
81 helm.sh/chart: helloworld-0.1.0
82 app.kubernetes.io/name: helloworld
83 app.kubernetes.io/instance: RELEASE-NAME
84 app.kubernetes.io/version: "1.16.0"
85 app.kubernetes.io/managed-by: Helm
86 annotations:
87 "helm.sh/hook": test-success
88spec:
89 containers:
90 - name: wget
91 image: busybox
92 command: ['wget']
93 args: ['RELEASE-NAME-helloworld:8080']
94 restartPolicy: Never
As you can see the output which consists of YAMLs and placeholders replaced by its actual values, once you will deploy this YAMLs into the kubernetes cluster then you will get to know the success and failure state of the resource.
Conclusion
In this article we have seen -
- What is
helm install --dry-run --debug
andhelm template
ow it can be used for debugging helm template - Apart from that we have also seen the difference between both the commands
For more details please refer to official documentation.
Read More -
- Helm chart - How to Add/Install plugins
- Getting started with Helm Chart
- Helm chart - WordPress Installation with MariaDB on Kubernetes
- Helm chart - Build you first helm chart with Spring Boot
- Helm Chart - Convert Kubernetes YAML into Helm Chart YAML
- Helm Chart - Pass environment variables
- Helm Chart - Plugin
- Helm Chart - Dry Run Install
- Helm Chart - How to create multiple values files inside helm chart?
- Helmfile - How to use Helmfile for managing helm chart?
Posts in this Series
- How to use Helmfile for managing helm chart?
- How to create multiple values files inside helm chart?
- Pass environment variables into Helm Chart?
- How to fix - Helm install unknown flag --name/Error must either provide a name or specify --generate-name?
- Understanding Helm dry run for template debugging
- How to fix - Error create failed to create Secret invalid metadata.name Invalid value DNS-1123 subdomain must consist of lower case alphanumeric characters - or ., and must start and end with an alphanumeric character (e.g. example.com, regex used for validation is)
- Convert Kubernetes deployment YAML into Helm Chart YAML
- Helm chart - Wordpress Installation with MariaDB on Kubernetes
- Helm chart - How to Add/Install plugins
- Getting Started with Helm Chart
- Building first Helm Chart with Spring Boot Microservices