devops-exercises/exercises/kubernetes/solutions/replicaset_01_solution.md
abregman 891c9c69fe Add a couple of Kubernetes questions and exercises
In addition, changed the order of some Linux questions.
2021-09-05 01:00:35 +03:00

1.1 KiB

ReplicaSet 01 - Solution

  1. Create a ReplicaSet with 2 replicas. The app can be anything.
cat >> rs.yaml <<EOL
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: web
  labels:
    app: somewebapp
    type: web
spec:
  replicas: 2
  selector:
    matchLabels:
      type: web
  template:
    metadata:
      labels:
        type: web
    spec:
      containers:
      - name: httpd
        image: registry.redhat.io/rhscl/httpd-24-rhel7
EOL

kubectl apply -f rs.yaml
  1. Verify a ReplicaSet was created and there are 2 replicas
kubectl get rs
# OR a more specific way: kubectl get -f rs.yaml
  1. Delete one of the Pods the ReplicaSet has created
kubectl delete po <POD_NAME>
  1. If you'll list all the Pods now, what will you see?
The same number of Pods. Since we defined 2 replicas, the ReplicaSet will make sure to create another Pod that will replace the one you've deleted.
  1. Remove the ReplicaSet you've created
kubectl delete -f rs.yaml
  1. Verify you've deleted the ReplicaSet
kubectl get rs
# OR a more specific way: kubectl get -f rs.yaml