Difficulty: beginner
Estimated Time: 20-30 minutes

Kubernetes - Deployments

The goal of this Lab is to explain the basics of Kubernetes deployments.

This labs will explain the concept of Kubernetes deployments, examine the structure of a deployment file, walk through simple command-line and file based deployments.

Please email feedback to: [email protected]

Kubernetes Deployments

Step 1 of 3

Kubernetes: Deployments

In ours earlier Pods lab, we explored running pods. Pods are very useful for providing structure to containers, but if a pod fails it will not be restarted.

To remedy this, Kubernetes created an object called a Deployment. Deployments are specifications for running one or more pods, and methods to keep them running.

To run a Kubernetes deployment from the command-line:

kubectl run nginx --image=nginx --port 80

Congrats, you have just created your first pod deployment. The run command automatically performed a few things for you:

  • it searched for a suitable node to run the pod
  • it scheduled the pod to run on that Node
  • it configured the cluster to restart / reschedule the pod when needed

To verify that the command created a deployment:

kubectl get deployments

To see the pods created by the deployment:

kubectl get pods

The magic of Deployments

If a pod that was created by a Deployment should ever crash, the Deployment will automatically restart it. To see this in action, kill the pod directly:

kubectl delete pod $(kubectl get pods --no-headers=true | awk '{print $1;}')

The pod should be deleted successfully. Now wait a moment or two and check the pod again:

kubectl get pods

Notice the the pod is running again. This is because the Deployment will restart a pod when it fails.

To completely delete the pod and running containers, you must delete the Deployment:

kubectl delete deployment nginx