This tutorial explain the process of creating your first ever chart, explaining what goes inside these packages and the tools you use to develop them. By the end of it you should have an understanding of the advantages of using Helm to deliver your own applications to your cluster.
For this we use 3-tier architecture, the diagram below illustrates how it might be described in terms of Kubernetes objects.
A Kubernetes object is a “record of intent”–once you create the object, the Kubernetes system will constantly work to ensure that object exists. By creating an object, you’re effectively telling the Kubernetes system what you want your cluster’s workload to look like; this is your cluster’s desired state.
A Helm chart encapsulates each of these YAML definitions, provides a mechanism for configuration at deploy-time and allows you to define metadata and documentation that might be useful when sharing the package. Helm can be useful in different scenarios:
- Find and use popular software packaged as Kubernetes charts
- Share your own applications as Kubernetes charts
- Create reproducible builds of your Kubernetes applications
- Intelligently manage your Kubernetes object definitions
- Manage releases of Helm packages
Let’s explore the second and third scenarios by creating our first chart.
Step 1. Generate Your First Chart
$ helm create rcherara-chart-3-tier-architecture
The most important piece of the puzzle is the templates/ directory. This is where Helm finds the YAML definitions for your Services, Deployments and other Kubernetes objects. If you already have definitions for your application, all you need to do is replace the generated YAML files for your own. What you end up with is a working chart that can be deployed using the helm install command.
the service.yaml file
This is a basic Service definition using templating. When deploying the chart, Helm will generate a definition that will look a lot more like a valid Service. We can do a dry-run of a helm install and enable debug to inspect the generated definitions:
$ helm install --dry-run --debug ./rcherara-chart-3-tier-architecture
The Output :
[debug] Created tunnel using local port: '53883'
[debug] SERVER: "127.0.0.1:53883"
[debug] Original chart version: ""
[debug] CHART PATH: /Users/rcherara/Projects-Helm-Chart/rcherara-chart-3-tier-architecture
NAME: kneeling-crab
REVISION: 1
RELEASED: Mon Dec 31 11:38:38 2018
CHART: rcherara-chart-3-tier-architecture-0.1.0
USER-SUPPLIED VALUES:
{}
COMPUTED VALUES:
affinity: {}
fullnameOverride: ""
image:
pullPolicy: IfNotPresent
repository: nginx
tag: stable
ingress:
annotations: {}
enabled: false
hosts:
- chart-example.local
paths: []
tls: []
nameOverride: ""
nodeSelector: {}
replicaCount: 1
resources: {}
service:
port: 80
type: ClusterIP
tolerations: []
HOOKS:
---
# kneeling-crab-rcherara-chart-3-tier-architecture-test-connection
apiVersion: v1
kind: Pod
metadata:
name: "kneeling-crab-rcherara-chart-3-tier-architecture-test-connection"
labels:
app.kubernetes.io/name: rcherara-chart-3-tier-architecture
helm.sh/chart: rcherara-chart-3-tier-architecture-0.1.0
app.kubernetes.io/instance: kneeling-crab
app.kubernetes.io/managed-by: Tiller
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['kneeling-crab-rcherara-chart-3-tier-architecture:80']
restartPolicy: Never
MANIFEST:
---
# Source: rcherara-chart-3-tier-architecture/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: kneeling-crab-rcherara-chart-3-tier-architecture
labels:
app.kubernetes.io/name: rcherara-chart-3-tier-architecture
helm.sh/chart: rcherara-chart-3-tier-architecture-0.1.0
app.kubernetes.io/instance: kneeling-crab
app.kubernetes.io/managed-by: Tiller
spec:
type: ClusterIP
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: rcherara-chart-3-tier-architecture
app.kubernetes.io/instance: kneeling-crab
---
# Source: rcherara-chart-3-tier-architecture/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: kneeling-crab-rcherara-chart-3-tier-architecture
labels:
app.kubernetes.io/name: rcherara-chart-3-tier-architecture
helm.sh/chart: rcherara-chart-3-tier-architecture-0.1.0
app.kubernetes.io/instance: kneeling-crab
app.kubernetes.io/managed-by: Tiller
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: rcherara-chart-3-tier-architecture
app.kubernetes.io/instance: kneeling-crab
template:
metadata:
labels:
app.kubernetes.io/name: rcherara-chart-3-tier-architecture
app.kubernetes.io/instance: kneeling-crab
spec:
containers:
- name: rcherara-chart-3-tier-architecture
image: "nginx:stable"
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{}
the deployement.yaml file
Step 2. Deploying Your First Chart
By default, the chart will create a ClusterIP type Service, so NGINX will only be exposed internally in the cluster. To access it externally, we’ll use the NodePort type instead.
$ helm install --name rcherara-example ./rcherara-chart-3-tier-architecture --set service.type=NodePort
The output of helm install displays a handy summary of the state of the release, what objects were created, and the rendered NOTES.txt file to explain what to do next.
To can get the service URL by running the command :
$ minikube service list
$ minikube service rcherara-example-rcherara-chart-3-tier-architecture --url
or from the dashboard
If all went well, you should see the NGINX welcome page as shown above. Congratulations! You’ve just deployed your very first service packaged as a Helm chart!
Step 3. Packaging
$ helm package ./rcherara-chart-3-tier-architecture
To install new app from this package run :
$ helm install --name rcherara-from-package-3-tier-architecture rcherara-chart-3-tier-architecture-0.1.0.tgz --set service.type=NodePort
$ helm search local
Contribute To The Stable Repository!
Now as you are a chart author, you can help to build out the stable repository by improving existing charts or submitting new ones. Checkout https://kubeapps.com to see what’s currently available and head to https://github.com/helm/charts to get involved.