ReplicaSets - Sandeep-K-Khandelwal/CKAD GitHub Wiki
ReplicationController and ReplicaSet monitor the PODs in the cluster and make sure the desired number of PODs are always up and running. ReplicationController and ReplicaSet spin up a new POD if one of the existing POD terminates and make sure the desired number of PODs are always running.
ReplicationController is an older technology while ReplicaSet is a new one. They both do the same task with a minimal difference.
ReplicationController
kubectl create -f rc-definition.yml
- Create Replication controller based on the definition filekubectl get replicationcontrollers
- Get the list of Replication controllerskubectl delete replicationcontroller <replication_controller_name>
- Delete the specified Replication controller. It also delete the underlying Podskubectl describe replicationcontroller <replication_controller_name>
- Get details about the specified Replication controller
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc
labels:
app: myapp
type: frontend
spec:
replicas: 3
template:
metadata:
name: myapp-pod
labels:
app: myap
type: frontend
spec:
containers:
- name: nginx
image: nginx
ReplicaSet - We need to specify selector
for ReplicaSet. The selector
is optional for the ReplicationController
kubectl create -f rs-definition.yml
- Create ReplicaSet based on the definition filekubectl get replicasets
- Get the list of ReplicaSetskubectl delete replicaset <replication_controller_name>
- Delete the specified ReplicaSet. It also deletes the underlying Podskubectl describe replicaset <replication_controller_name>
- Get details about the specified ReplicaSet
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
type: frontend
spec:
replicas: 3
selector:
matchLabels:
type: frontend
template:
metadata:
labels:
type: frontend
app: myapp
spec:
containers:
- name: nginx
image: nginx
Scale ReplicaSet -
- Update the definition file used to create the ReplicaSet earlier and use the command -
kubectl apply -f <rs-definition.yml>
kubectl scale --replicas=<new number of relicas> -f <rs-definition.yml>
kubectl scale --replicas=<new number of relicas> replicaset <replica_set_name>