Skip to content
thesarfo

Concept

Kubernetes: ReplicaSets

How ReplicaSets keep a fixed number of identical Pods running, with an example manifest and common commands.

views 0

A ReplicaSet ensures that a specific number of identical Pods are always running. It is an improved version of the older ReplicationController, supporting both equality- and set-based label selectors.

ReplicaSets provide high availability by running multiple instances (replicas) of an application. If one Pod fails, the ReplicaSet automatically creates a replacement. Each replica is created from the same Pod template but has a unique name and IP address, and may be scheduled on different worker nodes.

Example YAML manifest:

apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
replicas: 3
selector:
matchLabels:
app: guestbook
template:
metadata:
labels:
app: guestbook
spec:
containers:
- name: php-redis
image: gcr.io/google_samples/gb-frontend:v3

To create the ReplicaSet:

Terminal window
kubectl create -f redis-rs.yaml

Common commands:

Terminal window
kubectl apply -f redis-rs.yaml
kubectl get replicasets
kubectl get rs
kubectl scale rs frontend --replicas=4
kubectl get rs frontend -o yaml
kubectl get rs frontend -o json
kubectl describe rs frontend
kubectl delete rs frontend