Wednesday, August 17, 2022

Autoscaling in Kubernetes

Kubernetes pod autoscaler using custom metrics – Sysdig 

Autoscaling in Kubernetes:

ReplicaSet works with a set number of pods.

Horizontal Pod Autoscaler(HPA) enables scaling up and down as needed

Can configure based on desired state of CPU, memory etc.

 

Horizontal Pod Autoscaler, or HPA, enables the application to increase the number of  pods based           on traffic.

 

The master node will periodically check pod metrics and scale to meet the desired state by updating   the replicas field of the scaled resource, such as ReplicaSets or deployment. 

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
labels:
name: nginx-deployment
annotations:
kubernetes.io/change-cause: "custom message"
spec:
replicas: 5
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

$ kubectl apply -f deployment.yaml

$ kubectl get all



$ kubectl get hpa  

$ kubectl autoscale deploy nginx-deployment  --min=2  --max=5 --cpu-percent=10

"cpu-percent" is the trigger to create new pods.  This tells the system, “If the CPU usage hits 10% across the cluster, create a new  pod.”


 


 

A Horizontal Pod Autoscaler is created behind the scenes to manage the  autoscaling feature of the deployment.

 

 

 

 

 

 

 

 

 

 

0 comments:

Post a Comment