Kubernetes_Autoscale
Kubernetes_Autoscale
Michael Robotics
Hi, I'm Michal. I'm a Robotics Engineer and DevOps enthusiast. My mission
is to create skill-learning platform that combats information overload by
adhering to the set of principles: simplify, prioritize, and execute.
https://github.com/MichaelRobotics
https://github.com/MichaelRobotics/DevOpsTools/blob/main/KubernetesAutoscaleP1.pdf
Download PDF
Click there to go to ChatPdf website
Go to website
Browse file
Essential for this PDF is a thorough knowledge of networking. I highly recommend the HTB
platform's networking module, which offers extensive information to help build a
comprehensive understanding.
https://www.hackthebox.com/
What is Kubernetes?
Kubernetes is an open-source platform that automates the deployment, scaling, and
management of containerized applications. It helps manage clusters of nodes running
containers, ensuring efficient and reliable operation.
Kubernetes clusters consist of a control plane and multiple worker nodes. The control plane
manages cluster operations, while worker nodes run the actual container workloads.
System Requirements
RAM: 2 GB per node (1 GB can work for testing but may lead to limited performance)
10 GB free storage
Ubuntu
kube-apiserver: Central management component that exposes the Kubernetes API; acts
etcd: Distributed key-value store for storing all cluster data, ensuring data consistency
across nodes.
policies.
kubelet: Agent that runs on each node, responsible for managing pods and their
containers.
HPA adjusts the number of pods in a depncing performance and cost-efficiency as demand
changes.
Resource Optimization: Scales pods based on actual needs, minimizing waste and costs.
HPA monitors metrics and compares them to set thresholds. When CPU usage exceeds the
target, more pods are added; when it drops below, the pod count is reduced to save
resources.
curl -O https://raw.githubusercontent.com/MichaelRobotics/Kubernetes/main/HPA/metrics-server.yaml
apply
curl -O https://raw.githubusercontent.com/MichaelRobotics/Kubernetes/main/HPA/Deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: php-apache
[...]
apiVersion: v1
kind: Service
metadata:
name: php-apache
labels:
run: php-apache
spec:
ports:
- port: 80
selector:
run: php-apache
apply manifest:
curl -O https://raw.githubusercontent.com/MichaelRobotics/Kubernetes/main/HPA/hpa.yaml
hpa resource:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: php-apache
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: php-apache
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
Configuration scales pods to keep CPU utilization at 50% and memory utilization at 80%, between
1 and 10 replicas.
--cpu-percent=50 \
--memory-percent=80 \
--min=1 \
--max=10
6) Test autoscaler
Autoscaler keept creating new pods until cpu usage stabilized around 50%, as was indicated
in hpa.yml
Kubernetes tool designed to optimize the resource allocation of pods by adjusting their CPU
2) How it works?
VPA analyzes historical and real-time resource usage and makes recommendations or
directly modifies the pod specifications. It has four modes that control its behavior:
Deploy metric server as shown in HPA example. Then get modified deployment (deleted
curl -O https://raw.githubusercontent.com/MichaelRobotics/Kubernetes/main/VPA/Deploy.yaml
apply
./hack/vpa-up.sh
curl -O https://raw.githubusercontent.com/MichaelRobotics/Kubernetes/main/VPA/vpa.yaml
it looks like:
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: php-apache-vpa
spec:
targetRef:
apiVersion: "apps/v1"
kind: Deployment
name: php-apache
updatePolicy:
updateMode: "Auto" # Change to "Off", "Initial", or "Recreate" as needed
Kubernetes Autoscaling: HPA &
VPA for optimal pod 10
performance
2) VPA modes
Off Mode
Purpose: Collects data, recommends resources, but doesn’t change pod configurations.
Initial Mode
Use Case: Optimize resources for new pods without affecting running ones.
Auto Mode
Recreate Mode
Purpose: Updates resources when pods are recreated, not via forced evictions.
apply vpa
After minute, check if vpa calculated optimised resources for pods in deployment:
calculated:
Lower Bound: The minimum necessary resources (25m CPU and 262144k memory) to ensure
Target: The optimal resource values for efficient operation, which in this case are the same
Uncapped Target: The ideal resource allocation, ignoring constraints like resource limits, but
Upper Bound: The maximum resource allocation, also set to the same values, to prevent
over-provisioning.
The Horizontal Pod Autoscaler (HPA) and Vertical Pod Autoscaler (VPA) both adjust
resources in Kubernetes, but they are not designed to work together. HPA scales the number
of pod replicas based on metrics like CPU and memory usage, while VPA adjusts the
Using both autoscalers simultaneously can cause conflicts, as HPA changes the number of
replicas, and VPA alters pod resources, leading to potential issues. Kubernetes may address
Michael Robotics
Hi, I'm Michal. I'm a Robotics Engineer and DevOps enthusiast. My mission
is to create skill-learning platform that combats skill information overload
by adhering to the set of principles: simplify, prioritize, and execute.
https://github.com/MichaelRobotics
https://github.com/piyushsachdeva/CKA-2024/tree/main/Resources/Day27
Kubernetes Documentation
This section lists the different ways to set up and run Kubernetes
https://kubernetes.io/docs/setup/
Michael Robotics
Hi, I'm Michal. I'm a Robotics Engineer and DevOps enthusiast. My mission
is to create skill-learning platform that combats skill information overload
by adhering to the set of principles: simplify, prioritize, and execute.
https://github.com/MichaelRobotics
PS.