一、
   产线当前是基于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: nginx01
  labels: &labels
    app: nginx01
    service: svc-nginx01
spec:
  replicas: 1
  selector:
    matchLabels: *labels
  template:
    metadata:
      labels: *labels
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  annotations:
  name: svc-nginx01
spec:
  type: NodePort
  selector:
    app: nginx01
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 30009
# cat hpa-svc.yaml 
apiVersion: autoscaling/v2beta2 
kind: HorizontalPodAutoscaler
metadata: 
  name: nginx-01-hpa
spec: 
  scaleTargetRef: 
    apiVersion: apps/v1 
    kind: Deployment 
    name: nginx01
  minReplicas: 2
  maxReplicas: 5
  metrics:
  - type: Object
    object:
      metric:
        name: http_requests_2m
      describedObject:
        kind: Service
        name: svc-nginx01
      target:
        type: Value
        value: 1000
# cat ingress001.yaml 
apiVersion: networking.k8s.io/v1 
kind: Ingress
metadata:
  name: ingress001
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: ingress01.test.com
    http:
      paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: svc-nginx01
              port: 
                number: 80
  - host: ingress03.test.com
    http:
      paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: svc-nginx03
              port:
                number: 80

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐