NGINX Ingress Controller 쿠버네티스 모니터링 설정
이 포스트에서는 Kubernetes 클러스터에 배포 중인 NGINX Plus Ingress Controller의 대시보드를 활성화하여 모니터링 하는 방법과, NGINX Plus Ingress Controller 메트릭을 Prometheus 형식으로 수집하여 Grafana를 통해 모니터링하는 방법을 설명합니다.
NGINX Ingress Controller는 Manifest 파일을 사용하여 구성/배포되었습니다.
목차
1. NGINX Ingress Controller 모니터링
2. NGINX Plus Ingress Controller 대시보드 활성화
3. NGINX Plus Ingress Controller 메트릭 모니터링
3-1. NGINX Ingress Controller 메트릭 설정
3-2. Prometehus를 통한 NGINX Ingress Controller 메트릭 모니터링 설정
3-3. Grafana 서버 설치
3-4. Grafana 활용 메트릭 모니터링 설정
1. NGINX Ingress Controller 모니터링

NGINX Plus Ingress Controller는 내장된 대시보드를 제공하며, 클러스터 내의 요청 처리량, 응답 상태, 백엔드 서버의 상태 등을 실시간으로 파악할 수 있습니다.
또한 Ingress Controller의 메트릭을 Prometheus, Grafana와 연동하여 더 많은 메트릭을 그래프와 표 형식으로 시각화하여 더욱 효과적으로 모니터링할 수 있습니다.
2. NGINX Plus Ingress Controller 대시보드 활성화
NGINX Ingress Controller의 대시보드 기능은 NGINX Plus Ingess Controller에서만 사용할 수 있습니다.
대시보드에 액세스하기 위해 액세스를 허용할 IP를 설정해야 합니다.
1. NGINX Ingress Controller의 deployment 파일에 -nginx-status-allow-cidrs command-line argument 설정을 추가하고 배포합니다.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-ingress
namespace: nginx-ingress
......
args:
- -nginx-plus
- -nginx-configmaps=$(POD_NAMESPACE)/nginx-config
- -nginx-status-allow-cidrs= 10.244.0.0/16 # 클러스터에 설정된 CIDR 설정
대시보드의 기본 설정으로 8080번 포트를 통해 접근할 수 있습니다. nginx-status-port command-line argument 설정을 통해 포트를 지정할 수 있습니다.
2. 해당 포트를 외부에서 접근할 수 있도록 NodePort 서비스를 설정하여 배포합니다.
apiVersion: v1
kind: Service
metadata:
name: nginx-ingress
namespace: nginx-ingress
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
name: http
- port: 443
targetPort: 443
protocol: TCP
name: https
- port: 8080 # 8080 포트 설정
targetPort: 8080
protocol: TCP
name: dashboard
selector:
app: nginx-ingress
3. 적용된 서비스를 확인합니다. 8080번 포트가 30575번 포트로 노출된 것을 확인할 수 있습니다.
# kubectl get svc -n nginx-ingress
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-ingress NodePort 10.102.97.200 <none> 80:30348/TCP,443:32253/TCP,8080:30575/TCP 11d
4. <노드 IP>:<서비스 포트>/dashboard.html 주소로 연결하여 대시보드에 접근할 수 있습니다.

3. NGINX Plus Ingress Controller 메트릭 모니터링
3-1. NGINX Ingress Controller 메트릭 설정
NGINX Ingress Controller는 메트릭을 Prometheus 형식으로 제공하도록 설정할 수 있습니다.
1. 메트릭 설정을 위해 NGINX Ingress Controller의 deployment 파일을 수정하고, 배포합니다.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-ingress
namespace: nginx-ingress
spec:
replicas: 1
selector:
matchLabels:
app: nginx-ingress
template:
metadata:
labels:
app: nginx-ingress
app.kubernetes.io/name: nginx-ingress
annotations: # annotations 항목에 prometheus 설정 활성화
prometheus.io/scrape: "true"
prometheus.io/port: "9113"
prometheus.io/scheme: http
......
args:
- -nginx-plus
- -nginx-configmaps=$(POD_NAMESPACE)/nginx-config
- -nginx-status-allow-cidrs= 10.244.0.0/16
- -enable-prometheus-metrics # prometheus 메트릭 활성화
NGINX Ingress Controller의 메트릭을 9113번 포트를 통해 수집할 수 있습니다.
2. NodePort 서비스 설정에 9113번 포트를 추가하여 배포합니다.
apiVersion: v1
kind: Service
metadata:
name: nginx-ingress
namespace: nginx-ingress
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
name: http
- port: 443
targetPort: 443
protocol: TCP
name: https
- port: 8080
targetPort: 8080
protocol: TCP
name: dashboard
- port: 9113 # 메트릭 포트 설정
targetPort: 9113
protocol: TCP
name: prometheus
selector:
app: nginx-ingress
3. 적용된 서비스를 확인합니다. 9113번 포트가 32200번 포트로 노출된 것을 확인할 수 있습니다.
# kubectl get svc -n nginx-ingress
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-ingress NodePort 10.102.97.200 <none> 80:30348/TCP,443:32253/TCP,8080:30575/TCP,9113:32200/TCP 11d
4. <노드 IP>:<서비스 포트>/metrics로 연결하여 메트릭 정보를 확인할 수 있습니다.

3-2. Prometehus를 통한 NGINX Ingress Controller 메트릭 모니터링 설정
NGINX Ingress Controller의 메트릭을 Grafana를 활용하여 모니터링 하기 위해서 메트릭을 모니터링 할 Prometheus 서버가 필요합니다. 해당 서버를 Manifest 파일을 통해 클러스터에 배포하겠습니다.
1. prometheus 네임스페이스를 생성합니다
kubectl create namespace prometheus
2. configmap 파일을 작성하고 배포합니다. data 항목에 메트릭을 수집할 target 설정을 합니다.
# vi prometheus-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-server-conf
namespace: prometheus
data:
prometheus.yml: |
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'nginx-ingress-controller'
static_configs:
- targets: ['192.168.200.161:32200'] # Ingress Controller의 메트릭 서비스 주소 설정
# kubectl apply -f prometheus-config.yaml
3. deployment 파일을 작성하고 배포합니다.
# vi prometheus-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus-server
namespace: prometheus
spec:
replicas: 1
selector:
matchLabels:
app: prometheus-server
template:
metadata:
labels:
app: prometheus-server
spec:
containers:
- name: prometheus
image: prom/prometheus
ports:
- containerPort: 9090
volumeMounts:
- name: config-volume
mountPath: /etc/prometheus
volumes:
- name: config-volume
configMap:
name: prometheus-server-conf
defaultMode: 420
# kubectl apply -f prometheus-deployment.yaml
4. NodePort 서비스 설정 파일을 작성하고 배포합니다.
# vi prometheus-service.yaml
apiVersion: v1
kind: Service
metadata:
name: prometheus-service
namespace: prometheus
spec:
type: NodePort
ports:
- protocol: TCP
port: 80
targetPort: 9090
selector:
app: prometheus-server
# kubectl apply -f prometheus-service.yaml
5. 배포 중인 서비스를 확인합니다.
# kubectl get svc -n prometheus
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
prometheus-service NodePort 10.105.120.16 <none> 80:31028/TCP 163m
3-3. Grafana 서버 설치
설정한 Prometheus 서버와 Grafana를 연동하여 NGINX Ingress Controller의 메트릭을 모니터링하고 시각화할 수 있습니다.
이 포스트에서는 kubernetes 클러스터의 노드로 구성되지 않은 별개의 VM 환경에서 Grafana 서버를 구성했습니다. Ubuntu 환경에서 설치를 진행했으며 다른 환경의 설치 방법은 여기를 참조하세요.
1. Grafana 설치를 위한 필수 패키지 설치를 진행합니다.
# apt-get install -y apt-transport-https software-properties-common wget
2. 공개키를 저장할 경로를 생성하고, 다운로드합니다.
# mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
3. stable 버전의 저장소를 등록합니다.
# echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
4. 저장소를 업데이트하고, 다운로드합니다.
# apt-get update
# apt-get install grafana
5. 설치가 완료되면 Grafana 서버를 시작합니다.
# systemctl start grafana-server
3-4. Grafana 활용 메트릭 모니터링 설정
1. 설치한 VM의 3000번 포트로 연결하여 Grafana 서버에 접속해 로그인을 진행합니다.
초기 ID/PW는 admin/admin입니다

2. 좌측 메뉴바의 Connections – Data sources 메뉴로 이동합니다.

3. Add data source를 선택하여 Prometheus를 선택합니다.

4. Data source의 이름과 메트릭을 수집할 Prometheus 서버의 주소를 입력합니다.

5. 필요한 경우 추가적인 설정을 마치고, Save & test 버튼을 클릭하여 Prometheus API로 요청에 성공하는지 확인합니다.

6. Data sources 메뉴로 이동하여 생성을 확인하고, Build a dashboard 버튼을 통해 대시보드를 생성합니다.

7. 대시보드를 직접 구성하거나, 사전에 설정된 대시보드 형식을 적용할 수 있습니다.
이 포스트에서는 NGINX 공식 Ingress Controller github repo의 json파일을 사용했습니다.

8. Grafana의 대시보드를 활용한 NGINX Ingress Controller 모니터링 환경이 구성된 것을 확인할 수 있습니다.

아래 뉴스레터를 구독하고 NGINX와 NGINX STORE의 최신 정보들을 빠르게 전달받아보세요.
댓글을 달려면 로그인해야 합니다.