In one of our last posts, we saw how to install NGINX Ingress controller using a Helm chart. Helm is a great tool to manage and standardize our solutions deployed in K8s. It gives us great control and consistency to deploy the same configurations across our environments and clusters.
As we discussed in this post, there are two ways of customizing a Helm chart - using the —set flag in the command line or modifying the values.yaml file. In general, the first one is what we’d do if we only needed to change very few parameters of the installation. The second option is a preferred approach for installations that require many changes or changes that span multiple settings.
Let’s see a practical example with NGINX. For us, Mulesoft Architects and Developers, it’s very important for our Runtime Fabric setups to understand how to adapt the NGINX ingress controller to our needs. We’ll see in this post both approaches: how to apply simple and quick changes with the —set flag and how to use the values.yaml file. Let’s see it:
Where:
Check the status of the pods, services, and ingress to ensure everything is configured correctly.
We can then leave the my-values.yaml as it is (and keep it as a standard for our installations) and change the number of replicas with the —set flag.
We could do that running the following command that combines both approaches:
If something goes wrong, you can rollback to the previous version:
As we discussed in this post, there are two ways of customizing a Helm chart - using the —set flag in the command line or modifying the values.yaml file. In general, the first one is what we’d do if we only needed to change very few parameters of the installation. The second option is a preferred approach for installations that require many changes or changes that span multiple settings.
Let’s see a practical example with NGINX. For us, Mulesoft Architects and Developers, it’s very important for our Runtime Fabric setups to understand how to adapt the NGINX ingress controller to our needs. We’ll see in this post both approaches: how to apply simple and quick changes with the —set flag and how to use the values.yaml file. Let’s see it:
Prerequisites
To follow these examples, we’ll need to have- A K8s cluster → check out this post on How to get our K8s cluster in 2 mins
- Install helm → check out this post on How to install Helm
- kubectl installed and configured → check out these two posts:
Initial setup
Create a dedicated namespace
- We’ll create a dedicated namespace for all the ingress resources called ingress-nginx
kubectl create ns ingress-nginx
Add the Helm repository
- For this example we will use the Bitnami repository. To add run the command
helm repo add bitnami https://charts.bitnami.com/bitnami
- Verify that the new repo is in the list of repos of your Helm installation
helm repo list
- Update the new repo
helm repo update
Explore the default values.
- To understand what can be customized, it's always useful to inspect the default values of the NGINX chart:
helm show values bitnami/nginx
- This will output the default
values.yaml
file, which lists all the configurable options.
Basic customizations
Let’s say we’re happy with the default values and we just want to customize the following:- The number of replicas to run the controller (it would be number of replicas in the deployment). We’ll set it up to 3.
- The type of service - Instead of using a LoadBalancer service we want to use a NodePort service.
- The port for our NodePort service. We want to use port number 30092 in all worker nodes.
helm install gon-nginx bitnami/nginx -n ingress-nginx --set replicaCount=3 --set service.type=NodePort
- gon-nginx - it’s the name of our release
- -n ingress-nginx - specifies the namespace where we want to deploy all the resources of the chart
- replicaCount and service.type are the parameters we are customizing
- Verify there’s a new release in the namespace with:
helm list -n ingress-nginx
- Next, verify we’ve got 3 replicas running the ingress controller
kubectl get pods -n ingress-nginx
- And lastly, let’s verify that the service is of a type NodePort
kubectl get svc -n ingress-nginx
Create our custom values.yaml file
Now let’s do a more complex customization. Based on the default values, create a custommy-values.yaml
file to override the settings. Here's the my-values.yaml
file for that will use for our example:replicaCount: 2
image:
repository: bitnami/nginx
pullPolicy: IfNotPresent
service:
type: NodePort
resources:
limits:
cpu: 500m
memory: 256Mi
requests:
cpu: 250m
memory: 128Mi
livenessProbe:
enabled: true
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
successThreshold: 1
readinessProbe:
enabled: true
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3
successThreshold: 1
persistence:
enabled: true
accessModes:
- ReadWriteOnce
size: 8Gi
path: /usr/share/nginx/html
annotations: {}
storageClass: ""
ingress:
enabled: true
hostname: my-nginx.local
annotations:
kubernetes.io/ingress.class: nginx
tls: []
Where:
- replicaCount: Specifies the number of NGINX pod replicas. Here, it's set to 5.
- image: Defines the Docker image to use for NGINX. You can customize the repository, tag, and pull policy.
- service.type: Set to
LoadBalancer
to expose the NGINX service externally. The default port is 80. - resources: Configures the resource requests and limits for the NGINX pods.
- livenessProbe and readinessProbe: Enable and configure health checks to ensure NGINX is running correctly.
- persistence: Enables persistent storage for NGINX. You can specify the size, access mode, and path.
- ingress: Configures ingress settings to expose NGINX via a hostname and manage TLS if required.
Install the Chart
Once you've created yourvalues.yaml
, you can install the NGINX chart using Helm with your custom configuration:helm install gon-nginx-2 bitnami/nginx -n ingress-nginx -f my-values.yaml
Verify the installation
helm list -n ingress-nginx
kubectl get pods
kubectl get svc
And if we get the details of one of the pods we can get the values of the resources and readinessProbe:
Combining both approaches
Let’s just see with one example how to customize a chart using a custom values.yaml file and the command line. Let’s say that now we basically want to do a custom installation like the one we did in the second example, using the same my-values.yaml file but, this time, we want to set the number of replicas to 5 for testing.
We can then leave the my-values.yaml as it is (and keep it as a standard for our installations) and change the number of replicas with the —set flag.
We could do that running the following command that combines both approaches:
helm install gon-nginx-3 bitnami/nginx -n ingress-nginx -f my-values.yaml --set replicaCount=5
Verify that now the number of replicas is 5
How to upgrade or rollback if neeeded
If you need to make further changes to your configuration, modify themy-values.yaml
and upgrade the release:helm upgrade gon-nginx bitnami/nginx -f my-values.yaml
helm rollback gon-nginx 1