ReplicaSet

Replicaset is same as ReplicationController and came after it. The only different is the spec.selector section and it recreates the already existing pods if they get terminated. In other words, replicaset makes sure the specified number of pods matching by the selector are running.

Following shows the resource yml for replicaset.

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: app-rs
  labels:
    type: router-rs
spec:
  template:
    metadata:
      name: router-pod
      labels:
        type: router
    spec:
      containers:
        - name: nginx
          image: nginx
  replicas: 2
  selector:
    matchLabels:
      type: router

It will make sure that the 2 pods of type router are running.

Replicaset can be created using command,

kubectl create -f replicaset-def.yml

It can be scaled up/down by changing replicas value in yml file and running the command,

kubectl apply -f replicaset-def.yml

# or

kubectl replace -f replicaset-def.yml

Another way to scale up/down by using the commands,

kubectl scale --replicas=4 -f replicaset-def.yml

# or

kubectl scale --replicas=4 -f app-rs

Where app-rs is the name of the replicaset.