In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to use K8s monitoring data component Pod automation for capacity expansion and HPA". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "how to use K8s monitoring data component Pod automation for capacity expansion and HPA" can help you solve the problem.
Automatic expansion and reduction HPA: the full name is Horizontal Pod Autoscaler
When we installed the K8s cluster, we installed a metrics-server component, which is a monitoring data component that provides HPA and basic resource monitoring capabilities. This is the Pod:
[root@k8s-master01] # kubectl get pod-n kube-system metrics-server-6bf7dcd649-5fhrw 1 Running 2 (3d5h ago) 8d
Through this component, you can see the memory and CPU usage of the node or Pod:
[root@k8s-master01] # kubectl top pod-ANAMESPACE NAME CPU (cores) MEMORY (bytes) default busybox 0m 0Mi kube-system calico-kube-controllers-5dffd5886b-4blh7 3m 18Mi Kube-system calico-node-fvbdq 42m 135Mi kube-system calico-node-g8nqd 52m 73Mi
In addition to simple monitoring functions, you can also use the monitoring data to do some other operations.
For example, we can set a certain value for the resources of Pod. When the use of resources exceeds this value, the system will consider that the Pod is currently under pressure, thus expanding the capacity.
Generally, CPU and custom metrics are used to expand capacity, and the memory is relatively small.
HPA practice:
Note: in order to achieve automatic expansion of HPA, the following conditions need to be met
You must install metrics-server components or other custom versions of metrics-server
The requests parameter must be configured
Cannot expand objects that cannot be scaled, such as DaemonSet
First create a yaml file for nginx:
Kubectl create deployment hpa-nginx-- image=nginx-- dry-run=client-o yaml > hpa-nginx.yaml
Then go to the yaml file to configure: configure in the configuration image. The last three lines of the following code can also be written down if you also want to expand the memory based on memory.
Resources: it means resources.
Requests: it means request. It should mean request for resources.
Spec: containers:-image: nginx name: nginx resources: requests: cpu: 10m
Execute the yaml file to create a copy:
[root@k8s-master01] # kubectl create-f hpa-nginx.yaml deployment.apps/hpa-nginx created
A service port is exposed:
[root@k8s-master01] # kubectl expose deployment hpa-nginx-- port=80 [root@k8s-master01] # kubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEhpa-nginx ClusterIP 10.98.236.134 80/TCP 3m17skubernetes ClusterIP 10.96.0.1 443/TCP 8d
Visit and test: prove that this Pod is ready to use
[root@k8s-master01 ~] # curl 10.98.236.134Welcome to nginxroomhtml {color-scheme: light dark;} body {width: 35em.margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;} Welcome to nginx!
If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.
For online documentation and support please refer tonginx.org.Commercial support is available atnginx.com.
Thank you for using nginx.
Configure the rules for automatic expansion and reduction of Hpa: this command means that when the CPU value of the hpa-nginx Pod reaches 10, the capacity will be expanded automatically, with a minimum of 1 and a maximum of 10.
[root@k8s-master01] # kubectl autoscale deployment hpa-nginx-cpu-percent=10-min=1-max=10horizontalpodautoscaler.autoscaling/hpa-nginx autoscaled
Take a look at the rules of hpa:
[root@k8s-master01 ~] # kubectl get hpaNAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGEhpa-nginx Deployment/hpa-nginx 0% Universe 10% 1 10 1 2m38s
Let's do a loop access to hpa-nginx: observe whether the CPU value of hpa will rise
[root@k8s-master01] # while true; do wget-Q-O-http://10.98.236.134 > / dev/null; done
Observe whether the capacity has been expanded: you can see that the number of copies of hpa-nginx has been automatically expanded.
[root@k8s-master01 ~] # kubectl get hpaNAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGEhpa-nginx Deployment/hpa-nginx 640% 0Mi hpa 10% 1 10 1 7m14s [root@k8s-master01 ~] # kubectl top pod NAME CPU (cores) MEMORY (bytes) busybox 0m 0Mi hpa -nginx-bd88bdd8f-7gdwq 1m 3Mi hpa-nginx-bd88bdd8f-8c6j6 1m 3Mi hpa-nginx-bd88bdd8f-cfcjs 1m 7Mi hpa-nginx-bd88bdd8f-h8vx7 74m 7Mi hpa-nginx-bd88bdd8f-kpgl8 2m 3Mi hpa-nginx-bd88bdd8f-lpf45 1m 3Mi Hpa-nginx-bd88bdd8f-lwc2h 1m 3Mi hpa-nginx-bd88bdd8f-qkgfd 1m 3Mi hpa-nginx-bd88bdd8f-t9fj9 1m 3Mi hpa-nginx-bd88bdd8f-tbrl4 1m 7Mi
Then, stop the access test to see if the copy will automatically scale down to the original; wait a while to find that the copy has returned to the original one. Note that this time may be a little slow, wait a moment, it is not a mistake.
[root@k8s-master01 ~] # kubectl get hpaNAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGEhpa-nginx Deployment/hpa-nginx 2% Running 10% 10 10 11m [root@k8s-master01 ~] # kubectl get podNAME READY STATUS RESTARTS AGEbusybox 1 Running 26 (46m ago) 8dhpa-nginx -bd88bdd8f-h8vx7 1ax 1 Running 027m, this is the end of the introduction on "how to automate the expansion and expansion of HPA, the K8s monitoring data component Pod". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.