Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Using heapster to realize HPA

2025-04-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Horizontal Pod Autoscaling (Pod horizontal automatic scaling), referred to as HPA. HAP determines whether the number of copies of Pod needs to be adjusted by monitoring and analyzing the load changes of all Pod controlled by RC or Deployment, which is the most basic principle of HPA.

HPA is designed in the kubernetes cluster as a controller,HPA Controller polling once in 30s by default (which can be set by the flag of kube-controller-manager-horizontal-pod-autoscaler-sync-period) to query the resource utilization of Pod in the specified resources (RC or Deployment), and compare it with the values and indicators set at the time of creation, so as to achieve automatic scaling.

HPA can get data from two places:

1. Heapster: only CPU utilization is supported

2. Custom monitoring

Install and configure heapster

Https://github.com/kubernetes-retired/heapster/tree/v1.4.2/deploy/kube-config/influxdb

$docker pull docker.io/zhaoqing/heapster-amd64:1.4.2

$docker pull docker.io/pupudaye/heapster-influxdb-amd64:v1.3.3

1. Install heapster database influxdb

-apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: monitoring-influxdb namespace: kube-systemspec: replicas: 1 template: metadata: labels: task: monitoring k8s-app: influxdb spec: containers:-name: influxdb image: docker.io/pupudaye/heapster-influxdb-amd64:v1.3.3 volumeMounts:-mountPath: / data name: influxdb-storage volumes: -name: influxdb-storage emptyDir: {}-apiVersion: v1kind: Servicemetadata: labels: task: monitoring kubernetes.io/cluster-service: 'true' kubernetes.io/name: monitoring-influxdb name: monitoring-influxdb namespace: kube-systemspec: ports:-port: 8086 targetPort: 8086 selector: k8s-app: influxdb

2. Install heapster

-apiVersion: v1kind: ServiceAccountmetadata: name: heapster namespace: kube-system---kind: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1beta1metadata: name: dongyali-sa2-clusterrolebindingsubjects:- kind: ServiceAccount name: heapster namespace: kube-systemroleRef: kind: ClusterRole name: cluster-admin apiGroup: rbac.authorization.k8s.io---apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: heapster namespace: kube-systemspec: replicas: 1 template: metadata: labels: task: monitoring K8s-app: heapster spec: serviceAccountName: heapster containers:-name: heapster image: docker.io/zhaoqing/heapster-amd64:1.4.2 imagePullPolicy: IfNotPresent command:-/ heapster- source=kubernetes: https://kubernetes.default-sink=influxdb: http://monitoring-influxdb.kube-system.svc:8086---apiVersion: v1kind: Servicemetadata: labels: Task: monitoring kubernetes.io/cluster-service: 'true' kubernetes.io/name: Heapster name: heapster namespace: kube-systemspec: ports:-port: 80 targetPort: 8082 selector: k8s-app: heapster

3. Modify kube-controller-manager.yaml

$cd / etc/kubernetes/manifests/

$vim kube-controller-manager.yaml

Spec: containers:-command:-kube-controller-manager-horizontal-pod-autoscaler-use-rest-clients=false # added

Take effect automatically after modification

4. Create an application pod user test hpa

ApiVersion: apps/v1beta1kind: Deploymentmetadata: name: hpa-nginx-deploy labels: app: nginx-demospec: revisionHistoryLimit: 15 template: metadata: labels: app: nginx spec: containers:-name: nginx image: nginx resources: requests: cpu: 100m ports:-containerPort: 80

5. Create a hpa for the above pod

$kubectl autoscale deployment hpa-nginx-deploy-cpu-percent=10-min=1-max=10

Set the minimum number of pod replicas to 1 and the maximum to 10. HPA will dynamically increase or decrease the number of pod according to the set cpu usage (10%).

$kubectl get hpa

NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS

Hpa-nginx-deploy Deployment/hpa-nginx-deploy 0% Bond 10% 1 10 1

$kubectl get hpa hpa-nginx-deploy-o yaml

$kubectl describe hpa hpa-nginx-deploy

6. Check the changes of hpa by stress test

$kubectl get pod-o wide | grep hpa

Hpa-nginx-deploy-7db6976d9b-p7llf 1/1 Running 0 155m 10.244.2.250 server242.example.com

$kubectl run-I-- tty load-generator-- image=busybox / bin/sh

/ # while true; do wget-Q-O-http://10.244.2.250; done

Check in another terminal.

$kubectl get hpa

$kubectl get deployment hpa-nginx-deploy

$kubectl delete deployments.apps load-generator

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report