Kubernetes - Replication Controllers and Replica Sets đ¯
Replica Sets are newer than Replication Controllers, and are the preferred way to manage Pods đ¤
Description đ
A Replica Set is a set of pods that are managed by a controller. It ensures that the specified number of pods are running at any given time. If a pod fails, the Replica Set will create a new one to replace it.
Why use Replica Sets đ
They enable users to monitor pods, by labeling pods it will allow replica set to know which pods to monitor and provides a method to filter out pods thats are not part of the replica set.
Basic Commands đ
-
get list of
replica setskubectl get replicaset -
get descriptive information on the desired
replica setkubectl describe replicaset <replica-set-name> -
edit the specified
replica setkubectl edit replicaset <replica-set-name> -
scale
replica setto the desired number ofreplicaskubectl replace -f <edited-yaml-file>or
kubectl scale --replicas=<new-number-of-replicas> -f <yaml-file> -
delete specified
replica setkubectl delete replicaset <replica-set-name>
Examples đ§Š
-
sample
replication controllerdefinitionapiVersion: v1 kind: ReplicationController metadata: name: myapp-rc labels: app: myapp type: front-end # most crucial for replication controller spec: template: # pod template for the replication controller metadata: name: myapp-pod labels: app: myapp type: front-end spec: containers: - name: nginx-container image: nginx replicas: 3 -
sample
replica setdefinitionapiVersion: apps/v1 kind: ReplicaSet metadata: name: myapp-rs labels: app: myapp type: front-end spec: template: metadata: name: myapp-pod labels: app: myapp type: front-end spec: containers: - name: nginx-container image: nginx replicas: 3 # one of the major differences between replica controller and replica set selector: matchLabels: type: front-end