1. Why Helm Is Needed
One important design philosophy in Kubernetes is declarative operation. Users change the system by setting the system’s expected state. For example, the current replica count is 2 and it needs to be adjusted to 3. The declarative way is to modify the replica count in the configuration file to 3; the imperative way is to send a command that adds one replica, +1.
A system that uses declarative configuration focuses more on the outcome and places higher demands on system design. In a distributed system, no component is 100% reliable; for users, a declaratively configured system is friendlier.
Kubernetes uses yaml as its configuration file format. Deploying a simple Jenkins service in Kubernetes means writing two yaml files: jenkins-deployment.yaml and jenkins-service.yaml. See Deploying Jenkins with Kubectl. Add other services, and take into account multiple environments, and the number of yaml files that must be maintained becomes very large.
Maintaining yaml directly for deployment is bad both for project organization and for maintenance and updates. We need a tool that simplifies the application deployment and management process.
2. What Helm Is
Helm is a Kubernetes package manager started by Deis, similar to the apt and yum tools in Linux. Deis has been acquired by Microsoft.
2.1 Basic Concepts
- Chart
A Chart is used to package yaml files; it contains the images, dependencies, resources, service definitions, and so on required to run an application.
- Release
An instance of a Chart on a Kubernetes cluster. Every installation creates a new Release, and a single Chart can correspond to many instances.
- Repository
A repository used to publish and store Charts.
2.2 Basic Components
Helm uses a C/S architecture. The components are:
- Helm CLI
Helm CLI is the Helm client. It runs locally and is responsible for interacting with the other components.
- Tiller
Tiller is the server-side component. It runs on the Kubernetes cluster and manages the applications deployed by Helm.
- Repository
Repository is the Chart repository.
2.3 Features Helm Provides
- Application packaging
- Application distribution
- Version management
- Dependency checking
3. Chart
By creating a folder with a specific directory structure, a chart describes a set of application resources and guides application deployment.
The chart package structure for Wordpress:
| |
The contents of the Chart.yaml file:
| |
4. Installation and Usage
Because Helm uses a C/S architecture, installation has two parts: the client and the server. The exact commands differ by operating system; see the official Helm documentation. Here we use an OS X client and a CentOS server running minikube as the example.
4.1 Installing the Client
On OS X:
| |
On CentOS:
| |
View the repository sources:
| |
It is recommended to update the repository source:
| |
4.2 Installing the Server
- Install tiller
Since a remote development environment is configured (see Building a Remote Kubernetes Development Environment), run the following on OS X:
| |
On Kubernetes 1.16.0 and later you may hit Error: error installing: the server could not find the requested resource. This is because extensions/v1beta1 has been replaced by apps/v1. Run the following command to install:
| |
tiller will be installed into the kube-system namespace; you can check it with the kubectl get pods --namespace kube-system command.
- Create an access role
Run the commands:
| |
4.3 Checking Whether Helm Works
Running the helm version command checks whether both the local and the server installation are ready.
| |
If the Server side reports an error, it may be caused by a missing package on the Node, for example socat. Log in to the server and run yum install -y socat.
4.4 Creating a Chart Deployment
- Create a new chart
| |
In values.yaml you can see that a Nginx application is created by default. To make it easier to access from outside for testing, change the service properties in values.yaml to:
| |
- Deploy to the server
| |
- View the deployed application
After a few seconds the application is running. Open the address http://10.10.10:32046 and you will see the Nginx page.
- View the release
| |
- Package the chart
| |
Note that this must be run from the parent directory of hello-chart. Packaging simply compresses the hello-chart folder into a tgz file.
- Delete the release:
| |
After deletion, the application is removed as well.
