0
0
Kubernetesdevops~5 mins

Chart values and customization in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you install software on Kubernetes using Helm charts, you often want to change how it works. Chart values let you customize settings easily without changing the main files. This helps you adjust the app to your needs.
When you want to change the number of app replicas to handle more users.
When you need to set a custom image version for your app.
When you want to enable or disable features like logging or monitoring.
When you want to add environment variables to your app containers.
When you want to change resource limits like CPU or memory for your app.
Config File - values.yaml
values.yaml
replicaCount: 3
image:
  repository: nginx
  tag: stable
  pullPolicy: IfNotPresent
service:
  type: ClusterIP
  port: 80
resources:
  limits:
    cpu: 500m
    memory: 256Mi
  requests:
    cpu: 250m
    memory: 128Mi

This values.yaml file sets the number of replicas to 3, uses the stable nginx image, and defines resource limits and requests for CPU and memory. It also sets the service type and port. You can change these values to customize your app deployment without editing the main chart files.

Commands
This command installs the nginx chart using the custom settings from the values.yaml file. It applies your changes like replica count and resource limits.
Terminal
helm install my-nginx nginx -f values.yaml
Expected OutputExpected
NAME: my-nginx LAST DEPLOYED: Fri Apr 26 12:00:00 2024 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None
-f - Specifies the custom values file to override default chart settings
This command lists the pods running in your Kubernetes cluster to verify that your app pods are created with the custom settings.
Terminal
kubectl get pods
Expected OutputExpected
NAME READY STATUS RESTARTS AGE my-nginx-5d8f9d7f7b-abcde 1/1 Running 0 1m my-nginx-5d8f9d7f7b-fghij 1/1 Running 0 1m my-nginx-5d8f9d7f7b-klmno 1/1 Running 0 1m
This command updates the existing nginx release with any changes made in the values.yaml file, allowing you to customize the app after installation.
Terminal
helm upgrade my-nginx nginx -f values.yaml
Expected OutputExpected
Release "my-nginx" has been upgraded. Happy Helming! NAME: my-nginx LAST DEPLOYED: Fri Apr 26 12:05:00 2024 NAMESPACE: default STATUS: deployed REVISION: 2 TEST SUITE: None
-f - Uses the custom values file for the upgrade
This command shows the current values used by the installed nginx release, so you can check what customizations are active.
Terminal
helm get values my-nginx
Expected OutputExpected
replicaCount: 3 image: repository: nginx tag: stable pullPolicy: IfNotPresent service: type: ClusterIP port: 80 resources: limits: cpu: 500m memory: 256Mi requests: cpu: 250m memory: 128Mi
Key Concept

If you remember nothing else from this pattern, remember: customizing Helm chart values lets you change app settings easily without touching the main chart files.

Common Mistakes
Editing the chart's default values.yaml file directly inside the chart folder.
This can cause problems when upgrading the chart because your changes may be overwritten.
Always create and use a separate custom values.yaml file and pass it with the -f flag during install or upgrade.
Not specifying the -f flag when installing or upgrading, so the default values are used.
Your custom settings will be ignored and the app will run with default configurations.
Always include -f values.yaml to apply your custom settings.
Changing values that do not exist or are misspelled in the custom values file.
Helm will ignore unknown keys, so your changes won't take effect and can cause confusion.
Check the chart documentation for valid keys and use correct spelling and indentation.
Summary
Create a custom values.yaml file to set your app's configuration like replicas, image, and resources.
Use helm install or helm upgrade with the -f flag to apply your custom values.
Verify your app pods with kubectl get pods and check active values with helm get values.