CKA Certification Course - Certified Kubernetes Administrator

2025 Updates Kustomize Basics

Kustomize vs Helm

Before diving into the next section, let's take a closer look at an alternative tool to Kustomize: Helm. This guide offers a high-level overview of Helm's functionality to customize Kubernetes manifests for various environments while adding several advanced features.

Helm leverages Go templating syntax to dynamically assign values to properties within your Kubernetes manifests. Consider the following basic deployment configuration as an example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.name }}
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "nginx:{{ .Values.image.tag }}"

In this configuration, the use of double curly braces {{ }} highlights the Go templating syntax. Notice that the replicas property is set dynamically using the replicaCount variable from an external values file. This dynamic approach allows you to adjust settings, such as the number of replicas for different environments, without directly modifying the core deployment manifest.

To supply values for these variables, you create a separate values.yaml file. For example:

# Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.name }}
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "nginx:{{ .Values.image.tag }}"

# values.yaml
replicaCount: 1
image:
  tag: "2.4.4"

When you deploy your application, Helm seamlessly injects the defined values into your templates. In the example above, the replica count becomes 1, and the image tag is set to "2.4.4".

Helm Project Structure

A well-organized Helm project typically separates configuration files based on the target environment. Below is an example directory structure that demonstrates how to arrange your Helm charts and values files:

k8s/
└── Deployment.yaml
└── environments/
    ├── values.dev.yaml
    ├── values.stg.yaml
    └── values.prod.yaml
└── templates/
    ├── nginx-deployment.yaml
    ├── nginx-service.yaml
    ├── db-deployment.yaml
    └── db-service.yaml
  • The templates directory contains Kubernetes manifest files that include Go templating syntax.
  • The environments directory includes various values.yaml files tailored for development, staging, and production.

When deploying your application, you select the appropriate values file based on the target environment, and Helm injects these values into the templates accordingly.

Additional Helm Features

Helm is more than just a templating tool—it is a powerful package manager for Kubernetes applications, offering capabilities similar to those found in Linux package managers like yum or apt. Key advanced features include:

  • Conditionals and loops within templates
  • Built-in functions to manipulate and format data
  • Lifecycle hooks to manage application deployment events

Important Note

Helm charts are rendered using Go templating syntax, meaning they are not valid YAML until processed. This can make the charts more challenging to read compared to plain Kubernetes YAML files.

In contrast, Kustomize uses straightforward YAML overlays, making it simpler and often more readable. However, the simplicity of Kustomize comes with less flexibility than Helm's advanced feature set.

The image compares Kustomize and Helm, highlighting Helm's features like package management, conditionals, loops, functions, hooks, and its use of Go templating syntax.

Conclusion

Ultimately, choosing between Kustomize and Helm depends on your project's specific requirements, your team's expertise, and the level of complexity you're prepared to manage. Helm’s powerful templating, advanced features, and environment-specific configuration options make it an excellent choice for complex deployments, while Kustomize offers a simpler, more transparent approach using plain YAML.

For additional insights into other Kubernetes tools and best practices, visit the Kubernetes Documentation and explore further resources on Docker Hub.

Watch Video

Watch video content

Previous
Kustomize Problem Statement idealogy