Using Helm to Package and Deploy your Application

Objective

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.

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. 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. Add the following content to the file:

    Code Snippet
    12345
    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.
  3. Create a new file called values.yaml and specify the default configuration values like replicaCount and image.tag. Add the following content to the file:

    Code Snippet
    123
    replicaCount: 1 image: tag: "1.0.0"
  4. Create a new directory called templates and 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. Add the following content to the file:

    Code Snippet
    123456789101112131415161718192021222324
    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%

    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. To perform a dry-run of your Helm chart to see if it is valid, run the following command inside the hello-kyma-chart directory:

    Code Snippet
    1
    helm template hello-kyma .

    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-chart directory:

      Code Snippet
      1
      helm install hello-kyma-helm .

      You should now see the following output:

      Code Snippet
      123456
      NAME: hello-kyma-helm LAST DEPLOYED: Tue Jun 8 11:25:00 2021 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None
    2. To see the Deployment in your cluster, run the following command:

      Code Snippet
      1
      kubectl get deployments

      You should now see the following output:

      Code Snippet
      12
      NAME READY UP-TO-DATE AVAILABLE AGE hello-kyma-helm 1/1 1 1 2m
  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
      1
      helm upgrade hello-kyma-helm .

      You should now see the following output:

      Code Snippet
      1234567
      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
    2. List the Deployments using kubectl:

      Code Snippet
      1
      kubectl get deployments

      You should now see the following output:

      Code Snippet
      12
      NAME READY UP-TO-DATE AVAILABLE AGE hello-kyma-helm 2/2 2 2 4m
  10. View the Helm release in Kyma dashboard.

    1. Open Kyma dashboard in your browser.

    2. Go to Apps → Helm Releases and choose the hello-kyma-helm release.

      The Kyma dashboard with the Helm Releases section selected. It lists a Helm release named hello-kyma-helm with chart hello-kyma-chart, revision 2, version 0.1.0, and status DEPLOYED.

      You should now see the following output:

      The Kyma dashboard with a Helm release named hello-kyma-helm at revision 2, status DEPLOYED. It includes release data such as chart version 0.1.0 and deployment times.

      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, and more.

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