Using Helm to Package and Deploy your Application

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Use Helm to package and deploy your application

Use Helm to Deploy and Manage Deployments

Business Scenario

Using different manifests, you manually deployed your application with all corresponding Kubernetes objects to a Kubernetes cluster. Now you want to use Helm to package your deployment manifest and deploy it via Helm to your cluster.

Exercise Options

You can perform this exercise in two ways:

  1. Platform Simulation – follow the step-by-step instructions within the simulation.
  2. Live Environment - by using the instructions provided below, you can perform the steps in the SAP BTP Free Tier account.
Note

We are strongly recommending first performing the steps in the Live Environment.

Platform Simulation

Choose the Start Exercise button below to open a simulation of the platform. Then follow the step-by-step instructions to deploy and manage deployments using Helm.

Live Environment

In this exercise, you will create, customize and deploy a Helm chart for a deployment.

Prerequisites

  • You have successfully created a SAP BTP, Kyma runtime instance in the SAP BTP subaccount.
  • You have configured kubectl to work with your SAP BTP, Kyma runtime instance.
  • Furthermore, you have installed the Helm CLI on your local machine.

Once you have the Helm CLI installed, you can create a Helm chart for your deployment. The Helm CLI provides a command to create a Helm chart for you. This will create a few sample files for you to get started with. However, in this approach, we will create the Helm chart manually from scratch.

Task 1: Create, customize and deploy a Helm chart for a deployment

Steps

  1. Create a new directory for your Helm chart and change into it. Call it hello-kyma-chart and change into it.

  2. Create a new file called Chart.yaml and specify information about the chart, such as the name, version, description, and so on.

    1. Add the following content to the file:

      Code snippet
      apiVersion: v2
      name: hello-kyma-chart
      description: A Helm chart for the Hello Kyma example application
      type: application # A chart can be either an 'application' or a 'library' chart.
      version: 0.1.0 # This is the chart version.
      Copy code
  3. Create a new file called values.yamland specify the default configuration values like replicaCount and image.tag

    1. Add the following content to the file:

      Code snippet
      replicaCount: 1
      
      image:
        tag: "1.0.0"
      Copy code
  4. Create a new directory called templatesand change into it.

    In this directory, you can add all the templates for your Helm chart. For now, we will only add a template for the deployment.

  5. Create a new file called deployment.yaml and specify the Kubernetes deployment's definition and use your configuration values.

    1. Add the following content to the file:

      Code snippet
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: {{ .Release.Name }}
      spec:
        replicas: {{ .Values.replicaCount }} 
        selector:
          matchLabels:
            app: {{ .Release.Name }}
        template:
          metadata: 
            labels: 
              app: {{ .Release.Name }}
          spec:
            containers: 
              - name: hello-kyma
                image: ghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:{{ .Values.image.tag }}
                ports:
                  - containerPort: 8080 
        strategy:
          type: RollingUpdate
          rollingUpdate:
            maxSurge: 25%
            maxUnavailable: 25%
      Copy code
      Hint

      Take advantage of the {{ .Release.Name }} and {{ .Values.replicaCount }} placeholders to make use of the configuration values that you specified in the values.yaml file. The {{ Release.Name }} placeholder will be replaced with the name of the Helm release. The {{ .Chart.AppVersion }} placeholder will be replaced with the version of the application that you specified in the Chart.yaml file.

  6. Perform a dry-run of your Helm chart to see if it is valid.

    1. Run the following command inside the hello-kyma-chartdirectory:

      Code snippet
      helm template hello-kyma .
      Copy code
    2. You should now see a rendered output of your Helm chart.

  7. Install the Helm chart in your cluster.

    1. Run the following command inside the hello-kyma-chartdirectory:

      Code snippet
      helm install hello-kyma-helm .
      Copy code
    2. You should now see the following output:

      Code snippet
      NAME: hello-kyma-helm
      LAST DEPLOYED: Tue Jun 8 11:25:00 2021
      NAMESPACE: default
      STATUS: deployed
      REVISION: 1
      TEST SUITE: None
      Copy code
    3. You can now see the deployment in your cluster:

      Code snippet
      kubectl get deployments
      Copy code
    4. You should now see the following output:

      Code snippet
      NAME     READY   UP-TO-DATE   AVAILABLE   AGE
      hello-kyma-helm     1/1     1           1           2m
      Copy code
  8. Update the values.yaml file and change the replicaCount to 2.

  9. Update the Helm chart in your cluster.

    1. Run the following command inside the hello-kyma-chart directory:

      Code snippet
      helm upgrade hello-kyma-helm .
      Copy code
    2. You should now see the following output:

      Code snippet
      Release "hello-kyma-helm" has been upgraded. Happy Helming!
      NAME: hello-kyma-helm
      LAST DEPLOYED: Tue Jun 8 11:25:00 2021
      NAMESPACE: default
      STATUS: deployed
      REVISION: 2
      TEST SUITE: None
      Copy code
    3. List the deployment with kubectl:

      Code snippet
      kubectl get deployments
      Copy code
    4. You should now see the following output:

      Code snippet
      NAME   READY   UP-TO-DATE   AVAILABLE   AGE
      hello-kyma-helm   2/2     2           2            4m
      Copy code
  10. View the Helm release in the Kyma Dashboard.

    1. Open the Kyma Dashboard in your browser.

    2. Navigate to the Apps menu item and select Helm Releases. And click the hello-kyma-helm release.

    3. You should now see the following output:

      Note

      Once you discover other Kubernetes objects later in this course, you will be able, for example, to extend your helm chart with other manifests for services, ingresses etc.

Result

You have successfully created a Helm chart for your deployment and deployed it to your cluster.

Log in to track your progress & complete quizzes