본 내용은 CloudNet 에서 진행하는 주말 스터디에 참여하여 해당 내용을 참고로 작성되었습니다.
https://gasidaseo.notion.site/gasidaseo/CloudNet-Blog-c9dfa44a27ff431dafdd2edacc8a1863
목표
<1> 소개
<2> 웹 접속
<3> 공식 대시보드 가져오기
<4> NGINX로 테스트 해보기
<5> 정리
시각화 툴
그라파나는 데이터 자체를 저장하지는 않는다.
데이터 소스를 프로메테우스를 사용한다.
1
웹 접속 : TSDB 데이터를 시각화, 다양한 데이터 형식 지원(메트릭, 로그, 트레이스 등)
2
그라파나는 시각화 솔루션으로 데이터 자체를 저장하지 않음 → 현재 실습 환경에서는 데이터 소스는 프로메테우스를 사용
3
접속 정보 확인 및 로그인 : 기본 계정
# ingress 확인
kubectl get ingress -n monitoring kube-prometheus-stack-grafana
kubectl describe ingress -n monitoring kube-prometheus-stack-grafana
echo -e "Grafana Web URL = https://grafana.$KOPS_CLUSTER_NAME"
# ingress 도메인으로 웹 접속
https://grafana.masterseo1.link
4
데이터 소스를 확인해보자.
Configuration → Data sources : 스택의 경우 자동으로 프로메테우스를 데이터 소스로 추가해둠 ← 서비스 주소 확인
http://kube-prometheus-stack-prometheus.monitoring:9090/
# 서비스 주소 확인
kubectl get svc,ep -n monitoring kube-prometheus-stack-prometheus
-bash: https://grafana.masterseo1.link: No such file or directory
(masterseo1:default) [root@kops-ec2 ~]# kubectl get svc,ep -n monitoring kube-prometheus-stack-prometheus
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kube-prometheus-stack-prometheus ClusterIP 100.69.254.113 <none> 9090/TCP 13h
NAME ENDPOINTS AGE
endpoints/kube-prometheus-stack-prometheus 172.30.91.213:9090 13h
1
id를 확인한다.
그라파나 > 대시보드 > 임포트 > id를 로드 한다.
import
순서
Dashboard → Import → 13770 입력 후 Load ⇒ 데이터소스(Prometheus 선택) -> Import 클릭
2
Dashboard → Import → 15757 입력 후 Load ⇒ 데이터소스(Prometheus 선택)-> Import 클릭
3
13332
Dashboard → Import → 13332 입력 후 Load ⇒ 데이터소스(Prometheus 선택) 후 Import 클릭
https://grafana.com/grafana/dashboards/13332-kube-state-metrics-v2/
4
[Node Exporter Full]
Dashboard → Import → 1860 입력 후 Load ⇒ 데이터소스(prometheus: Prometheus 선택) 후 Import 클릭
5
공식 대시보드에서 검색해보자.
RDS 707 등
https://grafana.com/grafana/dashboards/?pg=docs-grafana-latest-dashboards
6
https://grafana.com/orgs/imrtfm/dashboards
NGIN 모니터링 해보기
1
nginx 웹 서버 helm 설치
#
helm repo add bitnami https://charts.bitnami.com/bitnami
# 파라미터 파일 생성 : 서비스 모니터 방식으로 nginx 모니터링 대상을 등록하고, export 는 9113 포트 사용, nginx 웹서버 노출은 AWS CLB 기본 사용
cat <<EOT > ~/nginx-values.yaml
metrics:
enabled: true
service:
port: 9113
serviceMonitor:
enabled: true
namespace: monitoring
interval: 10s
EOT
// 메트릭 enable 한다. 9113 포트로 서비스 한다.
2
# 배포
helm install nginx bitnami/nginx --version 13.2.23 -f nginx-values.yaml
# CLB에 ExternanDNS 로 도메인 연결
kubectl annotate service nginx "external-dns.alpha.kubernetes.io/hostname=nginx.$KOPS_CLUSTER_NAME"
3
# 확인
kubectl get pod,svc,ep
kubectl get servicemonitor -n monitoring nginx
kubectl get servicemonitor -n monitoring nginx -o json | jq
4
# nginx 파드내에 컨테이너 갯수 확인
kubectl get pod -l app.kubernetes.io/instance=nginx
kubectl describe pod -l app.kubernetes.io/instance=nginx
(masterseo1:default) [root@kops-ec2 ~]# kubectl get pod -l app.kubernetes.io/instance=nginx
NAME READY STATUS RESTARTS AGE
nginx-697fd655bf-dvpxv 2/2 Running 0 7m32s
// 2/2 이다.nginx-exporter 컨테이너도 1개 같이 생긴다.
(masterseo1:default) [root@kops-ec2 ~]# kubectl describe pod -l app.kubernetes.io/instance=nginx
Name: nginx-697fd655bf-dvpxv
Namespace: default
Priority: 0
Service Account: default
Node: i-0cf34fb82a31a3da8/172.30.51.179
Start Time: Sun, 30 Apr 2023 09:45:39 +0900
Labels: app.kubernetes.io/instance=nginx
app.kubernetes.io/managed-by=Helm
app.kubernetes.io/name=nginx
helm.sh/chart=nginx-13.2.23
pod-template-hash=697fd655bf
Annotations: <none>
Status: Running
IP: 172.30.59.115
IPs:
IP: 172.30.59.115
Controlled By: ReplicaSet/nginx-697fd655bf
Containers:
nginx:
Container ID: containerd://8a9b317e5e84846b903af18e08e8b982363c099c1c0436c6dede3b0c8b637dda
Image: docker.io/bitnami/nginx:1.23.3-debian-11-r17
Image ID: docker.io/bitnami/nginx@sha256:a59c09a20b23165c099084cf603aec60924f3e91ab24f1e8969714c32344bfa3
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Sun, 30 Apr 2023 09:45:45 +0900
Ready: True
Restart Count: 0
Liveness: tcp-socket :http delay=30s timeout=5s period=10s #success=1 #failure=6
Readiness: tcp-socket :http delay=5s timeout=3s period=5s #success=1 #failure=3
Environment:
BITNAMI_DEBUG: false
NGINX_HTTP_PORT_NUMBER: 8080
Mounts: <none>
metrics:
Container ID: containerd://c335e6880f8bcc57dcf4fc17571853d8bb5e73ac6cb80a82a1a65305f615cb45
Image: docker.io/bitnami/nginx-exporter:0.11.0-debian-11-r44
Image ID: docker.io/bitnami/nginx-exporter@sha256:91c7e1a893011a15a5ee450c8ea3e8d21c2337f6e00ec43b7f8f1740af2ea25f
Port: 9113/TCP
Host Port: 0/TCP
Command:
/usr/bin/exporter
-nginx.scrape-uri
http://127.0.0.1:8080/status
State: Running
Started: Sun, 30 Apr 2023 09:45:51 +0900
Ready: True
Restart Count: 0
Liveness: http-get http://:metrics/metrics delay=15s timeout=5s period=10s #success=1 #failure=3
Readiness: http-get http://:metrics/metrics delay=5s timeout=1s period=10s #success=1 #failure=3
Environment: <none>
Mounts: <none>
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes: <none>
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 7m36s default-scheduler Successfully assigned default/nginx-697fd655bf-dvpxv to i-0cf34fb82a31a3da8
Normal Pulling 7m36s kubelet Pulling image "docker.io/bitnami/nginx:1.23.3-debian-11-r17"
Normal Pulled 7m30s kubelet Successfully pulled image "docker.io/bitnami/nginx:1.23.3-debian-11-r17" in 5.278299324s
Normal Created 7m30s kubelet Created container nginx
Normal Started 7m30s kubelet Started container nginx
Normal Pulling 7m30s kubelet Pulling image "docker.io/bitnami/nginx-exporter:0.11.0-debian-11-r44"
Normal Pulled 7m25s kubelet Successfully pulled image "docker.io/bitnami/nginx-exporter:0.11.0-debian-11-r44" in 5.67497397s
Normal Created 7m25s kubelet Created container metrics
Normal Started 7m24s kubelet Started container metrics
5
# 접속 주소 확인 및 접속
echo -e "Nginx WebServer URL = http://nginx.$KOPS_CLUSTER_NAME"
curl -s http://nginx.$KOPS_CLUSTER_NAME
--------------------------
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
6
kubectl logs deploy/nginx -f
7
# 반복 접속
while true; do curl -s http://nginx.$KOPS_CLUSTER_NAME -I | head -n 1; date; sleep 1; done
8
대시보드
12708
NGINX 웹서버에 컨테이너 상태를 확인한다!!!
데이터 소스를 프로메테우스 사용하여 그라파나를 사용해보았다.
공식 대시보드가 참 많다. 하나 하나 사용해보자.
nginx 웹서버의 컨테이너 상태를 확인해 보았다.
다음과정
https://brunch.co.kr/@topasvga/3141
https://brunch.co.kr/@topasvga/3144
감사합니다.