Search⌘ K
AI Features

Creating ReplicaSets

Understand how to create and manage ReplicaSets in Kubernetes to maintain the desired number of Pod replicas. This lesson explains key components like apiVersion, selector, and template, enabling you to build scalable and fault-tolerant applications by monitoring and controlling Pod instances effectively.

Definition

Let’s look at a ReplicaSet named go-demo-2.yml based on the Pod we created in the previous chapter:

YAML
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: go-demo-2
spec:
replicas: 2
selector:
matchLabels:
type: backend
service: go-demo-2
template:
metadata:
labels:
type: backend
service: go-demo-2
db: mongo
language: go
spec:
containers:
- name: db
image: mongo:3.3
- name: api
image: vfarcic/go-demo-2
env:
- name: DB
value: localhost
livenessProbe:
httpGet:
path: /demo/hello
port: 8080

Note: The apiVersion, kind, and metadata fields are mandatory with all Kubernetes objects. ReplicaSet is no exception because it’s also a Kubernetes object.

  • Line 1: We specify that the apiVersion is apps/v1.

  • ...