Step 1: Scaling a deployment
To list your deployments use the get deployments command: kubectl get deployments
We should have 1 Pod. If not, run the command again. This shows:
The DESIRED state is showing the configured number of replicas
The CURRENT state show how many replicas are running now
The UP-TO-DATE is the number of replicas that were updated to match the desired (configured) state
The AVAILABLE state shows how many replicas are actually AVAILABLE to the users
Next, let’s scale the Deployment to 4 replicas. We’ll use the kubectl scale command, followed by the deployment type, name and desired number of instances:
kubectl scale deployments/kubernetes-bootcamp --replicas=4
To list your Deployments once again, use get deployments:
kubectl get deployments
The change was applied, and we have 4 instances of the application available. Next, let’s check if the number of Pods changed:
kubectl get pods -o wide
There are 4 Pods now, with different IP addresses. The change was registered in the Deployment events log. To check that, use the describe command:
kubectl describe deployments/kubernetes-bootcamp
You can also view in the output of this command that there are 4 replicas now.
Step 2: Load Balancing
Let’s check that the Service is load-balancing the traffic. To find out the exposed IP and Port we can use the describe service as we learned in the previously Module:
kubectl describe services/kubernetes-bootcamp
Create an environment variable called NODE_PORT that has a value as the Node port:
export NODE_PORT= ( k u b e c t l g e t s e r v i c e s / k u b e r n e t e s − b o o t c a m p − o g o − t e m p l a t e = ′ ( i n d e x . s p e c . p o r t s 0 ) . n o d e P o r t ′ ) e c h o N O D E P O R T = (kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}') echo NODE_PORT= (kubectlgetservices/kubernetes−bootcamp−ogo−template=′(index.spec.ports0).nodePort′)echoNODEPORT=NODE_PORT
Next, we’ll do a curl to the exposed IP and port. Execute the command multiple times:
curl ( m i n i k u b e i p ) : (minikube ip): (minikubeip):NODE_PORT
We hit a different Pod with every request. This demonstrates that the load-balancing is working.
Step 3: Scale Down
To scale down the Service to 2 replicas, run again the scale command:
kubectl scale deployments/kubernetes-bootcamp --replicas=2
List the Deployments to check if the change was applied with the get deployments command:
kubectl get deployments
The number of replicas decreased to 2. List the number of Pods, with get pods:
kubectl get pods -o wide
This confirms that 2 Pods were terminated.
Performing a Rolling Update
Step 1: Update the version of the app
To list your deployments use the get deployments command: kubectl get deployments
To list the running Pods use the get pods command:
kubectl get pods
To view the current image version of the app, run a describe command against the Pods (look at the Image field):
kubectl describe pods
To update the image of the application to version 2, use the set image command, followed by the deployment name and the new image version:
kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
The command notified the Deployment to use a different image for your app and initiated a rolling update. Check the status of the new Pods, and view the old one terminating with the get pods command:
kubectl get pods
Step 2: Verify an update
First, let’s check that the App is running. To find out the exposed IP and Port we can use describe service:
kubectl describe services/kubernetes-bootcamp
Create an environment variable called NODE_PORT that has the value of the Node port assigned:
export NODE_PORT= ( k u b e c t l g e t s e r v i c e s / k u b e r n e t e s − b o o t c a m p − o g o − t e m p l a t e = ′ ( i n d e x . s p e c . p o r t s 0 ) . n o d e P o r t ′ ) e c h o N O D E P O R T = (kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}') echo NODE_PORT= (kubectlgetservices/kubernetes−bootcamp−ogo−template=′(index.spec.ports0).nodePort′)echoNODEPORT=NODE_PORT
Next, we’ll do a curl to the the exposed IP and port:
curl ( m i n i k u b e i p ) : (minikube ip): (minikubeip):NODE_PORT
We hit a different Pod with every request and we see that all Pods are running the latest version (v2).
The update can be confirmed also by running a rollout status command:
kubectl rollout status deployments/kubernetes-bootcamp
To view the current image version of the app, run a describe command against the Pods:
kubectl describe pods
We run now version 2 of the app (look at the Image field)