Steps to create a Replication Controller using the kubectl command
In this blog, we will show the Steps to create a Replication Controller using the kubectl command in the kubernetes environment.
- 2 Node Cluster ( 1 Master VM with 2 Nodes)
- Kubernetes Components
- We have already installed and configured the 2 Node cluster in our demo environment.
- Please check the URL https://www.assistanz.com/steps-to-install-kubernetes-cluster-manually-using-centos-7/ for more information.
CREATING REPLICATION CONTROLLER USING KUBECTL
- Login to the Master node through putty.
- use the below command, to create replication controller POD.
Syntax: kubectl run <name for the replication controller> --image=<image name> --generator=run/v1
Example: kubectl run web-rc --image=nginx --port=80 --generator=run/v1
- In few seconds, replication controller created successfully.
- You can verify the replication controller through describe command.
kubectl describe replicationcontroller web-rc
- Generator arguments allow you create kubernetes resources using the kubectl command. For more information, Please check this URL https://kubernetes.io/docs/reference/kubectl/conventions/#generators
SCALING UP THE POD REPLICAS
- By default, it will create only one POD if we do not specify the replica set numbers. You can verify it by listing the pods.
kubectl get pods
- Use the below command to increase the replica set.
Syntax: kubectl scale <resource type> <replication controller name> --replicas=<number of required replicas>
Example: kubectl scale replicationcontroller web-rc --replicas=3
- The command executed successfully.
- We can able to see two more pods are in starting status.
- We can find the pods events through describe command.
kubectl describe pods web-rc-t5w6z
- After few seconds, all the pods will be in running status.
SCALING DOWN THE POD REPLICAS
- We can use the same kubectl scale command with less replica set.
kubectl scale replicationcontroller web-rc --replicas=1
- It will scale down to one POD.
- You can see the PODS are terminating using kubectl get pods command.
- After few seconds, you can have only one POD in the replica set.
Thanks for reading this blog. We hope it was useful for you to learn about creating replication set using the kubectl command.