Skip to content

Helm_Lab_02 | Basic Chart

Sandeep Rawat edited this page Dec 9, 2020 · 18 revisions

Helm Lab 02

In this section of the lab, we'll create a helm chart for application deployement. The chart we created here will be used throughout the rest of the lab.

  • Helm chart to deploy a basic app
  • Walkthrough of various Kubernetes manifests we will be creating

To get going, let's take a brief look at a Helm chart.

Introduction of Charts

Helm uses a packaging format called charts. A chart is a collection of files that describe a related set of Kubernetes resources. A single chart might be used to deploy something simple, like a nginx pod, or something complex, like a full web app stack with HTTP servers, databases, caches, and so on.

If you want to download and look at the files for a published chart, without installing it, you can do so with helm pull chartrepo/chartname

Helm charts are structured like this, to get more check Charts Guide.

mychart/
  Chart.yaml
  values.yaml
  charts/
  templates/
  ...

The templates/ directory is for template files. When Helm evaluates a chart, it will send all of the files in the templates/ directory through the template rendering engine. It then collects the results of those templates and sends them on to Kubernetes.

The values.yaml file is also important to templates. This file contains the default values for a chart. These values may be overridden by users during helm install or helm upgrade

The Chart.yaml file contains a description of the chart.

Time to start

Set team namespace as default namespace

$ kubectl config set-context $(kubectl config current-context) --namespace=<team_name>; 
i.e kubectl config set-context $(kubectl config current-context) --namespace=ethanhunt 

Initializing a helm chart directory

We can initialize the helm chart directory by command:

$ helm create gowebapp
$ brew install tree
$ tree gowebapp # Check the structure of the generated helm chart directory

## Replacing Kubernetes manifests

In the app directory replace the manifests file by these files

  • gowebapp/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: goweb-app
  labels:
    app.kubernetes.io/name: app
    app.kubernetes.io/instance: goweb-app
    app.kubernetes.io/version: "1.16.0"
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: app
      app.kubernetes.io/instance: goweb-app
  template:
    metadata:
      labels:
        app.kubernetes.io/name: app
        app.kubernetes.io/instance: goweb-app
    spec:
      containers:
        - name: goweb-app
          image: "opstreedevops/ot-go-webapp-master:1.0-15"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
  • gowebapp/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: goweb-app
  labels:
    app.kubernetes.io/name: app
    app.kubernetes.io/instance: goweb-app
    app.kubernetes.io/version: "1.16.0"
spec:
  type: ClusterIP
  ports:
    - port: 8080
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app.kubernetes.io/name: app
    app.kubernetes.io/instance: goweb-app
  • gowebapp/templates/ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: goweb-app
  labels:
    app.kubernetes.io/name: app
    app.kubernetes.io/instance: goweb-app
    app.kubernetes.io/version: "1.16.0"
spec:
  rules:
    - host: "<your_team_name>.com"
      http:
        paths:
          - path: /
            backend:
              serviceName: goweb-app
              servicePort: 8080

Please ensure that you replace your_team_name Once the files are replaced, remove the extra files

$ rm -rf gowebapp/templates/tests
$ rm -rf gowebapp/templates/serviceaccount.yaml
$ rm -rf gowebapp/templates/NOTES.txt
$ rm -rf gowebapp/templates/_helpers.tpl
$ rm -rf gowebapp/templates/hpa.yaml

Deploying the created helm chart

We can deploy the locally created helm chart by:-

$ helm install goweb-app gowebapp

Verify the deployment by:-

$ helm ls 
$ kubectl get pods 
$ kubectl get ingress 

To check on web enter the details in /etc/hosts file depicting hostname and IP Address:-

91.211.152.138 ethanhunt.com

But you might not see the Web UI here as it depends on the database which is not letting UI come Up. This issue will be resolved in the coming Lab.