CodeBlanks Logo Icon CodeBlanks

ReplicaSet YAML

Learn the ReplicaSet YAML structure.

ReplicaSet YAML

The ReplicaSet YAML is very similar to the Deployment's; only kind differs and there's no strategy field:

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: api:1.0

ReplicationController

In old sources you may see ReplicationController (rc); it's the ReplicaSet's predecessor and supports only equality-based selectors. It isn't used in new configurations:

# old
kind: ReplicationController
spec:
  selector:
    app: api
# new
kind: ReplicaSet
spec:
  selector:
    matchLabels:
      app: api

Practice ReplicaSet YAML

Write a ReplicaSet YAML: name api, replicas: 3; selector and template label app: api; container named api, image api:1.0.

Starter code

terminal
# buraya yaz

Sample solution

terminal
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: api:1.0

Expected output

replicaset.apps/api created

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the ReplicaSet's apiVersion?

  • batch/v1
  • replicaset/v1
  • apps/v1 Correct answer
  • v1

Explanation: Deployment, ReplicaSet, StatefulSet and DaemonSet are in the apps group.

2 Write the object type.

Question
apiVersion: apps/v1
kind: ____
Answer
apiVersion: apps/v1
kind: ReplicaSet

Explanation: Type names are case-sensitive.

3 Match.

Term Meaning
ReplicaSet apps/v1
ReplicationController Old predecessor
matchLabels Label matching
template Pod mould

All lessons in Intermediate