What happens when you run oc scale deployment/frontend --replicas 3 ?
Manual Scaling
Deployment controller then submits the new pod spec to the Kubernetes scheduler which is responsible for selecting an appropriate node to run the new pod on. It considers various factors such as node resource availability, pod affinity and anti-affinity rules, and node labels. Once the scheduler selects a node, it sends a binding request to the API server.
------------------------------------- Horizontal Pod AutoScaler---------------------------------------------
The Kubernetes HorizontalPodAutoscaler, a resourceful and adaptable guardian of workloads, tirelessly monitors the flow of demand, automatically adjusting the number of pods, deployments, and statefulsets to maintain optimal performance. Think of it as an able military general - dispatching reinforcements to meet the growing needs of its troops in response to surging demands and when the demands subside and the number of pods exceeds the specified minimum, the HPA acts as a wise advisor, instructing workloads to scale down, ensuring efficient resource utilization.
Horizontal scaling --> deploy more troops ( quantity ) [ pods ]
vertical scaling --> assign more resources to the already deployed troops ( quality ) [ cpu / memory ]
Now - oc autoscale deployment/ frontend --cpu-percent=50 --min=3 --max=10
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: frontend
spec:
maxReplicas: 10
minReplicas: 3
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: frontend
targetCPUUtilizationPercentage: 50
status:
currentReplicas: 0
desiredReplicas: 0
We are requesting K8s to track my CPU utilisation and when it reaches 50% of usage then come to my aid and dynamically increase pods to handle the surge in demand ( max upto 10 )
And when the utilisation dips , scale down inteliigently until the minimum (3 ) threshold is met.
To know about Scaling policies and behaviour during scale up and scale up , refer the doc :
https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/
Very informative and useful, thank you for sharing @Chetan_Tiwary_ , keep them coming
pleasure @Wasim_Raja
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.