Advanced Kubernetes Deployment Exercise

Table of Contents

1. Introduction

In this Kubernetes deployment exercise, let us learn to update deployments, event monitoring, and perform rollbacks.

2. Creating a Deployment

2.1 Using the Command Line

To create a deployment using the command line, run the following command:

2.2 Using a YAML Definition File

Alternatively, create the same deployment using the following YAML definition file (my-deployment.yaml):

Apply the deployment using:

3. Verifying Deployment

3.1 Deployment Details

Check the status of the deployment:

Observe the number of replicas in the current and new ReplicaSets.

3.2 Scaling Events

Watch the events related to the deployment while updating the image:

You'll see events indicating the rolling update process.

4. Updating a Deployment

We'll explore three methods for updating deployments:

4.1 Using kubectl set image

We can use the kubectl set image command to update the image of the nginx deployment. For example, to update the nginx container image to version 1.23, run the following command:

4.2 Using kubectl edit deployment

  1. Open the Deployment YAML File:

    • Use the following command to open the YAML configuration of the deployment in your default editor:

    • This command will open the deployment configuration for my-deployment.

  2. Make Changes:

    • Navigate to the spec.template.spec.containers section.

    • Update the image version or any other desired fields.

    • Save the file and exit the editor.

    • It automatically apply the changes to the configuration. You can watch the changes with the kubectl describe command.

4.3 Editing the YAML file

  1. Open the deployment YAML file for editing:

  2. Make Changes:

    • Navigate to the spec.template.spec.containers section.

    • Update the image version.

    • Save the file and exit the editor.

  1. Apply the Changes:

    • The changes made in the YAML file will be applied to the deployment using the following command:

5. Rolling Back a Deployment

5.1 Check Rollout History

View the rollout history of your deployment:

5.2 Roll Back to Previous Revision

To roll back to a previous revision:

6. Pausing and Resuming a Deployment

Pause a deployment to apply fixes:

Resume the rollout:

7. References

Last updated