Mega Menu

Saturday, March 07, 2020

Kubernetes ReplicaSet sample yaml


ReplicaSet is a definition to number of replicas of a pod that should exist. ReplicaSet is a replacement for replication controller.
template element in the below yaml file should be similar to the pod definition as to define the type of pod to be created (eg: https://digicommlearner.blogspot.com/2020/03/kubernetes-basic-yaml-file-for-pod.html)

apiVersion, kind, selector --> different elements than that of replication controller.
ReplicaSet uses labels to identify the the pod to be monitored. It matches the label of the pod with the matchLabel element defined under selector element. Labels are hence very important and are used in wide range of such features in Kubernetes.

replicaset.yml

apiVersion: app/v1
kind: ReplicaSet
metadata:
   name: repset
   labels:
        app: myapp
        type: ui
spec:
   template:
        metadata:
          name: myapp-pod1
          labels:
             app: myapp
             type: ui
        spec:
            containers:
                -  name: hello-world
                   image: hello-world
     replicas: 2
     selector:
          matchLabels:
               type: ui


Sample Scripts -
      kubectl create -f replicaset.yml   --> creates replicaset with number of pods as that of replicas in the yml file
     kubectl get replicaset--> lists the replicaset details
     kubectl replace -f replicaset.yml   --> replace with the updated yml file.

To dynamically scale replicas, without updating the yml, scale command can be used -
   kubectl scale --replicas=4 -f replicaset.yml
   kubectl scale --replicas=4 replicaset REPLICASET_NAME  

       eg: kubectl scale --replicas=4 replicaset repset

kubectl delete replicaset repset  --> repset is the name of the replicaset


    

No comments:

Post a Comment