ECHOKE
Guides

Helm Syntax - Chart Development

Engin Can Höke
#helm#kubernetes#devops

If you’re new to Helm, it’s recommended to read the What is Helm blog first.

In this tutorial, we’ll create a basic Helm template to generate Kubernetes manifest files for deploying an Nginx application.

Expected Output

We’ll create a basic Nginx Deployment with the following specifications:

To allow flexibility in changing the image, replica count, or version, we’ll parameterize certain properties.

Parameterized Properties

We’ll focus on parameterizing the following properties:

Creating the Helm Chart

First, create the necessary directory structure and files:

mkdir -p deployment/templates
touch deployment/Chart.yaml
touch deployment/values.yaml
touch deployment/templates/deployment.yaml

Chart.yaml

Populate Chart.yaml with the following content:

apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: nginx
version: 0.1.0

values.yaml

Fill values.yaml with the following content:

name: nginx

image:
  name: nginx
  repository: nginx
  version: 1.14.2

replicaCount: 3

port: 80

deployment.yaml

In deployment/templates/deployment.yaml, use the following template:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.name }}-deployment
  labels:
    app: {{ .Values.name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.name }}
    spec:
      containers:
      - name: {{ .Values.image.name }}
        image: {{ .Values.image.repository }}:{{ .Values.image.version }}
        ports:
        - containerPort: {{ .Values.port }}

In this template, {{ .Values.property }} references the corresponding property in values.yaml. For example, {{ .Values.image.repository }} retrieves the repository value under the image section.

Testing the Helm Chart

To test the Helm chart and view the generated Kubernetes manifest, run:

helm template deployment

This command will output the Kubernetes manifest, which should match the expected configuration specified earlier.

By following this tutorial, you’ve created a parameterized Helm chart that generates Kubernetes manifests for deploying an Nginx application. This approach allows for easy customization and scalability of your deployments.

For more detailed information on Helm and chart development, refer to the official Helm documentation.

← Blog'a Dön