Kubernetes ReplicaSets - ReplicationController

We have seen the word 'replicas' in the Docker Swarm services definition time.

How to work with ReplicaSet?

  What does ReplicaSet do?

ReplicaSet will define the group of pods. You can tell how many replicas of pods for your application. The template section will define how many pods and their specification will be defined. Defining ReplicaSet allows you to deploy podand keep it alive as per configuration.


How to create ReplicaSet?

ReplicaSet relationship with Pod

        apiVersion: apps/v1
        kind: ReplicaSet
        metadata:
          name: my-tcat-rs
          labels:
            version: "3.0"
        spec:
          replicas: 2
          selector:
            matchLabels:
              project: MyWeb
              role: frontend
          template:
            metadata:
              labels:
                project: MyWeb
                role: frontend
                env: dev
        
            spec:
              containers:
              - name: mytomcat
                image: tomcat:latest
                resources:
                 requests:
                  cpu: 100m
                  memory: 256Mi
                ports:
                - containerPort: 8080       
	
Create the replicaset using the YAML manifestat file.
kubectl create -f replicasets.yml
  
2. Describe the ReplicaSet
In the spec, section is where the important things happen: we have defined a set of labels for the ReplicaSet, but we have also defined a pod template (in this case, with a single container) and specified that we want two pod instances of it (replicas: 2).
        kubectl -n vybhava describe rs
        # another option to see the replicaset
        kubectl -n vybhava describe replicaset my-tcat-rs
	
3. How to Scale the ReplicaSet?

a. Scale-up ReplicaSet

You can specify the increased number for replicas configuration
        kubectl -n vybhava scale --replicas=6 rs my-tcat-rs
        kubectl -n vybhava get all
	
b. Scale down ReplicaSet

You cna brought down the replicas to 0 as well.
        kubectl -n vybhava scale --replicas=0 rs my-tcat-rs
        kubectl -n vybhava get all
	
4. Print wide output of the ReplicaSet
The regular kubectl command with get sub-command using -o wide option will give more details this we can use with alias name rs as well.
kubectl get rs -o wide or
  kubectl get replicasets -o wide 
Kubernetes replicaset listing with wide output


5. Delete the ReplicaSet

Deleting the ReplicaSet using 'delete' sub-command provide the name of the replicaset.
kubectl -n vybhava delete rs my-tcat-rs
kubectl -n vybhava get rs   
	
6.   
6. How to get the ReplicaSets output to YAML or JSON format?

Hope you guys enjoyed this simple story about ReplicaSet commands and their outputs. Note that The Kubernetes docs explicitly suggest using a deployment rather than a ReplicaSet directly.

References


Comments

Popular posts from this blog

Ansible 11 The uri module with examples

Jenkins Active choices parameter - Dynamic input

DevOps Weapons