ReplicaSet YAML Walkthrough

  • A ReplicaSet is a process that runs multiple instances of a Pod and keeps the specified number of Pods constant.
  • Its purpose is to maintain the specified number of Pod instances running in a cluster at any given time.

If you are new to the replica set you can read the replica set blog here

Let’s understand the replica set the YAML file.


  • This refers to the version of Kubernetes.
  • API version consists of two things group name and Version.
  • There are several versions, and several objects are introduced with each version.
  • Some common ones are v1, apps/v1, and extensions/v1beta1.
  • On the right-hand side, you can see the different types of values
  • You can check out the below command for the list of versions.
$ kubectl api-versions


  • This is the type of Kubernetes object. In this case (the example above), we’re creating a ReplicaSet.
  • You can see the other types of objects that we create commonly on the right side here.
  • You can check out the below command for the list of kinds.
$ kubectl api-resources | awk '{print $5}'


  • The metadata houses information that describes the object briefly.
  • The information in the metadata usually contains the name you want to give the object (Replicaset in our case), the labels, and the annotation.
  • name the object is the only mandatory field and the remaining are optional.


In the spec section, we have three fields — replicas, selector, and template

  • label selector to be used to select the pods, a number of replicas of the pod to be created.
  • In the above example, we are running 3 replicas of nginx container.
  • The selector is used to create pods using matchlabels defined in the template field.
  • The template is a pod template that is used by a selector to create a set of pods.

Now, we can use two types of selectors in replicaset (Equality/Set)

Equality based Selectors (matchLabels)

  • Equality based selectors allow filtering by label keys and values.
  • Three operators used in set based equality based selectors are = , == , !=. The first two represent equality (and are simply synonyms), while the latter represents inequality.
  • For example, if we provide the following selectors:
  • Here, we’ll select all resources with key equal to app and value equal to nginx-app.

Set-Based Selectors (matchExpressions)

  • Unlike Equality based, Set-based label selectors allow filtering keys according to a set of values.
  • Three kinds of operators used in set-based selectors are in , notin, exists(only the key identifier).
  • Here, the first selector will select all resources with key equal to app and value equal to nginx-app.
  • The second example selects all resources with key equal to tier and values other than frontend.




DevOps Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

001_Linux Server || Don’t worry if cache is eating up system’s memory.

Use LibreOffice flatpak in your language

what i have been waiting for has come !

How to Deploy your Streamlit app on Heroku

Everything can be engineered.

Product Manager 101 : Role and Responsibility

API automation made easier for a QA engineer

Filter pattern: kobiri’s parser pipeline

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


DevOps Engineer

More from Medium

Kubernetes Replicaset

Learn Kubernetes: Using an init-container


Deploy Kubernetes dashboard with NodePort