Helm hands-on: Overriding values
As soon as you got Helm up and running and understand the basics, you can start using it.
Let’s do a small hands-on example.
Pre-requisites
- A Kubernetes cluster
- Docker installed
- Helm installed
Hello, World!
We’ll use the cloudecho helm package.
This is a small API running on Port 8080, which prints a Hello, World! on every request.
To use it, we make use of the helm repo add command.
helm repo add cloudecho https://cloudecho.github.io/charts/
helm repo update
We can install it to our cluster with the following command:
helm install my-hello cloudecho/hello -n default --version=0.1.2
And that’s it!
Check the pod
If you run now the command kubectl get pods you should see the pod up and running:
NAME READY STATUS RESTARTS AGE
my-hello-7bfd984465-8lwwb 1/1 Running 0 10s
You can see the port of the service resource by calling kubectl get service:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-hello ClusterIP 10.108.136.240 <none> 8080/TCP 69s
As it is running inside the cluster we cannot access it, but we can use a port forward to the Port 8080:
kubectl port-forward my-hello-7bfd984465-8lwwb 80:8080
When you access now http://localhost you should see the response of the application which is something like:
Hello, World!
2022-03-04 18:30:20.5547678 +0000 UTC
If you want to remove the release just call the following command:
helm uninstall my-hello
Overriding the default configuration
Sometimes we want to override some values of the default configuration.
For this we don’t need to clone all files. Instead create a new directory with a values yaml:
mkdir cloudecho
cd cloudecho
touch cloudecho-values.yaml
We will write our customized parameters into the cloudecho-values.yaml. Check the documentation of the Helm Chart you’re using to know which parameters you can override!
For the cloudecho chart the port can be configured through service.port.
So let’s make it run on port 8090:
service.port: 8090
And even more: When running locally, we can change the service.type to NodePort to bind the port to the node IP, so that the application is accessible without any port forwarding.
So the final cloudecho-values.yaml will look like following:
service:
port: 8090
type: NodePort
Let’s deploy it in our cluster.
The --values option takes the file name with our values and overrides the default ones.
helm install my-hello cloudecho/hello -n default --version=0.1.2 --values .\cloudecho-values.yaml
Now to get the port to which our application was mapped you need to call kubectl get services.
This should print you the service:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-hello NodePort 10.108.61.98 <none> 8090:31117/TCP 3m38s
In the PORT(S) column you can see that the service is running inside it’s pod on the port 8090 and in this case on port 31117.
So if you access http://localhost:31117 you should be able to see the application now!