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:
- Create a Deployment using Kyma dashboard.
- Update and apply the Deployment manifest.
- Scale the Deployment.
- 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
In Kyma dashboard, go to the default namespace.
Go to Workloads → Deployments and choose the Create button.
Specify the Deployment's name and the container's image. Use the following data:
Field Value Name hello-kyma Docker image ghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:1.0.0 To review your Deployment manifest, choose the YAML tab.
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.
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.
Task 2: Update and apply the Deployment manifest using kubectl
Steps
To list all your Deployments, run the following kubectl command:
Code Snippet1kubectl get deploymentsYou see the Deployment that you have created.
To get the Deployment manifest as YAML, run the following command:
Code Snippet1kubectl get deployment hello-kyma -o yaml >> hello-kyma-deployment.yamlNote
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.
Go to your working directory and open the hello-kyma-deployoment.yaml file.
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.
Add the following image in the template.spec.containers.image field: ghcr.io/sap-samples/kyma-runtime-learning-journey/hello-kyma:1.1.0
Add the following annotation in the spec.template.metadata section:
Code Snippet12annotations: kubernetes.io/change-cause: Upgrade to new release v1.1.0
Save the file.
Apply the updated Deployment manifest.
Code Snippet1kubectl apply -f hello-kyma-deployment.yamlTo verify the update in the rollout history, run the following commands:
Code Snippet1kubectl rollout history deployment hello-kymaVerify the updated Deployment in the Workloads → Deployments section of Kyma dashboard.
Task 3: Scale the Deployment Using kubectl
Steps
To scale the Deployment to three replicas, run:
Code Snippet1kubectl scale deployment hello-kyma --replicas=3Kubernetes creates two additional Pods so that now there are three Pods running.
To verify that the Deployment is scaled successfully, run:
Code Snippet1kubectl get deployment hello-kymaTo 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
To list the rollout history, run:
Code Snippet1kubectl rollout history deployment hello-kymaYou should see two versions of the Deployment.
Roll back the Deployment by specifying the revision number.
Code Snippet1kubectl rollout undo deployment hello-kyma --to-revision=1If successful, you see the following output: deployment.apps/hello-kyma rolled back
List the rollout history again to verify the rollback.
Code Snippet1kubectl rollout history deployment hello-kymaYou see if the rollback was successful. Furthermore, the order of the revisions has changed, and it's incremented by one.
Result
Congratulations! You have completed the exercise. You have learned how to create, update, scale, and roll back a Deployment.