▶ ReplicaSet

[Create the ReplicaSet]
$ kubectl apply -f ReplicaSet.yaml
$ kubectl apply -f https://kubernetes.io/examples/controllers/frontend.yaml

[Can then get the current ReplicaSets deployed]
$ kubectl get rs
NAME       DESIRED   CURRENT   READY   AGE
frontend   3         3         3       6s

[Check on the state of the ReplicaSet]
$ kubectl describe rs/frontend
Name:         frontend
Namespace:    default
Selector:     tier=frontend
Labels:       app=guestbook
              tier=frontend
Annotations:  <none>
Replicas:     3 current / 3 desired
Pods Status:  3 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  tier=frontend
  Containers:
   php-redis:
    Image:        us-docker.pkg.dev/google-samples/containers/gke/gb-frontend:v5
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulCreate  13s   replicaset-controller  Created pod: frontend-gbgfx
  Normal  SuccessfulCreate  13s   replicaset-controller  Created pod: frontend-rwz57
  Normal  SuccessfulCreate  13s   replicaset-controller  Created pod: frontend-wkl7w

[Check for the Pods brought up]
$ kubectl get pods
NAME             READY   STATUS    RESTARTS   AGE
frontend-gbgfx   1/1     Running   0          10m
frontend-rwz57   1/1     Running   0          10m
frontend-wkl7w   1/1     Running   0          10m

[Get the yaml of one of the Pods running]
$ kubectl get pods frontend-gbgfx -o yaml


▶ Pod

[Create the Pod]
$ kubectl apply -f Pod.yaml
$ kubectl apply -f https://kubernetes.io/examples/pods/pod-rs.yaml

The new Pods will be acquired by the ReplicaSet, and then immediately terminated as the ReplicaSet would be over its desired count.

[Fetching the Pods]
$ kubectl get pods
NAME             READY   STATUS        RESTARTS   AGE
frontend-b2zdv   1/1     Running       0          10m
frontend-vcmts   1/1     Running       0          10m
frontend-wtsmm   1/1     Running       0          10m
pod1             0/1     Terminating   0          1s
pod2             0/1     Terminating   0          1s

The output shows that the new Pods are either already terminated, or in the process of being terminated.


▶ Re-Create

[Create the Pod first]
$ kubectl apply -f Pod.yaml
$ kubectl apply -f https://kubernetes.io/examples/pods/pod-rs.yaml

[And then create the ReplicaSet]
$ kubectl apply -f ReplicaSet.yaml
$ kubectl apply -f https://kubernetes.io/examples/controllers/frontend.yaml

[Fetching the Pods]
NAME             READY   STATUS    RESTARTS   AGE
frontend-hmmj2   1/1     Running   0          9s
pod1             1/1     Running   0          36s
pod2             1/1     Running   0          36s


▶ ReplicaSet as a Horizontal Pod Autoscaler Target

[Create the HPA]
$ kubectl apply -f HPA.yaml
$ kubectl apply -f https://k8s.io/examples/controllers/hpa-rs.yaml

[Create the Autoscale]
$ kubectl autoscale rs frontend --max=10 --min=3 --cpu-percent=50
