K8s Replica Manager
Document Why?
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
spec:
replicas: 3
selector:
app: nginx
template:
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
Document example:
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
# modify replicas according to your case
replicas: 3
selector: # difference between replication controller and replicaSet
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: php-redis
image: us-docker.pkg.dev/google-samples/containers/gke/gb-frontend:v5
There are three ways to scale replicas
# 1.update replicas in the definition yml, then
kubectl replace -f replicaset-definition.yml
# 2
kubectl scale --replicas=6 -f replicaset-definition.yml
# 3 NOTE: this will not update the definition file, hence the setting is not persistent
kubectl scale --replicas=6 [replicaset_name] [pod_name]