워크로드에서 측정항목 수집

이 페이지에서는 모니터링 및 데이터 관측 가능성을 지원하기 위해 Google Distributed Cloud (GDC) 에어 갭 어플라이언스 환경의 워크로드에서 측정항목을 스크랩하는 프로세스를 설명합니다.

시간이 지남에 따라 구성요소에서 생성되는 측정항목을 스크랩하고 수집할 수 있습니다. 모니터링 플랫폼은 GDC 에어갭 어플라이언스 프로젝트 네임스페이스 내에서 실행되는 워크로드에서 측정항목을 스크랩하는 맞춤 API를 제공합니다. 측정항목을 스크래핑하려면 관리 API 서버의 프로젝트 네임스페이스에 MonitoringTarget 커스텀 리소스를 배포합니다. 이 리소스가 배포되면 모니터링 플랫폼에서 데이터 수집을 시작합니다.

MonitoringTarget 커스텀 리소스는 모니터링 파이프라인이 프로젝트 내 지정된 포드를 스크랩하도록 지시합니다. 이러한 포드는 OpenMetrics와 같은 Prometheus 노출 형식으로 측정항목을 제공하는 HTTP 엔드포인트를 노출해야 합니다. 스크랩된 측정항목은 프로젝트의 Grafana 인스턴스에 표시되어 애플리케이션의 운영 상태에 대한 유용한 정보를 제공합니다.

MonitoringTarget 커스텀 리소스를 구성하려면 측정항목 수집을 위해 프로젝트 네임스페이스 내의 포드를 지정해야 합니다. 스크래핑 빈도, 포드의 측정항목 엔드포인트, 라벨, 주석 등 다양한 설정을 맞춤설정할 수 있습니다.

시작하기 전에

MonitoringTarget 커스텀 리소스를 관리하는 데 필요한 권한을 얻으려면 조직 IAM 관리자 또는 프로젝트 IAM 관리자에게 연결된 MonitoringTarget 역할 중 하나를 부여해 달라고 요청하세요.

필요한 액세스 수준과 권한에 따라 조직 또는 프로젝트에서 이 리소스에 대한 생성자, 편집자 또는 뷰어 역할을 획득할 수 있습니다. 자세한 내용은 IAM 권한 준비를 참고하세요.

MonitoringTarget 커스텀 리소스 구성

MonitoringTarget 커스텀 리소스는 모니터링 플랫폼에 측정항목을 수집할 위치를 알려줍니다. 측정항목을 수집할 포드, 해당 포드의 측정항목 엔드포인트, 스크래핑 빈도, 추가 설정을 지정할 수 있습니다.

이 리소스는 다음 구성을 정의합니다.

  • 타겟: 측정항목을 노출하는 프로젝트 내의 포드와 해당 엔드포인트입니다.
  • 스크랩 간격: 선택한 엔드포인트에서 측정항목을 가져올 빈도입니다.
  • 라벨 맞춤설정: 측정항목의 라벨 수정사항이 포함된 선택적 규칙입니다.

MonitoringTarget 커스텀 리소스에서 측정항목 엔드포인트를 지정하는 다음 방법 중 하나를 선택합니다.

  • 정적 엔드포인트: MonitoringTarget 구성에서 엔드포인트 (포트, 경로, 스키마)를 명시적으로 선언합니다.
  • 주석: 포드 측정항목 엔드포인트 정보는 컨테이너의 Deployment 파일 내 주석에서 가져옵니다. 각 포드에 다른 엔드포인트가 있는 경우 이 방법을 사용하면 더 유연하게 처리할 수 있습니다.

정적 엔드포인트

정적으로 정의된 엔드포인트에서 선택한 포드의 측정항목을 노출하려면 다음 단계를 따르세요.

  1. 모니터링을 위해 측정항목을 수집할 GDC 오프라인 어플라이언스 프로젝트를 확인합니다.

  2. 포드의 사양에서 containerPort 필드에 측정항목을 제공하는 포트를 선언합니다. 다음 예에서는 포드의 사양에서 포트 2112를 선언하는 방법을 보여줍니다.

    # ...
    spec:
      template:
        spec:
          containers:
          - name: your-container-name
            ports:
            - containerPort: 2112
    # ...
    
  3. MonitoringTarget 구성에서 podMetricsEndpoints 섹션에 엔드포인트 세부정보(포트, 경로, 스키마)를 지정하여 포드의 사양에 노출된 포트와 일치시킵니다.

    다음 YAML 파일은 선택된 모든 포드가 동일한 엔드포인트 http://your-container-name:2112/metrics에서 측정항목을 노출해야 하는 MonitoringTarget 구성의 예를 보여줍니다.

    apiVersion: monitoring.gdc.goog/v1
    kind: MonitoringTarget
    metadata:
      # Choose the same namespace as the workload pods.
      namespace: your-project-namespace
      name: your-container-name
    spec:
      selector:
          # Choose pod labels to consider for this job.
          # Optional: Map of key-value pairs.
          # Default: No filtering by label.
          # To consider every pod in the project namespace, remove selector fields.
        matchLabels:
          app: your-app-label
      podMetricsEndpoints:
        port:
          value: 2112
        path:
          # Choose any value for your endpoint.
          # The /metrics value is an example.
          value: /metrics
        scheme:
          value: http
    
  4. 타겟 포드와 동일한 네임스페이스 내의 관리 API 서버에 MonitoringTarget 구성을 적용합니다.

    kubectl --kubeconfig KUBECONFIG_PATH apply -f MONITORING_TARGET_NAME.yaml
    

    다음을 바꿉니다.

    • KUBECONFIG_PATH: 관리 API 서버의 kubeconfig 파일 경로입니다.
    • MONITORING_TARGET_NAME: MonitoringTarget 정의 파일의 이름입니다.

모니터링 플랫폼에서 측정항목 수집을 시작합니다.

주석

각 포드에 엔드포인트가 다른 경우 주석을 사용하여 측정항목을 노출하려면 다음 단계를 따르세요.

  1. 모니터링을 위해 측정항목을 수집할 GDC 오프라인 어플라이언스 프로젝트를 확인합니다.

  2. 컨테이너의 Deployment 파일의 annotations 섹션에 다음 주석을 추가합니다.

    • prometheus.io/path
    • prometheus.io/port
    • prometheus.io/scheme

    다음 예시에서는 포트 2112의 측정항목에 대한 주석을 보여줍니다.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: your-container-name
      namespace: your-project-namespace
      labels:
        app: your-app-label
      annotations:
        # These annotations are not required. They demonstrate selecting
        # pod metric endpoints through annotations.
        prometheus.io/path: /metrics
        prometheus.io/port: \"2112\"
        prometheus.io/scheme: http
    
  3. MonitoringTarget 구성의 podMetricsEndpoints 섹션에서 컨테이너의 Deployment 파일에 추가한 주석을 지정합니다. 이 사양은 선택한 포드의 주석에서 측정항목 엔드포인트 정보를 수집하도록 커스텀 리소스에 지시합니다.

    다음 YAML 파일은 주석을 사용하는 MonitoringTarget 구성의 예를 보여줍니다.

    apiVersion: monitoring.gdc.goog/v1
    kind: MonitoringTarget
    metadata:
    metadata:
      # Choose the same namespace as the workload pods.
      namespace: your-project-namespace
      name: your-container-name
    spec:
      selector:
        matchLabels:
          app: your-app-label
      podMetricsEndpoints:
        port:
          annotation: prometheus.io/port
        path:
          annotation: prometheus.io/path
        scheme:
          annotation: prometheus.io/scheme
    
  4. 타겟 포드와 동일한 네임스페이스 내의 관리 API 서버에 MonitoringTarget 구성을 적용합니다.

    kubectl --kubeconfig KUBECONFIG_PATH apply -f MONITORING_TARGET_NAME.yaml
    

    다음을 바꿉니다.

    • KUBECONFIG_PATH: 관리 API 서버의 kubeconfig 파일 경로입니다.
    • MONITORING_TARGET_NAME: MonitoringTarget 정의 파일의 이름입니다.

모니터링 플랫폼에서 측정항목 수집을 시작합니다.

추가 필드 및 옵션은 전체 MonitoringTarget 사양API 참조 문서를 참고하세요.

MonitoringTarget 사양 완료

다음 YAML 파일은 MonitoringTarget 맞춤 리소스의 전체 사양의 예를 보여줍니다. 자세한 내용과 필드에 관한 전체 설명은 API 참조 문서를 참고하세요.

apiVersion: monitoring.gdc.goog/v1
kind: MonitoringTarget
metadata:
  # Choose the same namespace as the workload pods.
  namespace: PROJECT_NAMESPACE
  name: MONITORING_TARGET_NAME
spec:
  # Choose matching pattern that identifies pods for this job.
  # Optional
  # Relationship between different selectors: AND
  selector:
    # Choose clusters to consider for this job.
    # Optional: List
    # Default: All clusters applicable to this project.
    # Relationship between different list elements: OR
    matchClusters:
    - string

    # Choose pod labels to consider for this job.
    # Optional: Map of key-value pairs.
    # Default: No filtering by label.
    # Relationship between different pairs: AND
    matchLabels:
      key1: value1

    # Choose annotations to consider for this job.
    # Optional: Map of key-value pairs
    # Default: No filtering by annotation
    # Relationship between different pairs: AND
    matchAnnotations:
      key1: value1

  # Configure the endpoint exposed for this job.
  podMetricsEndpoints:
    # Choose a port either through static value or annotation.
    # Optional
    # Annotation takes priority.
    # Default: static port 80
    port:
      value: integer
      annotation: string

    # Choose a path either through static value or annotation.
    # Optional
    # Annotation takes priority
    # Default: static path /metrics
    path:
      value: string
      annotation: string

    # Choose a scheme either through a static value (http or https) or annotation.
    # Optional
    # Annotation takes priority
    # Default: static scheme http
    scheme:
      value: string
      annotation: string

    # Choose the frequency to scrape the metrics endpoint defined in podMetricsEndpoints
    # Optional
    # Default: 60s
    scrapeInterval: string

    # Dynamically rewrite the label set of a target before it gets scraped.
    # https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
    # Optional
    # Default: No filtering by label
    metricsRelabelings:
    - sourceLabels:
      - string
      separator: string
      regex: string
      action: string
      targetLabel: string
      replacement: string

다음을 바꿉니다.

  • PROJECT_NAMESPACE: 프로젝트 네임스페이스
  • MONITORING_TARGET_NAME: MonitoringTarget 정의 파일의 이름입니다.