Steps to create Replica sets in the Kubernetes

In this blog, we will show you the Steps to create Replica sets in the kubernetes environment.

 

REQUIREMENTS

  • 2 Node Cluster ( 1 Master VM with 2 Nodes)
  • Kubernetes Components

 

INFRASTRUCTURE OVERVIEW

  • We have already installed and configured the 2 Node cluster in our demo environment.

 

PODS OVERVIEW

 

  • Currently, there are four orphan PODS which was created using replication controller.

Steps to create Replica sets in the Kubernetes

 

  • All the POD’s are labeled with app=web env=test.

Steps to create Replica sets in the Kubernetes

 

  • We will show you how to add the orphan pods into a Replica Set.

 

REPLICA SET BENEFITS

Steps to create Replica sets in the Kubernetes

 

CREATING A NEW REPLICA SET

 

  • From the master node, open the default text editor.

Steps to create Replica sets in the Kubernetes

 

  • Add the below script in the YML file.

apiVersion: apps/v1beta2
kind: ReplicaSet
metadata:
    name: rs-web
spec:
    replicas: 4
    selector:
       matchLabels:
          app: web
    template:
       metadata:
          labels:
             app: web
             env: test
       spec:
          containers:
          - name: rs-pod
            image: nginx

Steps to create Replica sets in the Kubernetes

 

  • Save and close the file.

 

  • Use the below command to create a new replica set.

kubectl apply -f rs.yml

Steps to create Replica sets in the Kubernetes

 

  • A new replica set is created successfully.

Steps to create Replica sets in the Kubernetes

 

VERIFYING THE REPLICA SET

 

  • Use the below command to view the list of replica set available in your environment.

kubectl get rs

Steps to create Replica sets in the Kubernetes

 

  • It added the orphan pods into the replica set. Also, it has not created any additional pods for the replica set.

Steps to create Replica sets in the Kubernetes

 

  • We can also describe the replica set using the below command.

Syntax: kubectl describe rs <replica set name>

Example: kubectl describe rs rs-web

Steps to create Replica sets in the Kubernetes

 

  • There are more expressions available for the replica set and will share that information in the future blogs.

 

Thanks for reading this blog. We hope it was useful for you to learn to create your first replica set in the kubernetes environment.



Author: Loges
Logeswaran holds Microsoft certified engineer & solution architect certifications with over 11+ years of experience in the fields of hosting technologies and IMS/Cloud consulting. At AssistanZ, Logeswaran spearheads the strategic planning and execution of the company’s Microsoft based core technologies to Enterprise clients.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.