Skip to content

EKS - Horizontal Pod Autoscaling (HPA)

Step-01: Introduction 露

  • What is Horizontal Pod Autoscaling?
  • How HPA Works?
  • How HPA configured?

Image

Step-02: Install Metrics Server 露

# Verify if Metrics Server already Installed
kubectl -n kube-system get deployment/metrics-server

# Install Metrics Server
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml

# Verify
kubectl get deployment metrics-server -n kube-system

Step-03: Review Deploy our Application 露

# Deploy
kubectl apply -f kube-manifests/

# List Pods, Deploy & Service
kubectl get pod,svc,deploy

# Access Application (Only if our Cluster is Public Subnet)
kubectl get nodes -o wide
http://<Worker-Node-Public-IP>:31231

Kubernetes Manifets 露

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hpa-demo-deployment
  labels:
    app: hpa-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hpa-nginx
  template:
    metadata:
      labels:
        app: hpa-nginx
    spec:
      containers:
      - name: hpa-nginx
        image: stacksimplify/kubenginx:1.0.0
        ports:
        - containerPort: 80
        resources:
          requests:
            memory: "128Mi"
            cpu: "100m"
          limits:
            memory: "500Mi"
            cpu: "200m"          
---
apiVersion: v1
kind: Service
metadata:
  name: hpa-demo-service-nginx
  labels:
    app: hpa-nginx
spec:
  type: NodePort
  selector:
    app: hpa-nginx
  ports:
  - port: 80
    targetPort: 80
    nodePort: 3123

Step-04: Create a Horizontal Pod Autoscaler resource for the "hpa-demo-deployment" 露

  • This command creates an autoscaler that targets 50 percent CPU utilization for the deployment, with a minimum of one pod and a maximum of ten pods.
  • When the average CPU load is below 50 percent, the autoscaler tries to reduce the number of pods in the deployment, to a minimum of one.
  • When the load is greater than 50 percent, the autoscaler tries to increase the number of pods in the deployment, up to a maximum of ten
    # Template
    kubectl autoscale deployment <deployment-name> --cpu-percent=50 --min=1 --max=10
    
    # Replace
    kubectl autoscale deployment hpa-demo-deployment --cpu-percent=50 --min=1 --max=10
    
    # Describe HPA
    kubectl describe hpa/hpa-demo-deployment 
    
    # List HPA
    kubectl get horizontalpodautoscaler.autoscaling/hpa-demo-deployment 
    

Step-05: Create the load & Verify how HPA is working 露

# Generate Load
kubectl run --generator=run-pod/v1 apache-bench -i --tty --rm --image=httpd -- ab -n 500000 -c 1000 http://hpa-demo-service-nginx.default.svc.cluster.local/ 

# List all HPA
kubectl get hpa

# List specific HPA
kubectl get hpa hpa-demo-deployment 

# Describe HPA
kubectl describe hpa/hpa-demo-deployment 

# List Pods
kubectl get pods

Step-06: Cooldown / Scaledown 露

  • Default cooldown period is 5 minutes.
  • Once CPU utilization of pods is less than 50%, it will starting terminating pods and will reach to minimum 1 pod as configured.

Step-07: Clean-Up 露

# Delete HPA
kubectl delete hpa hpa-demo-deployment

# Delete Deployment & Service
kubectl delete -f kube-manifests/ 

AWS EKS - Elastic Kubernetes Service - Masterclass 露

Image

Step-08: Imperative vs Declarative for HPA 露

  • From Kubernetes v1.18 onwards, we have a declarative way of defining HPA policies using behavior object in yaml.
  • Support for configurable scaling behavior
  • Starting from v1.18 the v2beta2 API allows scaling behavior to be configured through the HPA behavior field.
  • Behaviors are specified separately for scaling up and down in scaleUp or scaleDown section under the behavior field
    behavior:
      scaleDown:
        stabilizationWindowSeconds: 300
        policies:
        - type: Percent
          value: 100
          periodSeconds: 15
      scaleUp:
        stabilizationWindowSeconds: 0
        policies:
        - type: Percent
          value: 100
          periodSeconds: 15
        - type: Pods
          value: 4
          periodSeconds: 15
        selectPolicy: Max
    
  • Reference: Select V1.18 from top right corner on Kubernetes website for V1.18 documentation
  • https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/

Referencess 露

Metrics Server Releases 露

  • https://github.com/kubernetes-sigs/metrics-server/releases

Horizontal Pod Autoscaling - Scale based on many type of metrics 露

  • https://v1-16.docs.kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/

哆哆女性网智能生辰八字起名362娱乐设计区块链开发网站qq男生个性签名公司内部网站制作家俱 起名姓武怎么起名温州手机网站制作qq头像带字的情侣测算免费命运火龙果的栽培技术 火龙果种植带智起名字专业网络推广营销公司seo综合理财师个性签名六神无主卖家 营销推广占卜起名子wap网站建设公司seo教程成都网站seo网络优化公司优秀的设计网站推荐制作一网站要多少钱男孩名字怎样起好听大安网站优化微信营销推广活动永城市发展视频制作的网站水果店铺起名岳飞死亡之谜淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻不负春光新的一天从800个哈欠开始有个姐真把千机伞做出来了国产伟哥去年销售近13亿充个话费竟沦为间接洗钱工具重庆警方辟谣“男子杀人焚尸”男子给前妻转账 现任妻子起诉要回春分繁花正当时呼北高速交通事故已致14人死亡杨洋拄拐现身医院月嫂回应掌掴婴儿是在赶虫子男孩疑遭霸凌 家长讨说法被踢出群因自嘲式简历走红的教授更新简介网友建议重庆地铁不准乘客携带菜筐清明节放假3天调休1天郑州一火锅店爆改成麻辣烫店19岁小伙救下5人后溺亡 多方发声两大学生合买彩票中奖一人不认账张家界的山上“长”满了韩国人?单亲妈妈陷入热恋 14岁儿子报警#春分立蛋大挑战#青海通报栏杆断裂小学生跌落住进ICU代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了当地回应沈阳致3死车祸车主疑毒驾武汉大学樱花即将进入盛花期张立群任西安交通大学校长为江西彩礼“减负”的“试婚人”网友洛杉矶偶遇贾玲倪萍分享减重40斤方法男孩8年未见母亲被告知被遗忘小米汽车超级工厂正式揭幕周杰伦一审败诉网易特朗普谈“凯特王妃P图照”考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼恒大被罚41.75亿到底怎么缴男子持台球杆殴打2名女店员被抓校方回应护栏损坏小学生课间坠楼外国人感慨凌晨的中国很安全火箭最近9战8胜1负王树国3次鞠躬告别西交大师生房客欠租失踪 房东直发愁萧美琴窜访捷克 外交部回应山西省委原副书记商黎光被逮捕阿根廷将发行1万与2万面值的纸币英国王室又一合照被质疑P图男子被猫抓伤后确诊“猫抓病”

哆哆女性网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化