# Create a Chart in Helm

In 
Published 2022-12-03

This tutorial explains to you how to create a simple chart in Helm.

A Helm chart is a set of YAML manifests and templates that describes Kubernetes resources (Deployments, Secrets, CRDs, etc.) and defined configurations needed for the Kubernetes application.

Since the Kubernetes YAML manifest can be templated, you don't have to maintain multiple helm charts of different environments.

To create a chart you can run the following command to create "my-first-chart" chart:

helm create my-first-chart

You will see that a folder named my-first-chart is created, and it is populated with 2 directories and some files.

The example below will put together the deployment from Create, View and Destroy a Deployment and the service from Create a NodePort service.

We will package these two things into a package and when we deploy the Helm Chart, we deploy both the Kubernetes deployment and the service.

Go to ./templates/deployment.yaml and modify the file to look like:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-first-deploy
spec:
  replicas: {{.Values.replicaCount}}
  selector:
    matchLabels:
      app: {{.Values.app.label}}
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: {{.Values.app.label}}
    spec:
      containers:
      - name: app1-pod
        image: nginx:1.14.2
        ports:
        - containerPort: 8080

The same thing we do for the ./templates/service.yaml :

kind: Service 
apiVersion: v1 
metadata:
  name: http-server-service 
spec:
  type: {{.Values.service.type}}
  selector:
    app: {{.Values.app.label}}
  ports:
    - nodePort: {{.Values.service.nodePort}}
      port: 8080 
      targetPort: 80

And, here it is the values.yaml file :

replicaCount: 4

service:
  type: NodePort
  nodePort: 30001

app:
  label: "app1"

In order to deploy the chart on Kubernetes we need to run the following command:

helm install my-first-chart ./

And you will see on the screen something like this:

NAME: my-first-chart
LAST DEPLOYED: Thu Feb  2 21:54:36 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

If you want to get more information on Helm deployments you can run helm ls or helm list. You will receive something like this:

NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
my-first-chart  default         1               2023-02-02 21:54:36.6708663 +0200 EET   deployed        my-first-chart-0.1.0    1.16.0

Now we can run kubernetes commands to see our service:

kubectl get services
NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
http-server-service   NodePort    10.109.141.180   <none>        8080:30001/TCP   4m28s
kubernetes            ClusterIP   10.96.0.1        <none>        443/TCP          23h

This is a simple Helm chart, but in real live we have more complicated charts.