This object can be used to scale the number of Pods horizontally, let's say by giving a minimum and maximum number based on certain conditions such as CPU utilization

This can be used in conjunction with the ReplicaSet object

Let's say we have a replica set with 3 Pod replicas
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get rs
NAME DESIRED CURRENT READY AGE
rs6 3 3 3 8m

Let's say we have a ReplicaSet object by the name 'rs6' which has 3 Pod replicas. We can call this ReplicaSet in our HPA definition or using the autoscale command

Using autoscale command:
This would create an hpa with the same name as replicaset rs6, sets minimum replicas to 5 and maximum 10
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl autoscale rs rs6 --max=10 --min=5
horizontalpodautoscaler.autoscaling/rs6 autoscaled

networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get hpa rs6
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
rs6 ReplicaSet/rs6 /80% 5 10 0 26s

The replica set would now have a minimum of 5 replicas instead of the 3 it had earlier
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get rs
NAME DESIRED CURRENT READY AGE
rs6 5 5 4 3m

Let's delete the HPA that was created earlier
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl delete hpa --all
horizontalpodautoscaler.autoscaling "rs6" deleted
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get hpa
No resources found.

However the replica set still has 5 replicas
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get rs
NAME DESIRED CURRENT READY AGE
rs6 5 5 5 8m

Let apply the replica set definition again
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl apply -f ex6.yml
replicaset.apps/rs6 configured

It should now show 3 replicas as defined in the yaml fine
networkandcode@cloudshell:~ (kubernetes-cka-224606)$ kubectl get rs
NAME DESIRED CURRENT READY AGE
rs6 3 3 3 9m

--end-of-post--