Exercise Kubernetes Deployment

Table of Contents

1. Introduction

In this lab exercise, we'll cover essential Kubernetes deployment tasks. You'll create a deployment, verify its details, scale the number of pods, upgrade the application image, and finally, delete the deployment.

2. Imperative vs. Declarative

  • Imperative: Directly create, update, or delete resources using commands.

  • Declarative: Describe desired resource states using configuration files (YAML) and apply them.

3. Creating the Deployment

3.1 Declarative Method

  1. Create a YAML specification for the deployment:

    • Name: my-deployment

    • Container: my-container with image nginx:1.14.2

    • Number of replicas: 3

  2. Create a file named deployment.yaml:

Add the following content to deployment.yaml:

(Note: This file describes the desired state of your application.)

References

3.2 Imperative Method

Alternatively, you can create the same deployment imperatively using the following command:

This command directly creates the deployment.

(Note: This command may fail since the deployment named my-deployment already exist. Either change the name of the deployment or delete the existing deployment then recreate it with Imperative Method.) (To delete deployment refer the session ## 6. Deleting Deployment)Deleting Deployment

4. Verifying Deployment

4.1 Get Deployment Details

  • To list all deployments:

  • To describe a specific deployment (e.g., "my-deployment"):

4.2 ReplicaSet and Pods

  • A deployment automatically creates a ReplicaSet, which manages identical Pods.

  • To view ReplicaSets:

  • To see Pods under a specific deployment:

5. Scaling and Upgrading

5.1 Scale Pods

  • To scale the number of Pods in a deployment (e.g., "my-deployment") to 5:

5.2 Rollout Status

  • To verify the rollout status:

5.3 Upgrade Image Version

  1. Update the image version in your deployment YAML file.

  2. Apply the changes:

    (Note: Image upgrades will be explained in the next exercise.)

5.4 Scale Down

  • To scale down to 3 replica:

  • To scale down to 1 replica:

6. Deleting Deployment

6.1 Using Imperative Command

  • To delete a deployment (e.g., "my-deployment"):

6.2 Using Definition File

  • To delete the deployment using the definition file (deployment.yaml):

7. References

Last updated