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/v1kind: ReplicaSetmetadata: name: frontend labels: app: guestbook tier: frontendspec: replicas: 3 selector: matchLabels: app: guestbook template: metadata: labels: app: guestbook spec: containers: - name: php-redis image: gcr.io/google_samples/gb-frontend:v3To create the ReplicaSet:
kubectl create -f redis-rs.yamlCommon commands:
kubectl apply -f redis-rs.yamlkubectl get replicasetskubectl get rskubectl scale rs frontend --replicas=4kubectl get rs frontend -o yamlkubectl get rs frontend -o jsonkubectl describe rs frontendkubectl delete rs frontend