Getting Started with Kubernetes Helm Charts

28/12/2020

Getting Started With Helm Charts

Helm makes Kubernetes more user-friendly. It is a package manager. Helm Charts makes it easier to design, install and upgrade a Kubernetes application. They manage the complexity to make the installation process repeatable. Users are easily able to update and share their designs. Also, Helm has a rollback function to easily go back to order versions.

Helm Chart Structure

With the create command, Helm provides a predetermined structure to ensure a standard.

hello-world

├── Chart.yaml
├── charts
├── templates
│   ├── NOTES.txt
│   ├── _helpers.tpl
│   ├── deployment.yaml
│   ├── ingress.yaml
│   └── service.yaml
└── values.yaml

The files above will be auto-generated. Helm uses YAML format for configuration files.

Invoking Helm

In order to use Helm, you’ll need the following things:

  • A Kubernetes Cluster (Minikube provides a simple way of running Kubernetes)
  • Install Helm and Tiller, the server-side component.

(Make sure the Minikube and Tiller versions are compatible with the Kubernetes Cluster)

Once you have all the components installed, start your minikube:

$ minikube start

You will also need to use the following command to initialize Helm and Tiller:

$ helm init

Next, use the following Helm command to create the structure described above:

$ helm create hello-world

Writing Your First Helm Chart

Let’s check the status of the pods:

$ kubectl get pod –all-namespaces
NAMESPACE     NAME                                    READY     STATUS    RESTARTS   AGE
kube-system   kube-addon-manager-minikube             1/1       Running   2          1h
kube-system   kube-dns-54cccfbdf8-xcltd               3/3       Running   6          1h
kube-system   kubernetes-dashboard-77d8b98585-sj9lm   1/1       Running   2          1h
kube-system   storage-provisioner                     1/1       Running   2          1h
kube-system   tiller-deploy-59d854595c-97hdp          1/1       Running   2          1h

The tiller pod and the minikube pods are running. Let’s make some changes to Helm Charts. We are going to open the value.yml. It looks like this:

# Default values for hello-world.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
 
replicaCount: 1
 
image:
repository: heroku/nodejs-hello-world
tag: stable
pullPolicy: IfNotPresent
 
service:
type: ClusterIP
port: 80
 
ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
path: /
hosts:
– chart-example.local
tls: []
#  – secretName: chart-example-tls
#    hosts:
#      – chart-example.local
 
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after ‘resources:’.
# limits:
#  cpu: 100m
#  memory: 128Mi
# requests:
#  cpu: 100m
#  memory: 128Mi
 
nodeSelector: {}
 
tolerations: []
 
affinity: {}

The highlighted line has been changed. Instead of nginx, we are going to download heroku/nodejs-hello-world. You can set the default values in this value.yml file. They will be shared with other files.

If we check Helm, we don’t see anything:

$ helm ls

Let’s start the Helm Chart:

$ helm install hello-world
NAME:   kissing-markhor
LAST DEPLOYED: Fri Mar  9 09:13:04 2018
NAMESPACE: default
STATUS: DEPLOYED
 
RESOURCES:
==> v1/Service
NAME                         TYPE       CLUSTER-IP     EXTERNAL-IP  PORT(S)  AGE
kissing-markhor-hello-world  ClusterIP  10.110.109.73  <none>       80/TCP   1s
 
==> v1beta2/Deployment
NAME                         DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
kissing-markhor-hello-world  1        1        1           0          1s
 
==> v1/Pod(related)
NAME                                          READY  STATUS             RESTARTS  AGE
kissing-markhor-hello-world-6bbb947b9c-rttnz  0/1    ContainerCreating  0         1s
 
 
NOTES:
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods –namespace default -l "app=hello-world,release=kissing
-markhor"
-o jsonpath="{.items[0].metadata.name}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl port-forward $POD_NAME 8080:80

The noticeable part is the “NAME”. This name was generated by Helm.

Let’s check Helm:

$ helm ls
NAME             REVISION    UPDATED                     STATUS     CHART              NAMESPACE
kissing-markhor  1           Fri Mar  9 09:13:04 2018    DEPLOYED   hello-world-0.1.0  default

Also Kubernetes:

$ kubectl get pod –all-namespaces
NAMESPACE     NAME                                          READY  STATUS    RESTARTS AGE
default       kissing-markhor-hello-world-6bbb947b9c-rttnz  1/1    Running   0        5m
kube-system   kube-addon-manager-minikube                   1/1    Running   2        2h
kube-system   kube-dns-54cccfbdf8-xcltd                     3/3    Running   6        2h
kube-system   kubernetes-dashboard-77d8b98585-sj9lm         1/1    Running   2        2h
kube-system   storage-provisioner                           1/1    Running   2        2h
kube-system   tiller-deploy-59d854595c-97hdp                1/1    Running   2        2h

So the pod has been deployed to Kubernetes. We can use port forwarding:

$ kubectl port-forward kissing-markhor-hello-world-6bbb947b9c-rttnz 8080:80

Now you should be able to check your deployed application.

$ curl http://127.0.0.1:8080
 
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
 
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
 
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

Alternatively, you can check http://127.0.0.1:8080 to see the newly created application. Let’s tidy up. Find the server name:

$ helm ls
NAME             REVISION  UPDATED                    STATUS     CHART               NAMESPACE

kissing-markhor  1         Fri Mar  9 09:13:04 2018   DEPLOYED   hello-world-0.1.0   default

Use the following command to delete:

$ helm delete kissing-markhor
release "kissing-markhor" deleted

Let’s check the cluster:

$ kubectget pod –all-namespaces
NAMESPACE     NAME                                    READY  STATUS    RESTARTS  AGE
kube-system   kube-addon-manager-minikube             1/1    Running   2         2h
kube-system   kube-dns-54cccfbdf8-xcltd               3/3    Running   6         2h
kube-system   kubernetes-dashboard-77d8b98585-sj9lm   1/1    Running   2         2h
kube-system   storage-provisioner                     1/1    Running   2         2h
kube-system   tiller-deploy-59d854595c-97hdp          1/1    Running   2         2h

We can see the kissing-marker pod is gone.

Conclusion

The above should give you the inspiration to start using Helm Charts. It should make your Kubernetes deployments easier to handle.

References:

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Kubernetes: Getting Started

Kubernetes is an open-source platform for managing containerized applications across a cluster of physical or virtual machines....
28/12/2020

Setup a Kubernetes Cluster on DigitalOcean

Kubernetes is one of the few technologies that people struggle with not because it is complicated and hard to understand,...
28/12/2020

Book Review: Getting Started with Kubernetes – Second Edition

Kubernetes is both a powerful tool and a work in progress. Naturally, there is a lot of interest in the technology. At...
28/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024

Thuê địa chỉ IPv4 IPv6 trọn gói ở đâu chất lượng, giá RẺ nhất?
27/05/2024