Skip to content

Helm_Lab_02 | Basic Chart

Abhishek Dubey edited this page Dec 9, 2020 · 18 revisions

Helm Lab 02 | Basic Chart

Context

In this lab, we will create a helm chart for application deployment.

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

Initializing a helm chart directory

We can initialize the helm chart directory by command:-

helm create app

Check the structure of generated helm chart directory by:-

tree app

app
├── charts
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

Replacing Kubernetes manifests

In the app directory replace the manifests file by these files

  • deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-app
  labels:
    app.kubernetes.io/name: app
    app.kubernetes.io/instance: nginx
    app.kubernetes.io/version: "1.16.0"
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: app
      app.kubernetes.io/instance: nginx
  template:
    metadata:
      labels:
        app.kubernetes.io/name: app
        app.kubernetes.io/instance: nginx
    spec:
      serviceAccountName: nginx-app
      containers:
        - name: app
          image: "nginx:1.16.0"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
  • service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-app
  labels:
    app.kubernetes.io/name: app
    app.kubernetes.io/instance: nginx
    app.kubernetes.io/version: "1.16.0"
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app.kubernetes.io/name: app
    app.kubernetes.io/instance: nginx
  • ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: nginx-app
  labels:
    app.kubernetes.io/name: app
    app.kubernetes.io/instance: nginx
    app.kubernetes.io/version: "1.16.0"
spec:
  rules:
    - host: "<your_team_name>.training.local"
      http:
        paths:
          - path: /
            backend:
              serviceName: nginx-app
              servicePort: 80

Once the files are replaced, remove the extra files

rm -rf app/templates/tests
rm -rf app/templates/serviceaccount.yaml

Deploying the created helm chart

We can deploy the locally created helm chart by:-

helm install nginx ./app/ --namespace <your_team_namespace>

Verify the deployment by:-

helm ls --namespace <your_team_namespace>
kubectl get pods -n <your_team_namespace>
Clone this wiki locally