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.

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 create and manage a deployment.

Live Environment

In this exercise, you will perform the following tasks:

  1. Create a deployment via the 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 via the Kyma Dashboard

Steps

  1. Create a deployment via the Kyma Dashboard.

    1. Open the Kyma Dashboard, navigate to the deployments workload view and choose the Create Deployment button.

  2. Specify the deployment name and the container image. Use the following data:

    FieldValue
    Namehello-kyma
    Container imageghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:1.0.0
    1. As name enter hello-kyma, as container image enter ghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:1.0.0

    2. Choose the YAML tab to review your deployment manifest and choose the Create button.

  3. Verify the created deployment.

    After the deployment has been created, it will be automatically redirected to the deployment details view. You can see the deployment details and the pod details.

    1. Scroll down to the Resource Graph to observe the created deployment and its managed ReplicaSet and Pod.

Task 2: Update and apply the deployment manifest via kubectl

Steps

  1. List your deployments.

    1. Use kubectlto list your deployments.

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl get deployments
    2. You should see the deployment you just created.

  2. Get the deployment manifest as YAML and open it.

    Note

    Although you can use the Kyma Dashboard to edit the deployment manifest, we will use kubectlto apply changes from a persisted file because it is highly recommended to put all manifests under version control. This is not possible with the Kyma Dashboard. Therefore, we will use kubectlto download the deployment manifest and edit it locally.

    1. Enter:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl get deployment hello-kyma -o yaml >> hello-kyma-deployoment.yaml
    2. If you open this file, you will see a lot of information in the manifest. Most of them are read-only fields, which the Kubernetes environment automatically sets.

  3. Update the deployment to use a new version of the application.

    1. Change the current container image to the new version and set a change-causeto document the change.

      ghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:1.0.0

      kubernetes.io/change-cause: "Upgrade to new release v1.0.1"

    2. Save the file.

    3. Apply the updated deployment manifest.

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl apply -f hello-kyma-deployment.yaml
    4. Verify the update in the rollout history or with kubectl describe

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl rollout history deployment hello-kyma

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl describe deployment hello-kyma

    5. Verify the updated deployment in the Kyma Dashboard.

Task 3: Scale the deployment via kubectl

Steps

  1. Scale the deployment to three replicas.

    Code Snippet
    Copy code
    Switch to dark mode
    1
    kubectl scale deployment hello-kyma --replicas=3

    1. Use the given command.

  2. Verify it via kubectl.

    Kubernetes will now create the two additional pods.

    Note

    After a short while, there will be three pods running.

  3. Verify it via the Kyma Dashboard.

    1. Navigate to the Deployments workload view and select the hello-kyma deployment. Scroll down to the list with pods.

Task 4: Perform a rollback of the deployment via 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. List the rollout history.

    1. Use:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl rollout history deployment hello-kyma
    2. You should see the two versions of the deployment.

  2. Roll back the deployment by specifying the revision number.

    1. Use:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl rollout undo deployment hello-kyma --to-revision=1
    2. You should see the following output:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      deployment.apps/hello-kyma rolled back
  3. List the rollout history again to verify the rollback.

    1. Use:

      Code Snippet
      Copy code
      Switch to dark mode
      1
      kubectl rollout history deployment hello-kyma
    2. You should see that the rollback was successful. Furthermore, the order of the revisions has changed, and it got incremented by one.

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