the base of kuberneters is to scale your infra easily and dynimacly with a horizontal approch
if you want to scale manually a deployment or a replicas you can update the yaml and apply it or use the command kubectl scale or if you want to scale the limit of cpu and ram same way with command or in the file like
THATS FUCKING BORING
here we can use the HPA this auto scale/unscale our metric pods and balances thresh old
for the rest of the page we use this exemple
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: nginx:latest
ressources:
requests:
cpu: "250"
limits:
cpu: "500"
here this command say that if the pourcentage of the cpu is more than 50% we scale up and if its less we scale down the number of pods beetwen 1 and 10
THATS FUCKING CRAZY
kubectl autoscale deployment my-app --cpu-percent=50 --min=1 --max=10
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: my-app-hpa
spec:
scaleTargetRef:
apiversion: apps/v1
kind: Deployment
name: my-app
minReplicas: 2
maxReplicas: 5
metrics
- type: Ressource
ressource:
name: cpu
target:
type: Utilization
averageUtilization: 50
you can base the metric from custom adapter or External Adapter
kubectl get hpa
kubectl autoscale deployment my-app --cpu-percent=50 --min=1 --max=10 #base on cpu usage
kubectl delete hpa my-app
vertical scalling is change the limitation and the requirement of a pod deployements or replica
just retake our exemple with some change look line 20 but this is not automatic so FUCK OFF
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: nginx:latest
ressources:
requests:
cpu: "1"
limits:
cpu: "500"
we need to create a YAML file GG youre in kub so do yaml file for automatization stop running command
the VPA consist on multiple component de
apiVersion: autoscalling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: my-app-vpa
spec:
targetRef:
apiversion: apps/v1
kind: Deployment
name: my-app #here the name of you deployment
updatePolicy:
updateMode: "Auto"
ressourcePolicy:
containerName:
- containerPolicies: "my-app"
minAllowed:
cpu: "250m
maxAllowed:
cpu: "2"
controlledRessources: ["cpu"]
for line 11
Mode | Description |
---|---|
Off | Only Recommends. Does not change anything |
Initial | Only Changes on pod creation not later so VPA updater does not work |
Recreate | Evicts pods if usage goes beyond range |
Auto | Update existing pods to recommanded |