Understanding the replica set in Kubernetes
What is Replica?
Replica means copy so having exact same copy of a running pod is called as Replica. Where as ReplicaSet is a way to maintain the stable set of replica Pods running at any time. It guarantees the availability of specified number of identical Pods.
How does it work
ReplicaSet is defined with fields having a selector that specifies how to identify Pods It can acquire, a number of replicas indicating how many Pods it should be maintaining and a pod template specifying the data of of new pods which it should be maintaining. When replica-set needs to create a new pod it uses pod template to create a new pod.
ReplicaSet VS ReplicationController
ReplicaSet and Replication Controller both do the same thing. Both of them ensures that a specified number of Pods mentioned in replicas are running at any time. The only difference comes with the usage
of selectors to replicate Pods.ReplicaSet uses Set-Based selectors while Replication Controller use Equity-Based selectors.
See in below examples:
Replication Controller
apiVersion: v1
kind: ReplicationController
metadata:
name: RepCon
spec:
replicas: 3
selector:
app: RepCon
template:
metadata:
name: RepCon
labels:
app: RepCon
spec:
containers:
- name: RepCon
image: RepCon/rc
ports:
- containerPort: 80
Replica-Set
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: RS
tier: frontend
spec:
# modify replicas according to your case
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: redis
image: gcr.io/google_samples/gb-frontend:v3
Save it as ReplicaSet.yaml in current directory and run below command.
kubectl apply -f ReplicaSet.yaml
Now you can check the ReplicaSet with below command:
kubectl get rs
or
kubectl get replicaset
No comments:
Post a Comment