Skip to content

Latest commit

 

History

History
80 lines (55 loc) · 2.49 KB

README.md

File metadata and controls

80 lines (55 loc) · 2.49 KB

Exercise 4 - Scaling in and out

Scale the number of Hello World service pods

  1. 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
  2. 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.

  1. Pick a pod name that has a Pending state to confirm the lack of resources in the detailed status.

    kubectl describe pod helloworld-service...
    
  2. 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.

  3. 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
    
  4. 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.