Automatic Restarting of Pods inside Replication Controller of Kubernetes Cluster shows how Kubernetes reschedule pods in the cluster if one or more of existing Pods disappear for some reason. This is a common usage pattern and one of the key features of Kubernetes.
Another common usage pattern of Replication Controller is scaling:
The replication controller makes it easy to scale the number of replicas up or down, either manually or by an auto-scaling control agent, by simply updating the replicas field.
This blog will show how a Kubernetes cluster can be easily scaled up and down.
All the code used in this blog is available at kubernetes-java-sample.
Start Replication Controller and Verify
- Start a Replication Controller as:
1234./cluster/kubectl.sh create -f ~/workspaces/kubernetes-java-sample/wildfly-rc.yamlreplicationcontrollers/wildfly-rc - Get status of the Pods:
123456789101112131415./cluster/kubectl.sh get -w poNAME READY STATUS RESTARTS AGENAME READY STATUS RESTARTS AGEwildfly-rc-bgtkg 0/1 Pending 0 1swildfly-rc-l8fqv 0/1 Pending 0 1swildfly-rc-bgtkg 0/1 Pending 0 1swildfly-rc-l8fqv 0/1 Pending 0 1swildfly-rc-bgtkg 0/1 Pending 0 1swildfly-rc-l8fqv 0/1 Pending 0 1swildfly-rc-bgtkg 0/1 Running 0 1mwildfly-rc-l8fqv 0/1 Running 0 1mwildfly-rc-bgtkg 1/1 Running 0 1mwildfly-rc-l8fqv 1/1 Running 0 1mNote down name of the Pods as
wildfly-rc-bgtkg” and
wildfly-rc-bgtkg”.
- Get status of the Replication Controller:
12345./cluster/kubectl.sh get rcCONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICASwildfly-rc wildfly-rc-pod jboss/wildfly name=wildfly 2
If multiple Replication Controllers are running then you can query for this specific one using the label:
12345./cluster/kubectl.sh get rc -l name=wildflyCONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICASwildfly-rc wildfly-rc-pod jboss/wildfly name=wildfly 2
Scaling Kubernetes Cluster Up
Replication Controller allows dynamic scaling up and down of Pods.
- Scale up the number of Pods:
1234./cluster/kubectl.sh scale --replicas=3 rc wildfly-rcscaled - Status of the Pods can be seen in another shell:
123456789101112./cluster/kubectl.sh get -w poNAME READY STATUS RESTARTS AGEwildfly-rc-k6pk2 1/1 Running 0 47swildfly-rc-wez29 1/1 Running 0 47sNAME READY STATUS RESTARTS AGEwildfly-rc-aqaqn 0/1 Pending 0 0swildfly-rc-aqaqn 0/1 Pending 0 0swildfly-rc-aqaqn 0/1 Pending 0 0swildfly-rc-aqaqn 0/1 Running 0 2swildfly-rc-aqaqn 1/1 Running 0 11swildfly-rc-aqaqn
is created.
Scale Kubernetes Cluster Down
- Scale down the number of Pods:
1234./cluster/kubectl.sh scale --replicas=1 rc wildfly-rcscaled - Status of the Pods using
-w
is not correctly updated (#11338). But status of the Pods can be seen correctly as:
12345./cluster/kubectl.sh get poNAME READY STATUS RESTARTS AGEwildfly-rc-k6pk2 1/1 Running 0 9m
Kubernetes dynamically scales the Pods up and down using the scale --replicas
command.
All code used in this blog is available at kubernetes-java-sample.
Enjoy!
This sounds good
but i am not getting it exactly can you help me about this
Are you getting an error message?
kubectl.sh
is the same askubectl
command?Here you will be glad to know that we are having one of the best portal install fonts in windows 10 where all information available will help you increase your knowledge along with providing you exact ways for the same purpose.
Really such a nice post dear.
I am glad to see this brilliant post, all the details are very helpful and useful for us, keep up to good work.
Thanks for this wonderful article and continue sharing more topics like this.