### Overview
Deploying complex applications in Kubernetes often involves managing multiple resources like deployments, services, ConfigMaps, and secrets. Helm simplifies this process by allowing you to package all these resources into a single package, called a Chart, which can be easily deployed and managed.
### What is Helm?
Helm is a package manager for Kubernetes, similar to yum or apt for Linux. It allows you to package Kubernetes manifests into a Chart, making it easier to share and deploy complex applications. Helm Charts can be stored in repositories, which can be public or private.
### Helm v3
Helm v3 brought significant changes, including the removal of the Tiller component, which was a security concern in Helm v2. Helm now operates client-side, and no longer requires cluster-side components to function, simplifying its use and improving security.
### Chart Contents
A Helm Chart is a collection of files that describe a related set of Kubernetes resources. A typical Chart directory looks like this:
```
├── Chart.yaml
├── README.md
├── templates
│ ├── NOTES.txt
│ ├── _helpers.tpl
│ ├── configmap.yaml
│ ├── deployment.yaml
│ ├── pvc.yaml
│ ├── secrets.yaml
│ └── svc.yaml
└── values.yaml
```
- **Chart.yaml**: Contains metadata about the Chart, such as its name, version, and description.
- **README.md**: Optional file providing information about the Chart.
- **templates/**: Contains Kubernetes manifest templates.
- **values.yaml**: Defines default values for the templates.
### Templates
Templates in the `templates` directory use Go templating syntax to inject values from `values.yaml` into the manifests. This allows for dynamic configuration of resources.
For example, a Secret template might look like this:
```yaml
apiVersion: v1
kind: Secret
metadata:
name: {{ template "fullname" . }}
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
type: Opaque
data:
mariadb-root-password: {{ default "" .Values.mariadbRootPassword | b64enc | quote }}
mariadb-password: {{ default "" .Values.mariadbPassword | b64enc | quote }}
```
### Chart Repositories and Hub
Helm Charts are stored in repositories, which are simple HTTP servers containing an index file and tarballs of the Charts. You can search for Charts in the Artifact Hub or add specific repositories.
```bash
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm repo list
```
You can search for Charts within a repository using keywords:
```bash
$ helm search repo bitnami
```
### Deploying a Chart
To deploy a Chart, use the `helm install` command. Ensure that any necessary resources (like Persistent Volumes) are available before deployment. You can fetch and untar a Chart to review its contents and make necessary adjustments.
```bash
$ helm fetch bitnami/apache --untar
$ cd apache/
$ ls
```
Install the Chart:
```bash
$ helm install mywebserver .
```
You can list, delete, upgrade, and roll back releases easily:
```bash
$ helm list
$ helm delete mywebserver
$ helm upgrade mywebserver .
$ helm rollback mywebserver 1
```
### Managing Complex Applications
Helm makes it easy to manage complex applications with multiple interdependent resources. By packaging these resources into a single Chart, you can deploy, update, and roll back applications with ease.
### Using Helm for Machine Learning
Helm is particularly useful for deploying machine learning workflows, where you need to manage various resources like training jobs, model servers, and databases. Tools like **Kubeflow** and **KServe** provide Helm Charts for deploying ML components on Kubernetes.
#### Example: Deploying a Machine Learning Model with Helm
1. **Install KServe Helm Chart**:
```bash
$ helm repo add kserve https://kserve.github.io/charts
$ helm repo update
$ helm install kserve kserve/kserve
```
2. **Deploy a PyTorch Model**:
```yaml
apiVersion: "serving.kserve.io/v1beta1"
kind: "InferenceService"
metadata:
name: "pytorch-serve"
spec:
predictor:
pytorch:
storageUri: "gs://your-bucket/models/pytorch/model"
runtimeVersion: "latest"
```
3. **Create the InferenceService**:
```bash
$ kubectl apply -f pytorch-serve.yaml
```
4. **Access the Model**:
```bash
$ kubectl get svc pytorch-serve -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
```
### Conclusion
Helm simplifies the deployment and management of complex Kubernetes applications by packaging multiple resources into a single Chart. It offers a powerful way to share, deploy, and manage applications, making it an essential tool for Kubernetes administrators. For machine learning workloads, Helm Charts provided by tools like Kubeflow and KServe streamline the deployment of models and workflows, enhancing productivity and scalability.
Continue: [[10-Ingress]]