A ReplicaSet's purpose is to maintain a stable set of replica Pods running at any given time. As such, it is often used to guarantee the availability of a specified number of identical Pods.
ReplicaSet Definaition
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
# modify replicas according to your case
replicas: 3
// template content from the pod definition file
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google_samples/gb-frontend:v3
kubectl create -f replicaset.yaml
ReplicaSet Controller definition contains the same things as that of Replicaset the difference is in the definition of apiVersion and the selector tag. A selector tag is necessary for the replica set and optional for the replica set controller.
Replica set controller
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc
labels:
app: myapp
type: frontend
spec:
# modify replicas according to your case
replicas: 3
//optional selector
selector:
matchLabels:
type: frontend
//template from app definition
template:
metadata:
labels:
type: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google_samples/gb-frontend:v3
kubectl get replicaset
Replica set monitors pods and the label is used to help it monitor the concerned pods only.
Scale replicaSet
- by updating replica set definition
kubectl replace -f replicaset-definition.yml - Using scale command
kubectl scale --replcas=6 -f replicaset-definition.yml - Using scale command with type and replica set name
kubectl scale --replicas=6 replicaset myapp-replicaset
kubectl edit replicaset existing replicaset
more info https://blog.learncodeonline.in/kubernetes-core-concepts-replicasets-and-replication-controllers