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.
This is part of a series of articles about Kubernetes management
Key Benefits of Using Helm for Deployments
Here are a few benefits of using Helm to deploy applications in a Kubernetes cluster.
Simplified Deployment Management
Helm simplifies deployment management by providing a structured approach to package, configure, and deploy Kubernetes applications. Users can handle multiple deployments and configurations with a single command, eliminating repetitive and error-prone manual processes. This saves time and minimizes errors associated with Kubernetes setups.
Helm’s templating system offers tools to define dynamic configurations. This allows developers to create parameterized charts, accommodating various deployment scenarios without rewriting base configurations. By providing a separation between configuration and code, Helm improves maintainability and adaptability in dynamic environments.
Reusability and Consistency
Helm charts support reusability and consistency across deployments by encapsulating Kubernetes resources into verifiable packages. This ensures that configurations remain uniform across different environments, reducing discrepancies between development and production stages.
Helm allows organizations to distribute tested and reliable charts, promoting standardization within teams and across departments. The reuse of Helm charts provides a level of consistency that supports scaling and replication, ensuring a smoother DevOps workflow by assuring that every version remains aligned with organizational standards.
Environment Customization
Helm allows parameter overrides and value management within charts to customize environments. Users can define a single chart to accommodate different environments such as development, staging, and production, with different parameter values for each case. This granular control supports tailored deployments without modifying the core chart structure.
Helm also supports managing environment-specific configuration files, accommodating various scenarios and workloads. Engineers can tailor applications for environments using value files corresponding to each environment.
Rollbacks and Upgrades
Helm brings version control to Kubernetes deployments by offering rollbacks and upgrades. Users can revert applications to previous versions or apply updates through Helm’s tooling. This mitigates the risks associated with failed deployments, as rollbacks can be quickly executed to restore stable states.
Helm tracks changes and retains a history of releases, allowing detailed audits and adjustments. Infrastructure teams can use Helm’s upgrade functionalities to transition between application versions. Updates can be tested and rolled back in response to issues or failures, ensuring that production environments remain stable.
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: 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
2. Enable the Ingress addon to manage external access to your services:
$ minikube addons enable ingress
3. Make sure the hosts file is configured correctly to route traffic to your Minikube IP address:
$ minikube ip
4. 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
2. 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.
3. 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.
4. 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
2. 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
3. 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