Replicaset Link to heading
Replicasets are a fun topic…this new object replaces the old “Replication Controller”. Replicaset (shortname “rs”) can control pods that are not created within the replicaset or other deployment by simply matching labels.
Details Link to heading
- a single pod crashes then loses access to app - idea to have more than one instance of a pod
- another reason - to create multiple pods to share the load and balance
- spans across multiple nodes
- scales when demand increases
Setup Link to heading
- create YAML
- use 4 top level objects - api/kind/metadata/spec
- create POD template section under SPEC
- to create POD template MOVE the normal fields: metadata, name, labels and spec…usually defined in POD
- move thos fields under spec.template
ReplicaSet Link to heading
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: my-replicaset
labels:
app: myapp
type: frontend
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
type: frontend
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
type: frontend
- ReplicaSet can handle other pods that haven’t been created under the yaml file
- SELECTOR is the difference for the ReplicaSet
- MUST use selector.matchLabels
Labels and Selectors Link to heading
- use to monitor existing pods is one use case
- role of replicaSet is to monitor and deploy if any fail
- use same label set in “MatchLabels” and it knows which pods
- spec.replicas
- spec.selector.matchLabels.type
Scale Link to heading
- increase REPLICAS
1st method
update number of replica field in definition file
then use REPLACE cmd
kubectl replace -f replica-set.yaml
2nd method
use SCALE cmd
kubectl scale --replicas=6 -f replica-set.yaml
3rd method
also scale cmd
but use resource TYPE and resource NAME fields from definition file in command
kubectl scale --replicas=6 -f replicaset myapp-replicaset
Commands Link to heading
kubectl create -f replica-set.yaml
kubectl get replicaset
kubectl delete replicaset myapp-replicaset
kubectl replace -f replica-set.yaml
kubectl scale -replicas=6 -f replicaset-definition.yaml
k explain replicaset myapp-replicaset