In the dynamic world of Docker orchestration, Helm plays a pivotal role in managing Kubernetes applications. It streamlines the process of discovering, sharing, and using software from a catalog of packaged Kubernetes applications known as charts. Today, we'll explore a comprehensive guide on Helm, focusing on deployment templates with an illustrative example.

Before delving into the specifics, let's quicken the pulse of things. Helm is a package manager for Kubernetes, enabling you to find, share, and use software built for Kubernetes. Now, let's dive into the depths of Helm deployment templates.

Understanding Helm Deployment Templates
Helm deployment templates are a compelling feature of Helm, enabling you to create reusable, customizable Kubernetes manifests. They serve as a blueprint for your Kubernetes objects, allowing you to specify placeholders (also known as chart parameters) that can be filled with different values depending on the specific environment.
![[Kubernetes] Package Manager - Helm 簡介](https://i.pinimg.com/originals/78/15/0e/78150eab0af219181d8513e8f04ee82f.png)
These templates empower you to separate the concerns of what your application does (defined in the chart) from where and how it runs (defined in the release). Now, let's look at two crucial aspects of Helm deployment templates - values.yaml and templates.
values.yaml: Customizing Your Deployment

The values.yaml file forms the heart of Helm deployment templates, allowing you to customize your applications' behavior during deployment. It contains a list of key-value pairs, with each key representing a configuration parameter for your application.
For instance, consider a Helm chart of a simple Redis deployment. The values.yaml file might look like this: ```yaml master: enabled: true startup: 30 replicas: 2 ``` This indicates that the Redis master should be enabled, and it should start within 30 seconds. It also specifies that two Redis replicas should be created.
templates: Your Kubernetes Blueprints

The templates directory in your Helm chart houses the actual Kubernetes manifests (written in Go templates) responsible for creating, updating, and deleting Kubernetes resources. These templates take in the values defined in values.yaml and generate the final, environment-specific Kubernetes manifests.
Continuing with the Redis example, the templates directory might contain a file named redis-deployment.yaml, which could look like this: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "mychart.fullname" . }} .spec: replicas: {{ .Values.replicas }} selector: matchLabels: app.kubernetes.io/name: {{ include "mychart.name" . }} template: metadata: labels: app.kubernetes.io/name: {{ include "mychart.name" . }} spec: containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" ports: - name: http containerPort: 80 protocol: TCP ``` This Go template generates a Kubernetes Deployment resource, utilizing the values defined in values.yaml to specify the number of replicas and the container image's repository and tag.
Helm Deployment Template Example: A Simple Redis Application

Now that we've discussed the fundamentals of Helm deployment templates, let's create a simple Redis application using Helm. Our chart will consist of a values.yaml file and a redis-deployment.yaml template.
First, create a new directory for your chart and initiate it with Helm using `helm create my-redis-chart`. This command generates a basic Helm chart structure. Replace the contents of values.yaml and redis-deployment.yaml with the examples provided earlier. Then, package your chart with `helm package my-redis-chart`.









Deploying Your Helm Chart
With your Helm chart packaged, you can deploy it to your Kubernetes cluster using the following command: ```bash helm upgrade --install my-redis-release /path/to/my-redis-chart-0.1.0.tgz ``` This command upgrades the existing release named my-redis-release (or installs it if it doesn't exist) with the chart at the specified path, using the values defined in values.yaml.
In conclusion, Helm deployment templates offer a powerful way to customize and manage Kubernetes applications. By leveraging values.yaml and templates, you can create flexible, reusable Kubernetes manifests ready to be deployed to various environments. Start exploring Helm deployment templates today and elevate your Kubernetes application management to new heights!