문서 메뉴
문서 홈
/
MongoDB Enterprise Kubernetes 연산자
/ /

Prometheus와 함께 사용할 리소스 배포하기

이 페이지의 내용

  • 빠른 시작
  • MongoDB 리소스 만들기
  • 선택 사항: Prometheus 엔드포인트에서 TLS 활성화
  • mongodb-prometheus-sample.yaml
  • 예제

mongodb-prometheus-sample.yaml 파일을 사용하여 Kubernetes 클러스터에 MongoDB 리소스를 배포할 수 있습니다.지표 데이터를 사용하는 방법을 Prometheus에 표시합니다.

이 샘플은 사용자가 한 명인 간단한 MongoDB 리소스를 지정하고 spec.prometheus 기본 HTTP 인증이 있고 TLS 가 없는 속성을 지정합니다. 이 샘플을 통해 MongoDB가 Prometheus로 전송하는 지표를 테스트할 수 있습니다.

참고

이 설정은 0.54 Prometheus 연산자 버전으로 테스트했습니다.

  • Kubernetes 1.16+

  • Helm 3+

Helm을 사용하여 Prometheus 연산자를 설치할 수 있습니다. 자세한 내용은 설치 지침을 참조하세요.

Helm을 사용하여 Prometheus 연산자를 설치하려면 다음 명령을 실행합니다:

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/kube-prometheus-stack \
--namespace <prometheus-system> \
--create-namespace

다음 명령을 실행하여 Kubernetes 연산자를 설치하고 Kubernetes 연산자와 리소스를 포함하는 네임스페이스를 생성합니다.

helm install enterprise-operator mongodb/enterprise-operator \
--namespace <mongodb> --create-namespace

자세한 내용은 MongoDB Enterprise Kubernetes 연산자 설치를 참조하세요.

mongodb-prometheus-sample.yaml 파일을 사용하여 Kubernetes 클러스터에 MongoDB 리소스를 배포할 수 있습니다.지표 데이터를 사용하는 방법을 Prometheus에 표시합니다.

다음 명령으로 샘플을 바로 적용할 수 있습니다:

kubectl apply -f <mongodb-prometheus-sample.yaml>

이 명령은 두 개의 시크릿을 생성합니다. 여기에는 새 MongoDB 사용자에 대한 인증과 Prometheus 엔드포인트에 대한 기본 HTTP 인증이 포함되어 있습니다. 이 명령은 mongodb 시크릿을 모두 생성합니다. 네임스페이스에 있습니다.

이 명령은 또한 다음을 생성 합니다 . 이 리소스의 지표를 사용하도록 Prometheus를 구성합니다. 이 명령은 prometheus-system 네임스페이스에 ServiceMonitor 를 만듭니다.

  1. Helm을 사용하여 cert-manager를 설치하려면 cert-manager 설치 설명서를 참조하세요.

  2. cert-manager 를 만들려면 Issuer cert-manager 구성 문서 를참조하세요.

  3. 인증서를 만들려면 cert-manager 사용 설명서를 참조하세요.

중요

프로덕션 환경에서는 이 구성을 사용하지 않도록 합니다! 보안 전문가에게 TLS 구성 방법에 대해 조언을 구해야 합니다.

TLS 를 활성화하려면 MongoDB 사용자 지정 리소스의 spec.prometheus 섹션에 새 항목을 추가해야 합니다. 다음 패치 를 실행합니다.작업을 수행하여 필요한 항목을 추가합니다.

참고

tlsSecretKeyRef.name 비밀 kubernetes.io/tls 을 가리킵니다. 유형의 MongoDB Server 인증서 를 보유합니다.

kubectl patch mdbc mongodb --type='json' \
-p='[{"op": "add", "path": "/spec/prometheus/tlsSecretKeyRef", "value":{"name": "prometheus-target-cert"}}]' \
--namespace mongodb

다음과 같은 응답이 표시됩니다:

mongodbenterprise.mongodbenterprise.mongodb.com/mongodb patched

몇 분 후 MongoDB 리소스가 실행 중 단계로 돌아가야 합니다. 이제 Prometheus ServiceMonitor 를 구성해야 합니다. HTTPS 엔드포인트를 가리킵니다.

ServiceMonitor 를 업데이트하려면 다음 명령을 실행하여 리소스를 다시 패치합니다.

kubectl patch servicemonitors mongodb-sm --type='json' \
-p='
[
{"op": "replace", "path": "/spec/endpoints/0/scheme", "value": "https"},
{"op": "add", "path": "/spec/endpoints/0/tlsConfig", "value": {"insecureSkipVerify": true}}
]
' \
--namespace mongodb

다음과 같은 응답이 표시됩니다:

servicemonitor.monitoring.coreos.com/mongodb-sm patched

이러한 변경으로 새로운 ServiceMonitor 는 HTTPS 엔드포인트( 에 /spec/endpoints/0/scheme 정의됨)를 가리킵니다. 또한 spec/endpoints/0/tlsConfig/insecureSkipVerifytrue 로 설정하여 Prometheus가 MongoDB 측에서 TLS 인증서를 확인하지 않도록 합니다.

이제 Prometheus는 HTTPS를 사용하여 MongoDB 대상을 스크래핑할 수 있어야 합니다.

다음 mongodb-prometheus-sample.yaml 파일을 생성하여 Kubernetes 클러스터에 MongoDB 리소스를 배포하고 ServiceMonitor를 사용하여 지표 데이터를 사용하는 방법을 Prometheus에 표시합니다.

샘플 파일은 사용자가 한 명인 간단한 MongoDB 리소스를 지정하고 기본 HTTP 인증과 TLS가 없는 spec.prometheus 속성을 지정합니다. 이 샘플을 통해 MongoDB가 Prometheus로 전송하는 지표를 테스트할 수 있습니다.

자세히 알아보려면 Prometheus 설정을참조하세요.

---
apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
name: my-replica-set
spec:
members: 3
version: 6.0.6-ent
cloudManager:
configMapRef:
name: <project-configmap>
credentials: <credentials-secret>
type: ReplicaSet
persistent: true
prometheus:
passwordSecretRef:
# SecretRef to a Secret with a 'password' entry on it.
name: metrics-endpoint-password
# change this value to your Prometheus username
username: prometheus-username
# Enables HTTPS on the prometheus scrapping endpoint
# This should be a reference to a Secret type kuberentes.io/tls
# tlsSecretKeyRef:
# name: <prometheus-tls-cert-secret>
# Port for Prometheus, default is 9216
# port: 9216
#
# Metrics path for Prometheus, default is /metrics
# metricsPath: '/metrics'
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
# This needs to match `spec.ServiceMonitorSelector.matchLabels` from your
# `prometheuses.monitoring.coreos.com` resouce.
labels:
release: prometheus
name: mongodb-sm
# Make sure this namespace is the same as in `spec.namespaceSelector`.
namespace: mongodb
spec:
endpoints:
# Configuring a Prometheus Endpoint with basic Auth.
# `prom-secret` is a Secret containing a `username` and `password` entries.
- basicAuth:
password:
key: password
name: metrics-endpoint-creds
username:
key: username
name: metrics-endpoint-creds
# This port matches what we created in our MongoDB Service.
port: prometheus
# If using HTTPS enabled endpoint, change scheme to https
scheme: http
# Configure different TLS related settings. For more information, see:
# https://github.com/prometheus-operator/prometheus-operator/blob/main/pkg/apis/monitoring/v1/types.go#L909
# tlsConfig:
# insecureSkipVerify: true
# What namespace to watch
namespaceSelector:
matchNames:
# Change this to the namespace the MongoDB resource was deployed.
- mongodb
# Service labels to match
selector:
matchLabels:
app: my-replica-set-svc
---
apiVersion: v1
kind: Secret
metadata:
name: metrics-endpoint-creds
namespace: mongodb
type: Opaque
stringData:
password: 'Not-So-Secure!'
username: prometheus-username
...

다음 예에서는 MongoDB 리소스와 함께 Prometheus를 사용하는 데 필요한 리소스 정의를 보여줍니다.

자세히 알아보려면 Prometheus 설정을참조하세요.

---
apiVersion: mongodb.com/v1
kind: MongoDB
metadata:
name: my-replica-set
spec:
members: 3
version: 6.0.6-ent
cloudManager:
configMapRef:
name: <project-configmap>
credentials: <credentials-secret>
type: ReplicaSet
persistent: true
prometheus:
passwordSecretRef:
name: metrics-endpoint-password
username: prometheus-username
...
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
release: prometheus
name: mongodb-sm
namespace: mongodb
spec:
endpoints:
- basicAuth:
password:
key: password
name: metrics-endpoint-creds
username:
key: username
name: metrics-endpoint-creds
port: prometheus
scheme: http
namespaceSelector:
matchNames:
- mongodb
selector:
matchLabels:
app: my-replica-set-svc
...
---
apiVersion: v1
kind: Secret
metadata:
name: metrics-endpoint-creds
namespace: mongodb
type: Opaque
stringData:
password: 'Not-So-Secure!'
username: prometheus-username
...

돌아가기

샤딩된 cluster 배포

다음

데이터베이스 리소스 편집