Bring your own Prometheus
Bring your own Prometheus (BYO Prometheus)
이 페이지는 기존에 쓰고 있던 자체 Prometheus(BYO, Bring Your Own)로 Calico Enterprise 메트릭을 그대로 스크레이프하는 방법을 다뤄요. 기본으로 제공되는 Prometheus 설치를 쓰지 않고도, 컴포넌트별 메트릭을 내 Prometheus 인스턴스로 모아 Grafana 같은 시각화 도구에서 확인할 수 있어요.
출처: 문서
본문
Big picture
Bring Your Own(BYO) Prometheus를 위해 Calico Enterprise 메트릭을 스크레이프해요.
Value
Calico Enterprise는 Prometheus 모니터링 도구로 인스트루먼트된 잡에서 메트릭을 스크레이프하고, 그 시계열 데이터를 Grafana 같은 시각화 도구로 보여줘요. Calico Enterprise 컴포넌트의 다음 시계열 메트릭을 자신의 Prometheus로 스크레이프할 수 있어요:
- elasticsearch
- fluentd
- calico-node
- kube-controllers
- felix
- typha (기본 비활성화)
Before you begin
지원 버전
이 릴리스에서 지원하는 Prometheus 버전은 Release Notes의 coreos-prometheus 항목을 참고해요.
How to
Scrape all enabled metrics
이 섹션에서는 활성화된 모든 메트릭을 스크레이프하는 service monitor를 만들어요. 기본으로 활성화되지 않은 메트릭을 켜야 한다면 다음 섹션을 참고해요.
다음 예시는 "external-prometheus" 네임스페이스에 설치된 Prometheus 서버가 k8s-app=tigera-external-prometheus 라벨이 붙은 모든 service monitor를 선택하는 serviceMonitorSelector를 갖는 모습이에요.
-
다음 설정을
monitor.yaml이라는 파일로 저장해요.apiVersion: operator.tigera.io/v1 kind: Monitor metadata: name: tigera-secure spec: externalPrometheus: namespace: external-prometheus serviceMonitor: labels: k8s-app: tigera-external-prometheus설정 옵션 전체 목록은 Tigera Operator API reference를 참고해요.
-
매니페스트를 클러스터에 적용해요.
kubectl apply -f monitor.yaml -
새 설정이 클러스터에 추가됐는지 확인해요.
export NS=external-prometheus kubectl get servicemonitor -n $NS tigera-external-prometheus kubectl get serviceaccount -n $NS tigera-external-prometheus kubectl get secret -n $NS tigera-external-prometheus kubectl get clusterrole tigera-external-prometheus kubectl get clusterrolebinding tigera-external-prometheus끝이에요. 1분 안에 새 메트릭이 Prometheus 인스턴스에 나타나는 걸 볼 수 있을 거예요. 메트릭 검증에 대한 자세한 내용은 Verify BYO Prometheus 섹션을 참고해요.
Scrape metrics from specific components directly
활성화된 모든 메트릭을 스크레이프할 때는 앞 섹션 방식을 권장해요. mTLS를 써서 특정 컴포넌트의 메트릭을 직접 스크레이프하고 싶거나, 기본으로 꺼져 있는 메트릭을 켜고 싶을 때 계속 읽어 주세요.
Tab: elasticsearch
TLS 인증서 구성
-
필요한 secret과 configmap을 내 네임스페이스로 복사해요.
-
필요한 TLS secret과 CA configmap의 매니페스트를 저장해요.
kubectl get secret calico-node-prometheus-client-tls -n tigera-prometheus -o yaml > calico-node-prometheus-client-tls.yamlkubectl get configmap -n tigera-prometheus tigera-ca-bundle -o yaml > tigera-ca-bundle.yaml -
calico-node-prometheus-client-tls.yaml과tigera-ca-bundle.yaml에서 네임스페이스를 Prometheus 인스턴스가 실행 중인 네임스페이스로 바꿔요. -
매니페스트를 클러스터에 적용해요.
kubectl apply -f calico-node-prometheus-client-tls.yamlkubectl apply -f tigera-ca-bundle.yaml
Create the service monitor
ServiceMonitor를 Prometheus가 실행 중인 네임스페이스에 적용해요.
export NAMESPACE=<my-prometheus-namespace>
kubectl apply -f https://downloads.tigera.io/ee/v3.23.2/manifests/prometheus/elasticsearch-metrics-service-monitor.yaml -n $NAMESPACE
.yaml 파일에는 네임스페이스가 정의되어 있지 않아서, kubectl로 적용하면 $NAMESPACE에 적용돼요.
Tab: fluentd
TLS 인증서 구성
-
필요한 secret과 configmap을 내 네임스페이스로 복사해요.
-
필요한 TLS secret과 CA configmap의 매니페스트를 저장해요.
kubectl get secret calico-node-prometheus-client-tls -n tigera-prometheus -o yaml > calico-node-prometheus-client-tls.yamlkubectl get configmap -n tigera-prometheus tigera-ca-bundle -o yaml > tigera-ca-bundle.yaml -
calico-node-prometheus-client-tls.yaml과tigera-ca-bundle.yaml을 열어 네임스페이스를 Prometheus 인스턴스가 실행 중인 네임스페이스로 바꿔요. -
매니페스트를 클러스터에 적용해요.
kubectl apply -f calico-node-prometheus-client-tls.yamlkubectl apply -f tigera-ca-bundle.yaml
Create the service monitor
ServiceMonitor를 Prometheus가 실행 중인 네임스페이스에 적용해요.
export NAMESPACE=<my-prometheus-namespace>
kubectl apply -f https://downloads.tigera.io/ee/v3.23.2/manifests/prometheus/fluentd-metrics-service-monitor.yaml -n $NAMESPACE
.yaml 파일에는 네임스페이스가 정의되어 있지 않아서, kubectl로 적용하면 $NAMESPACE에 적용돼요.
Tab: calico node
TLS 인증서 구성
-
필요한 secret과 configmap을 내 네임스페이스로 복사해요.
-
필요한 TLS secret과 CA configmap의 매니페스트를 저장해요.
kubectl get secret calico-node-prometheus-client-tls -n tigera-prometheus -o yaml > calico-node-prometheus-client-tls.yamlkubectl get configmap -n tigera-prometheus tigera-ca-bundle -o yaml > tigera-ca-bundle.yaml -
calico-node-prometheus-client-tls.yaml과tigera-ca-bundle.yaml에서 네임스페이스를 Prometheus 인스턴스가 실행 중인 네임스페이스로 바꿔요. -
매니페스트를 클러스터에 적용해요.
kubectl apply -f calico-node-prometheus-client-tls.yamlkubectl apply -f tigera-ca-bundle.yaml
Create the service monitor
ServiceMonitor를 Prometheus가 실행 중인 네임스페이스에 적용해요.
export NAMESPACE=<my-prometheus-namespace>
kubectl apply -f https://downloads.tigera.io/ee/v3.23.2/manifests/prometheus/calico-node-monitor-service-monitor.yaml -n $NAMESPACE
.yaml 파일에는 네임스페이스가 정의되어 있지 않아서, kubectl로 적용하면 $NAMESPACE에 적용돼요.
Tab: kube-controllers
TLS 인증서 구성
-
필요한 secret과 configmap을 내 네임스페이스로 복사해요.
-
필요한 TLS secret과 CA configmap의 매니페스트를 저장해요.
kubectl get secret calico-node-prometheus-client-tls -n tigera-prometheus -o yaml > calico-node-prometheus-client-tls.yamlkubectl get configmap -n tigera-prometheus tigera-ca-bundle -o yaml > tigera-ca-bundle.yaml -
calico-node-prometheus-client-tls.yaml과tigera-ca-bundle.yaml에서 네임스페이스를 Prometheus 인스턴스가 실행 중인 네임스페이스로 바꿔요. -
매니페스트를 클러스터에 적용해요.
kubectl apply -f calico-node-prometheus-client-tls.yamlkubectl apply -f tigera-ca-bundle.yaml
Create the service monitor
ServiceMonitor를 Prometheus가 실행 중인 네임스페이스에 적용해요.
export NAMESPACE=<my-prometheus-namespace>
kubectl apply -f https://downloads.tigera.io/ee/v3.23.2/manifests/prometheus/kube-controller-metrics-service-monitor.yaml -n $NAMESPACE
.yaml 파일에는 네임스페이스가 정의되어 있지 않아서, kubectl로 적용하면 $NAMESPACE에 적용돼요.
Tab: Felix
메트릭 활성화
Felix 메트릭은 기본으로 꺼져 있어요.
기본적으로 Felix는 port 9091 TCP로 메트릭을 공개해요.
다음 명령으로 Felix 메트릭을 활성화해요.
kubectl patch felixconfiguration default --type merge --patch '{"spec":{"prometheusMetricsEnabled": true}}'
결과는 대략 이렇게 나와요:
felixconfiguration.projectcalico.org/default patched
Felix 설정값 전체는 Felix configuration을 참고해요.
Prometheus 관련 Felix 설정값 전체는 Felix Prometheus를 참고해요.
Windows 노드라면, Felix 메트릭을 공개하는 service를 생성해요
Calico Enterprise for Windows를 운영 중이라면, Windows 노드의 Felix 메트릭을 공개할 service를 만들어야 해요:
kubectl apply -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: felix-windows-metrics-svc
namespace: calico-system
labels:
k8s-app: felix-metrics
spec:
clusterIP: None
selector:
k8s-app: calico-node-windows
ports:
- port: 9091
targetPort: 9091
EOF
기본적으로 Windows 방화벽은 포트 리스닝을 차단해요. Calico Enterprise가 Prometheus 메트릭 포트의 Windows 방화벽 규칙을 관리하게 하려면, FelixConfiguration에서 windowsManageFirewallRules 설정을 활성화해요:
kubectl patch felixConfiguration default --type merge --patch '{"spec":{"windowsManageFirewallRules": "Enabled"}}'
자세한 내용은 FelixConfiguration reference를 참고해요. Calico Enterprise가 관리하게 두지 않고, Prometheus 포트 리스닝을 허용하는 Windows 방화벽 규칙을 직접 추가할 수도 있어요.
Create the service monitor
ServiceMonitor를 Prometheus가 실행 중인 네임스페이스에 적용해요.
export NAMESPACE=<my-prometheus-namespace>
kubectl apply -f https://downloads.tigera.io/ee/v3.23.2/manifests/prometheus/felix-metrics-service-monitor.yaml -n $NAMESPACE
.yaml 파일에는 네임스페이스가 정의되어 있지 않아서, kubectl로 적용하면 $NAMESPACE에 적용돼요.
Tab: Typha
메트릭 활성화
Typha 메트릭은 기본으로 꺼져 있어요.
기본적으로 Typha는 port 9091 TCP로 메트릭을 공개해요. 다만 Calico Enterprise를 Amazon yaml 파일로 설치했다면 TYPHA_PROMETHEUSMETRICSPORT 환경 변수로 직접 설정되기 때문에 이 포트는 9093이 돼요.
다음 명령으로 Typha 메트릭을 활성화해요.
kubectl patch installation default --type=merge -p '{"spec": {"typhaMetricsPort":9093}}'
결과는 대략 이렇게 나와요:
installation.operator.tigera.io/default patched
Create the service monitor
ServiceMonitor를 Prometheus가 실행 중인 네임스페이스에 적용해요.
export NAMESPACE=<my-prometheus-namespace>
kubectl apply -f https://downloads.tigera.io/ee/v3.23.2/manifests/prometheus/typha-metrics-service-monitor.yaml -n $NAMESPACE
.yaml 파일에는 네임스페이스가 정의되어 있지 않아서, kubectl로 적용하면 $NAMESPACE에 적용돼요.
Verify BYO Prometheus
-
포트 포워딩 기능으로 Prometheus 대시보드에 접근해요.
kubectl port-forward pod/byo-prometheus-pod 9090:9090 -n $NAMESPACE -
브라우저로 Prometheus 대시보드에 접속해요: http://localhost:9090.
-
Expression 텍스트 상자에 메트릭 이름을 입력하고 Execute 버튼을 눌러요.
Console 표에 모든 노드와 엔드포인트 수가 채워져요.
Troubleshooting
이 섹션은 특정 컴포넌트 메트릭 직접 스크레이프 섹션을 따라한 뒤 mTLS 문제를 겪을 때만 해당돼요.
-
클러스터에서 TLS 자격 증명과 CA 번들을 추출해요.
kubectl get secret -n $NAMESPACE calico-node-prometheus-client-tls -o jsonpath='{.data.tls\.key}' | base64 -d > key.pem kubectl get secret -n $NAMESPACE calico-node-prometheus-client-tls -o jsonpath='{.data.tls\.crt}' | base64 -d > cert.pem kubectl get cm -n $NAMESPACE tigera-ca-bundle -o jsonpath='{.data.tigera-ca-bundle\.crt}' > bundle.pem -
Prometheus pod를 포트 포워딩하고, 포워딩된 포트로 이 명령을 실행해요.
curl --cacert bundle.pem --key key.pem --cert cert.pem https://localhost:8080/metrics
메트릭이 보이면 정상이에요.
Create policy to secure traffic between pods
제로 트러스트를 지원하려면, BYO Prometheus pod와 각 메트릭 pod 사이 트래픽을 허용하는 Calico Enterprise 네트워크 정책을 만드는 걸 권장해요. ingress/egress 정책 샘플은 Get started with Calico network policy를 참고해요.