/    /  Kubernetes – Replica Sets

Kubernetes – Replica Sets

 

A replica set tells how many replicas of a pod should be running. It’s kind of like a replacement for the replication controller. Replica sets and replication controllers have one thing in common: they only support equality-based selectors, whereas replica sets support set-based selectors.

apiVersion: extensions/v1beta1 --------------------->1
kind: ReplicaSet --------------------------> 2
metadata:
   name: Tomcat-ReplicaSet
spec:
   replicas: 3
   selector:
      matchLables:
         tier: Backend ------------------> 3
      matchExpression:
{ key: tier, operation: In, values: [Backend]} --------------> 4
template:
   metadata:
      lables:
         app: Tomcat-ReplicaSet
         tier: Backend
      labels:
         app: App
         component: redis
   spec:
      containers:
      - name: Tomcat
      image: tomcat: 8.0
      ports:
      - containerPort: 7474

Setup Details

  • apiVersion: extensions/v1beta1 

The API version above is the advanced beta version of Kubernetes that supports replica sets.

  • kind: ReplicaSet 

In order to help kubectl recognize that the file creates a replica set, the kind has been defined as a replica set.

  • tier: Backend 

The label tier is the backend, which creates a matching selector.

  • {key: tier, operation: In, values: [Backend]}  

This will help  matchExpression understand the matching condition we’ve defined and the operation matchlabel uses  to find details.

Run the above file with kubectl and create the backend replica set according to the yaml  file.