Managing Upgrades and Maintenance in Kubernetes
Draining and Cordoning Nodes
When upgrading worker Nodes, it's crucial to ensure that the Pods running on those Nodes are not affected by the upgrade process. To accomplish this, it's necessary to drain the Nodes before upgrading them.
For example, consider a cluster with two Nodes. Run the following commands to set environment variables for easier reference:
export NODE1=
export NODE2=
Remove any existing taints on the Nodes (created earlier in the previous chapter). For example:
kubectl taint nodes --all no-webapps-
Let's also run a simple Deployment with five replicas to see how draining and cordoning work.
# Create a Deployment
kubectl create \
deployment hello-world \
--image=gcr.io/google-samples/hello-app:1.0
# Scale the Deployment to 5 replicas
kubectl scale \
deployment hello-world \
--replicas=5
If you want to see which Pods are running on each Node, you can use the following command:
kubectl get pods -o wide
With five replicas, there's a high chance that our Pods are running on more than one Node. Let's see which Pods are running on each Node:
# Get Pods running on Node 1
kubectl get pods \
-o wide \
--field-selector spec.nodeName=$NODE1
# Get Pods running on Node 2
kubectl get pods \
-o wide \Cloud-Native Microservices With Kubernetes - 2nd Edition
A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in KubernetesEnroll now to unlock all content and receive all future updates for free.
