Helm is a package manager for Kubernetes that simplifies the process of installing, upgrading, and managing applications in a Kubernetes cluster. Helm packages are called charts, and they include all the resources necessary to deploy an application, such as Kubernetes manifests, configuration files, and dependencies.
Here’s how you can use Helm to manage application deployments in Kubernetes:
Install Helm:
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
Create a new Helm chart:
helm create mychart
This will create a new directory called mychart, which contains the files for the chart.
Edit the values.yaml file to set the configuration options for the application.
For example, let’s say we’re deploying a simple web application that listens on port 8080. We can set the port number in the values.yaml file like this:
service:
port: 8080
Add any necessary Kubernetes resources to the chart, such as Deployments, Services, and ConfigMaps.
For example, let’s say we have a Deployment that runs a container with the image myimage:latest, and we want to expose it using a Service. We can add the following to the templates/deployment.yaml file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Chart.Name }}
labels:
app: {{ .Chart.Name }}
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Chart.Name }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: myimage:latest
ports:
- containerPort: 8080
And we can add the following to the templates/service.yaml file:
apiVersion: v1
kind: Service
metadata:
name: {{ .Chart.Name }}
spec:
selector:
app: {{ .Chart.Name }}
ports:
- port: {{ .Values.service.port }}
targetPort: 8080
type: ClusterIP
This will create a Deployment with one replica that runs the myimage:latest container and a Service that exposes it on port 8080.
Package the chart:
helm package mychart
This will create a mychart.tgz file, which is the packaged chart.
Install the chart in a Kubernetes cluster:
helm install myrelease mychart.tgz
This will install the chart in a new release called myrelease.
Verify the deployment:
kubectl get deployments,services
This will show the status of the Deployment and Service created by the chart.
Upgrade the chart:
If you need to make changes to the chart, you can upgrade it using the following command:
helm upgrade myrelease mychart.tgz
This will upgrade the chart to the latest version and apply any changes you’ve made.
Helm simplifies the process of managing application deployments in Kubernetes by providing a standardized way to package, install, and upgrade applications. It also enables you to easily share and reuse charts with others in your organization.