Pages

Sunday, August 16, 2020

Kubernetes ReplicationController

Create multiple instances of the pod using a ReplicationController, which is a master controller that replicates the specified pods, balances them on all the nodes, and reacts if some pod dies to restore the desired state.

forntendmvc_rc.yaml 

--- 
apiVersion: v1
kind: ReplicationController
metadata: 
 name: myapp-rc
spec: 
   replicas: 5  
   selector:    
     app: myapp    
   template:    
     metadata:         
       labels:           
         app: myapp           
         zone: prod           
         version: v1        
     spec:           
       containers:             
         - name:myapp-frontendmvc              
           image: makader/myapp:frontendmvc-v1              
           ports:               
             - containerPort:80
  • In the specification block, indicate the number of replicas for the pod. 
  • The selector label to indicate which pod will be replicated
  • The template with the information about the pod. 
  • The pod definition is the same as the previous script, so if you don’t remove the previous pod, the replication controller will create only four pods. 

kubectl create -f forntendmvc_rc.yml


 

Delete the frontendmvc pod and observe how the replication controller will add a new pod to maintain the desired state of five replicas

kubectl delete pod forntendmvc-pod  


 

No comments:

Post a Comment