일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Kubeflow
- CANARY
- argocd
- Pulumi
- operator
- mlops
- serving
- eBPF
- knative
- Argo
- seldon core
- Kopf
- blue/green
- Continuous Deployment
- tekton
- 카오스 엔지니어링
- gitops
- Litmus
- opentelemetry
- CI/CD
- Kubernetes
- 오퍼레이터
- opensearch
- Kubernetes 인증
- keda
- nginx ingress
- xdp
- Model Serving
- MLflow
- kubernetes operator
- Today
- Total
Kubernetes 이야기
Nginx Ingress 트래픽 모니터링 결과로 Auto Scale 사용하기 본문
소개
Kubernetes 는 기본적으로 Metrics Server 에서 제공하는 CPU, Memory 메트릭을 기반으로 Auto Scale을 적용할 수 있다.
하지만, CPU나 Memory 기반이 아닌 사용량 ( 예: 사용자 요청 수 ) 에 따라 Auto Scale을 하고 싶은 경우가 있다.
준비사항
사용자의 요청 메트릭을 수집하기 위해 Nginx Controller에 메트릭 수집 가능한 설정을 해 보자.
자세한 설정은 아래의 URL을 참고한다.
https://kubernetes.github.io/ingress-nginx/user-guide/monitoring/
Prometheus and Grafana installation - NGINX Ingress Controller
Prometheus and Grafana installation Two different methods to install and configure Prometheus and Grafana are described in this doc. - Prometheus and Grafana installation using Pod Annotations. This installs Prometheus and Grafana in the same namespace as
kubernetes.github.io
정상적으로 prometheus에 수집된다면 다음과 같은 metric을 조회할 수 있다.
이렇게 Prometheus에 수집된 정보를 HPA (Horizontal Pod Autoscaling) 에서 사용하기 위해서는 Prometheus Adapter 를 사용하여 연동할 수 있다.
Prometheus Adapter configuation
Prometheus Adapter 가 설치되어 있으면 adapter-config라는 Configmap 이 생성되어 있다. 여기에 사용자가 정의하는 Query 를 만들어 넣을 수 있다.
- seriesQuery: '{__name__=~"^nginx_ingress_controller_requests.*",namespace!="",ingress!=""}'
seriesFilters: []
resources:
template: <<.Resource>>
overrides:
exported_namespace: {resource: "namespace"}
ingress: {resource: "ingress"}
name:
matches: ""
as: "http_request_per_second"
metricsQuery: 'sum(rate(<<.Series>>{<<.LabelMatchers>>}[1m])) by (<<.GroupBy>>)'
설정 후 HPA 를 설정해 보자.
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: as-test
namespace: test
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: rollouts-bluegreen
minReplicas: 2
maxReplicas: 4
metrics:
- type: Object
object:
metricName: http_request_per_second
target:
apiVersion: networking.k8s.io/v1
kind: Ingress
name: prod-ingress
targetValue: 20
hpa 실행 후 부하테스트를 실행하면 아래와 같이 auto scale이 됨을 확인할 수 있다.
# client 한명이 40tps 발생
# hey -n 10000 -q 40 -c 1 http://test.prod.10.60.200.121.sslip.io/
# kubectl get hpa -n test Mon Feb 28 22:38:11 2022
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
as-test Deployment/rollouts-bluegreen 41100m/20 2 4 4 7m36s
'Kubernetes > 일반' 카테고리의 다른 글
Nginx Ingress Path 기반 라우팅 설정 (0) | 2022.03.15 |
---|---|
로컬 Kubernetes 클러스터 - kind 설치 (0) | 2022.03.08 |
kubernetes coredns 에 hosts 등록하기 (0) | 2022.02.22 |
Chaos Mesh 를 사용한 카오스 엔지니어링 (0) | 2022.02.21 |
cert-manager와 letsencrypt 연동 (0) | 2022.02.16 |