本文主要是介绍k8s-hpa,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、产线当前是基于cpu和memory,当前考虑增加QPS来做HPA
二、指标来源应用容器自身采集、ingress-nginx-controller采集、 外部网关、 外部SLB
三、步骤(测试)
1、使用prometheus采集ingress-controller的指标(其他一样)
2、helm部署prometheus-adapter-3.0.0.tgz
3、配置prometheus-adapter自定义指标
4、check指标函数以及ab测试
1.- seriesQuery: 'nginx_ingress_controller_requests{namespace!="",canary=""}'resources:template: <<.Resource>>name:matches: "^(.*)_requests"as: "http_requests_2m"metricsQuery: 'sum(rate(<<.Series>>{<<.LabelMatchers>>}[2m])) by (<<.GroupBy>>)' 2.
ab -c 10 -n 1000 -k http://ingress01.test.com/
ab -c 10 -n 1000 -k http://ingress03.test.com/3.
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/service/svc-nginx01/http_requests_2m" | jq .
结果:16730m
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/service/svc-nginx03/http_requests_2m" | jq .
结果:6665m
#cat deploy-test.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx01labels: &labelsapp: nginx01service: svc-nginx01
spec:replicas: 1selector:matchLabels: *labelstemplate:metadata:labels: *labelsspec:containers:- name: nginximage: nginx:1.14.2ports:- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:annotations:name: svc-nginx01
spec:type: NodePortselector:app: nginx01ports:- protocol: TCPport: 80targetPort: 80nodePort: 30009
# cat hpa-svc.yaml
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata: name: nginx-01-hpa
spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: nginx01minReplicas: 2maxReplicas: 5metrics:- type: Objectobject:metric:name: http_requests_2mdescribedObject:kind: Servicename: svc-nginx01target:type: Valuevalue: 1000
# cat ingress001.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: ingress001annotations:kubernetes.io/ingress.class: nginx
spec:rules:- host: ingress01.test.comhttp:paths:- path: /pathType: Prefixbackend:service:name: svc-nginx01port: number: 80- host: ingress03.test.comhttp:paths:- path: /pathType: Prefixbackend:service:name: svc-nginx03port:number: 80
这篇关于k8s-hpa的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!