On the road again

The article provides with basic commands and examples to manage ReplicaSets

ReplicaSet - runs N replicas of pod of a certain type and monitors the amount of running pods to be consequent with amount defined in manifest.
It’s important to understand that ReplicaSets and Pods are loosely coupled. The only thing a Pod needs, for it to be managed by a ReplicaSet, is to match the label selector of the ReplicaSet.
 
Example yam (for k8s newer than 1.8, tested on 1.13l:
apiVersion: apps/v1beta2
kind: ReplicaSet
metadata:
  name: web-rs
spec:
  replicas: 2
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-ctr
        image: <some_docker_image>
        ports:
        - containerPort: 8080
 
Create ReplicaSet:
sudo kubectl create -f ./replicaset.yml
 
Inspect ReplicaSet:
kubectl get rs/web-rs
kubectl get rs web-rs --output=yaml
kubectl describe rs/web-rs
 
View labels:
kubectl get pods --show-labels
 
Delete ReplicaSet without its pod(s):
kubectl delete rs/web-rs --cascade=false
Add comment