Creating and Managing a Deployment

Objective

After completing this lesson, you will be able to create and manage a deployment

Create and Manage a Deployment

Business Scenario

You want to deploy your developed application to a Kubernetes cluster. You have to define a Deployment manifest and apply it to the cluster.

Live Environment

In this exercise, you will perform the following tasks:

  1. Create a Deployment using Kyma dashboard.
  2. Update and apply the Deployment manifest.
  3. Scale the Deployment.
  4. Roll back the 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.

Task 1: Create a Deployment using Kyma dashboard

Steps

  1. In Kyma dashboard, go to the default namespace.

  2. Go to Workloads → Deployments and choose the Create button.

    Deployments in Kyma dashboard
  3. Specify the Deployment's name and the container's image. Use the following data:

    FieldValue
    Namehello-kyma
    Docker imageghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:1.0.0
    Create Deployment
  4. To review your Deployment manifest, choose the YAML tab.

    Review YAML
  5. Choose the Create button.

    You're automatically redirected to the Deployment details view. This view includes details about the created Deployment and the associated Pod.

  6. See the details of the created Deployment. Scroll down to the Resource Graph section to observe the created Deployment and the managed ReplicaSet and Pod.

    Kyma dashboard showing a Deployment named hello-kyma with its associated ReplicaSet and Pod. The Resource Graph section visualizes the relationship between the Deployment, ReplicaSet, and Pod..

Task 2: Update and apply the Deployment manifest using kubectl

Steps

  1. To list all your Deployments, run the following kubectl command:

    Code Snippet
    1
    kubectl get deployments

    You see the Deployment that you have created.

    A terminal screenshot showing the output of the command kubectl get Deployments. It lists a Deployment named hello-kyma with 1 Pod ready, up-to-date, and available, and an age of 33 minutes.
  2. To get the Deployment manifest as YAML, run the following command:

    Code Snippet
    1
    kubectl get deployment hello-kyma -o yaml >> hello-kyma-deployment.yaml

    Note

    In this task, you use kubectl to download the Deployment manifest and edit it locally. Although you can use Kyma dashboard to edit the Deployment manifest, it is highly recommended to apply changes from a persisted file and put all manifests under version control. This is not possible with Kyma dashboard.

  3. Go to your working directory and open the hello-kyma-deployoment.yaml file.

    YAML configuration for a Kubernetes Deployment named hello-kyma with one replica. It specifies rolling update strategy, resource limits, and uses an image from ghcr.io/sap-samples/kyma-runtime-learning-journey.
  4. To update the Deployment to use a new version of the application, change the current container image to the new version and set the change-cause to document the change.

    1. Add the following image in the template.spec.containers.image field: ghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:1.1.0

    2. Add the following annotation in the spec.template.metadata section:

      Code Snippet
      12
      annotations: kubernetes.io/change-cause: Upgrade to new release v1.1.0

    Deployment Upgrade YAML
  5. Save the file.

  6. Apply the updated Deployment manifest.

    Code Snippet
    1
    kubectl apply -f hello-kyma-deployment.yaml
  7. To verify the update in the rollout history, run the following commands:

    Code Snippet
    1
    kubectl rollout history deployment hello-kyma
  8. Verify the updated Deployment in the Workloads → Deployments section of Kyma dashboard.

Task 3: Scale the Deployment Using kubectl

Steps

  1. To scale the Deployment to three replicas, run:

    Code Snippet
    1
    kubectl scale deployment hello-kyma --replicas=3

    Kubernetes creates two additional Pods so that now there are three Pods running.

  2. To verify that the Deployment is scaled successfully, run:

    Code Snippet
    1
    kubectl get deployment hello-kyma
    A terminal screenshot showing the output of the command `kubectl get Deployment hello-kyma`. The Deployment hello-kyma has 1/3 Pods ready, 3 up-to-date, 1 available, and an age of 74 minutes.
  3. To verify it in Kyma dashboard, go to Workloads → Deployments and select the hello-kyma Deployment. Scroll down to the list with Pods.

Task 4: Perform a rollback of the Deployment using kubectl

Imagine that you have deployed a new application version, but it is not working as expected. You can now roll back the Deployment to the previous version.

Steps

  1. To list the rollout history, run:

    Code Snippet
    1
    kubectl rollout history deployment hello-kyma

    You should see two versions of the Deployment.

    The output of the command `kubectl rollout history Deployment hello-kyma`, displaying the revision history of the Deployment hello-kyma with two revisions and their change causes.
  2. Roll back the Deployment by specifying the revision number.

    Code Snippet
    1
    kubectl rollout undo deployment hello-kyma --to-revision=1

    If successful, you see the following output: deployment.apps/hello-kyma rolled back

  3. List the rollout history again to verify the rollback.

    Code Snippet
    1
    kubectl rollout history deployment hello-kyma

    You see if the rollback was successful. Furthermore, the order of the revisions has changed, and it's incremented by one.

    The output of the command `kubectl rollout history Deployment hello-kyma`, displaying the revision history of the Deployment with revisions 2 and 3, and their respective change causes.

Result

Congratulations! You have completed the exercise. You have learned how to create, update, scale, and roll back a Deployment.

Log in to track your progress & complete quizzes