-
Create a new YAML document
replica1.yaml
for 10 replicas of nginx container.apiVersion: apps/v1 kind: ReplicaSet metadata: name: myapp spec: replicas: 10 selector: ## Identify which PODS should be part of this Set matchLabels: name: myapp template: # Begining of POD Template metadata: ## define name of POD (Must MATCH with Line# 10 ) name: myapp labels: name: myapp spec: containers: - image: mahendrshinde/myweb:latest name: web ports: - containerPort: 80
-
Now, use following commands to deploy the replica set on cluster.
$ kubectl apply -f replica1.yaml # list all pods from current replica-set, should return 10 pods $ kubectl get pods -l name=myapp # Scaling from command-line (Imperative ) $ kubectl scale --replicas=3 -f .\replica1.yaml # list all pods from current replica-set, should return 3 running pods # Other pods might be in terminating stage. $ kubectl get pods -l name=myapp
-
Test the declarative option for scaling, open
replica1.yaml
and change line# 11 toreplicas: 5
from originalreplicas: 10
Now, run following command to apply and verify scaling operation.$ kubectl apply -f replica1.yaml # list all pods from current replica-set, should return 5 pods $ kubectl get rs $ kubectl get pods -l name=myapp
-
Clean-up : delete the replica set.
$ kubectl delete -f replica1.yaml # Check if pods are destroyed! $ kubectl get pods -l name=myapp