-
Scale the number of replicas of your Hello World service by running the following commands:
kubectl get deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE helloworld-service-v1 1 1 1 1 1m
kubectl scale deployment helloworld-service-v1 --replicas=4
kubectl get deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE helloworld-service-v1 4 4 4 4 1m
kubectl get pods NAME READY STATUS RESTARTS AGE helloworld-service-v1-... 1/1 Running 0 1m helloworld-service-v1-... 1/1 Running 0 1m helloworld-service-v1-... 1/1 Running 0 1m helloworld-service-v1-... 1/1 Running 0 2m
-
Try scaling out further.
kubectl scale deployment helloworld-service-v1 --replicas=25
If you look at the pod status, some of the pods will show a Pending
state. That is because we only have four physical nodes, and the underlying infrastructure has run out of capacity to run the containers with the requested resources. And the underlying infrastructure has run out of capacity to run the containers with the requested resources.
-
Pick a pod name that has a
Pending
state to confirm the lack of resources in the detailed status.kubectl describe pod helloworld-service...
-
We can easily spin up another Compute Engine instance to append to the cluster.
gcloud container clusters resize guestbook --size=5 gcloud compute instances list
Open another terminal and run:
kubectl get pods -w -o wide
This will monitor the recovering process.
-
Verify the new instance has joined the Kubernetes cluster, you’ll should be able to see it with this command:
kubectl get nodes kubectl get pods -o wide
-
IMPORTANT! - Scale back the number of replicas before moving on!
kubectl scale deployment helloworld-service-v1 --replicas=2 gcloud container clusters resize guestbook --size=3
Kubernetes will only keep 2 of the Hello World instances and terminate the rest.