What Is Helm?
Helm is a package manager for Kubernetes, simplifying the deployment and management of applications. By bundling Kubernetes YAML manifests into a single package called a Helm chart, it simplifies the deployment process.
Helm charts manage configuration and deployment and enable users to define and share Kubernetes applications. This reduces errors and accelerates the setup of Kubernetes environments, with Helm acting as an intermediary layer for management.
Helm also enables the sharing of applications and environments across teams by providing a standardized method to describe Kubernetes applications. It allows for distribution and deployment of applications, promoting collaboration and reducing redundancy.
We’ll provide two quick tutorials showing how to deploy applications in your Kubernetes cluster with Helm, the first showing how to deploy an existing Helm chart, and the second using a custom Helm chart you create yourself.
This is part of a series of articles about Kubernetes management
Step-By-Step Tutorial #1: Deploying Existing Helm Chart on Kubernetes
This tutorial outlines the steps to deploy a new Helm chart on Kubernetes, export the necessary connection details, and view the deployed application.
Install Helm Chart
To deploy a Helm chart, use the helm install
command. This command installs the application defined by the chart.
For example:
helm install phoenix-chart phoenixnap/ --values phoenixnap/values.yaml
Here:
phoenix-chart
is the release name.phoenixnap/
specifies the chart directory.--values phoenixnap/values.yaml
applies custom configuration from the specifiedvalues.yaml
file.
The helm install
command triggers the deployment of the application based on the configuration in the Helm chart.
Export Node Port and IP Address
After deploying the chart, export the Node Port and IP address to access the application externally. Use the commands provided in the NOTES section of the helm install
output. For example:
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services phoenix-chart) export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
These commands:
- Retrieve the Node Port from the Kubernetes Service object.
- Retrieve the IP address of the Kubernetes node.
- Store the results in the
NODE_PORT
andNODE_IP
environment variables for further use.
View the Deployed Application
To access the application, display the environment variables created in the previous step:
echo http://$NODE_IP:$NODE_PORT
This command constructs the URL to access the deployed application. Copy the resulting URL and paste it into a web browser. The application interface should load, confirming a successful deployment.
Following these steps ensures a seamless process for deploying Helm charts and verifying their accessibility in a Kubernetes environment.
TIPS FROM THE EXPERT
In my experience, here are tips that can help you better optimize Helm deployments:
- Leverage Helm hooks for custom logic: Helm provides hooks that allow you to run certain actions at different points in the release lifecycle, such as before or after an install, upgrade, or rollback. Use hooks to handle pre-deployment validations, database migrations, or clean-up tasks when uninstalling.
- Use Helm chart testing tools: Tools like helm unittest allow you to write unit tests for your charts. This helps catch potential misconfigurations early by verifying that templates render correctly for various configurations before deploying.
- Opt for Helmfile for complex, multi-chart deployments: Helmfile lets you manage multiple Helm charts in a declarative way, especially useful for orchestrating multi-environment, multi-chart setups. It simplifies the deployment of several services in a specific order and with shared values.
- Integrate Helm with secret management systems: Instead of hardcoding secrets in your values.yaml, integrate Helm with external secret management tools like HashiCorp Vault or AWS Secrets Manager. Use tools like helm-secrets to encrypt and manage sensitive data securely in your charts.
- Define consistent values with schema.yaml: Use the schema.yaml feature in Helm v3 to define a JSON schema for validating the values passed to your chart. This helps ensure consistency across different deployments by preventing invalid configurations from being applied.
Step By Step Tutorial #2: Deploying a Custom Application on Kubernetes with Helm
In this tutorial, we’ll show how to create a custom Helm deployment based on Apache Kafka, with some custom deployment values, deploy it to a Kubernetes cluster and set up ingress to enable it to receive traffic.
1. Prerequisites
Before deploying applications using Helm, ensure that you have the following tools installed and configured on your local machine:
- Docker: Required for containerizing applications.
- Minikube: A local Kubernetes cluster used for testing.
- kubectl: The command-line tool for interacting with Kubernetes clusters.
- Helm (v3): The package manager for Kubernetes.
To verify the installation:
- Start Minikube with the following command:
$ minikube start
- Enable the Ingress addon to manage external access to your services:
$ minikube addons enable ingress
- Make sure the hosts file is configured correctly to route traffic to your Minikube IP address:
$ minikube ip
- Add the IP and corresponding domain names to the hosts file.
2. Creating a Custom Helm Chart
Creating your own Helm chart is straightforward:
- Start by generating a basic chart structure with:
$ helm create kafka
- For an Apache Kafka deployment, you’ll typically need to configure a Deployment, Service, StatefulSet, and ConfigMap. To configure the StatefulSet, create statefulset.yaml in the templates/ directory:
apiVersion: apps/v1 kind: StatefulSet metadata: name: kafka spec: replicas: 1 selector: matchLabels: app: kafka serviceName: kafka template: metadata: labels: app: kafka spec: containers: - name: kafka image: bitnami/kafka:latest ports: - containerPort: 9092 env: - name: KAFKA_BROKER_ID value: "0" - name: KAFKA_LISTENERS value: PLAINTEXT://:9092 - name: KAFKA_ZOOKEEPER_CONNECT value: zookeeper:2181 volumeMounts: - mountPath: /bitnami/kafka name: kafka-storage volumeClaimTemplates: - metadata: name: kafka-storage spec: accessModes: [ "ReadWriteOnce" ] resources: requests: storage: 10Gi
This template uses values defined in values.yaml, making the configuration flexible and reusable.
- Define the Service object in service.yaml:
apiVersion: v1 kind: Service metadata: name: kafka spec: ports: - port: 9092 targetPort: 9092 selector: app: kafka
This service will expose the Kafka deployment to other pods within the cluster.
- Now, start customizing the values. The values.yaml file holds the default values for the chart. For example:
kafka: name: kafka container: image: bitnami/kafka:latest port: 9092 service: type: ClusterIP port: 9092 volume: name: kafka-storage mountPath: /bitnami/kafka
You can override these values when deploying by specifying a custom YAML file.
3. Deploying the Custom Chart
Once the chart is ready, deploy it using Helm:
$ helm install -f kafka-values.yaml kafka ./kafka
This command creates a Helm release named kafka using the custom values specified in kafka-values.yaml.
4. Deploying Multiple Applications with a Single Chart
Helm’s templating and value management capabilities allow developers to use a single chart for multiple deployments. For example, you can create a general application chart and deploy different applications like Kafka, Zookeeper, and other Kafka clients by creating separate value files for each:
$ helm create app
After customizing the templates and values.yaml, deploy each application:
$ helm install -f zookeeper.yaml zookeeper ./app $ helm install -f kafka-client.yaml kafka-client ./app
Each command deploys a separate application using the shared chart.
5. Managing Ingress with Helm
Ingress Controllers manage external access to the services in a Kubernetes cluster:
- Create an Ingress Helm chart:
$ helm create ingress
- Define the Ingress resource in ingress.yaml to route traffic:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: kafka-ingress spec: rules: - host: kafka.local http: paths: - path: / pathType: Prefix backend: service: name: kafka port: number: 9092
- After setting up the Ingress rules, deploy the Ingress controller:
$ helm install -f ingress.yaml ingress ./ingress
This deployment will manage routing for the applications in the cluster.
6. Verifying the Deployment
After deploying the applications and Ingress controller, list the deployments to verify:
$ helm list $ kubectl get statefulsets
This will show the status of all deployed applications, ensuring they are running as expected.
Learn More About GitOps and Helm Chart Deployment
Helm can be very helpful as a familiar component that can help teams transition from traditional workflows to GitOps. Here are additional articles that can help you use Helm charts with GitOps:
- Using Helm with GitOps – explores Helm, shows how Helm charts are mapped to Kubernetes manifests, and provides practical guidance for using Helm with GitOps.
- How to Simplify Your Kubernetes Helm Deployments – explains what to do if the Helm chart promotion process becomes complicated and difficult to automate. Learn a few Helm techniques that can make your process simpler and more robust.
- Using Help to Deploy a Kubernetes Application to Multiple Environments – shows how to use Helm to address a common deployment challenge – how to handle QA, staging, and production environments during the software lifecycle.
- Unlimited Preview Environments with Kubernetes Namespaces – shows how to create testing environments on demand for each pull request.
Deploy more and fail less with Codefresh and Argo