HAProxy

이 문서에서는 Google Cloud Managed Service for Prometheus를 사용하여 HAProxy용 PROMEX 서비스에서 측정항목을 수집할 수 있도록 Google Kubernetes Engine 배포를 구성하는 방법을 설명합니다. 이 문서에서는 다음을 수행하는 방법을 보여줍니다.

  • 측정항목을 보고하도록 HAProxy용 PROMEX 서비스를 설정합니다.
  • 내보낸 측정항목을 수집하도록 Managed Service for Prometheus의 PodMonitoring 리소스를 구성합니다.
  • 측정항목을 보도록 Cloud Monitoring의 대시보드에 액세스합니다.
  • 측정항목을 모니터링하도록 알림 규칙을 구성합니다.

이 안내는 관리형 컬렉션을 Managed Service for Prometheus와 함께 사용하는 경우에만 적용됩니다. 자체 배포 컬렉션을 사용하는 경우 HAProxy 문서에서 설치 정보를 참조하세요.

이 안내는 예시로서 제공되며 대부분의 Kubernetes 환경에서 작동합니다. 제한적인 보안 또는 조직 정책으로 인해 애플리케이션 또는 내보내기 도구를 설치하는 데 문제가 있으면 지원을 위한 오픈소스 문서를 참조하는 것이 좋습니다.

HAProxy에 대한 자세한 내용은 HAProxy를 참조하세요.

기본 요건

Managed Service for Prometheus 및 관리형 컬렉션을 사용하여 HAProxy용 PROMEX 서비스에서 측정항목을 수집하려면 배포가 다음 요구사항을 충족해야 합니다.

  • 클러스터가 Google Kubernetes Engine 버전 1.21.4-gke.300 이상을 실행 중이어야 합니다.
  • 관리형 컬렉션이 사용 설정된 상태에서 Managed Service for Prometheus를 실행 중이어야 합니다. 자세한 내용은 관리형 컬렉션 시작하기를 참조하세요.

  • Cloud Monitoring에서 사용할 수 있는 대시보드를 HAProxy 통합에 사용하려면 haproxy_promex 버전 2.4 이상을 사용해야 합니다.

    사용 가능한 대시보드에 대한 자세한 내용은 대시보드 보기를 참조하세요.

HAProxy는 서비스를 사용 설정한 상태에서 빌드되고 적절한 frontend가 구성에 포함된 경우에만 Prometheus 형식 측정항목을 노출합니다.

2.4 이상인 버전에 대한 대부분의 공식 Docker 이미지는 이 서비스가 사용 설정된 상태로 빌드됩니다.

다음 구성 예시는 HAProxy 엔터프라이즈 문서를 참조하도록 빌드되었습니다. 커뮤니티 버전과 함께 작동하며 특정 요구에 맞게 수정할 수 있습니다.

HAProxy 구성 수정

다음 예시와 같이 HAProxy 구성을 수정합니다.

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
  name: haproxy
data:
  haproxy.cfg: |
    ...
+   frontend prometheus
+     mode http
+     bind *:8404
+     http-request use-service prometheus-exporter if { path /metrics }
    ...
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: haproxy
spec:
  selector:
    matchLabels:
+     app.kubernetes.io/name: haproxy
  template:
    metadata:
      labels:
+       app.kubernetes.io/name: haproxy
    spec:
      containers:
      - name: haproxy
        image: haproxy:2.8
        ports:
+       - containerPort: 8404
+         name: prometheus
        volumeMounts:
        - mountPath: /usr/local/etc/haproxy/haproxy.cfg
          subPath: haproxy.cfg
          name: haproxy
      volumes:
      - name: haproxy
        configMap:
          name: haproxy
          items:
          - key: haproxy.cfg
            path: haproxy.cfg

+ 기호로 시작하는 모든 줄을 구성에 추가해야 합니다.

로컬 파일에서 구성 변경사항을 적용하려면 다음 명령어를 실행합니다.

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Terraform을 사용하여 구성을 관리할 수도 있습니다.

HAProxy용 PROMEX 서비스가 예상 엔드포인트에서 측정항목을 내보내는지 확인하려면 다음을 수행하세요.

  1. 다음 명령어를 사용하여 포트 전달을 설정합니다.
    kubectl -n NAMESPACE_NAME port-forward POD_NAME 8404
    
  2. 브라우저 또는 다른 터미널 세션의 curl 유틸리티를 사용하여 엔드포인트 localhost:8404/metrics에 액세스합니다.

PodMonitoring 리소스 정의

대상 검색을 위해 Managed Service for Prometheus 연산자에는 동일한 네임스페이스의 HAProxy 내보내기 도구에 해당하는 PodMonitoring 리소스가 필요합니다.

다음 PodMonitoring 구성을 사용할 수 있습니다.

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
  name: haproxy
  labels:
    app.kubernetes.io/name: haproxy
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  endpoints:
  - port: prometheus
    scheme: http
    interval: 30s
    path: /metrics
  selector:
    matchLabels:
      app.kubernetes.io/name: haproxy
portmatchLabels 필드의 값이 모니터링하려는 HAProxy 포드의 값과 일치하는지 확인합니다.

HAProxy는 bind 구성 옵션에 정의된 대상에서 측정항목을 노출합니다. 이 옵션을 사용하려면 측정항목 스크래핑을 위해 리슨할 IP 주소와 포트를 정의해야 합니다.

로컬 파일에서 구성 변경사항을 적용하려면 다음 명령어를 실행합니다.

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Terraform을 사용하여 구성을 관리할 수도 있습니다.

규칙 및 알림 정의

다음 Rules 구성을 사용하여 HAProxy 측정항목에 대한 알림을 정의할 수 있습니다.

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: monitoring.googleapis.com/v1
kind: Rules
metadata:
  name: haproxy-rules
  labels:
    app.kubernetes.io/component: rules
    app.kubernetes.io/name: haproxy-rules
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  groups:
  - name: haproxy
    interval: 30s
    rules:
    - alert: HAProxyDown
      annotations:
        description: |-
          HAProxy instance is down
            VALUE = {{ $value }}
            LABELS: {{ $labels }}
        summary: HAProxy down (instance {{ $labels.instance }})
      expr: haproxy_server_up{job="haproxy"} == 0
      for: 5m
      labels:
        severity: critical
    - alert: HAProxyTooManyConnections
      annotations:
        description: |-
          HAProxy instance has too many connections
            VALUE = {{ $value }}
            LABELS: {{ $labels }}
        summary: HAProxy too many connections (instance {{ $labels.instance }})
      expr: haproxy_frontend_current_sessions{job="haproxy"} / haproxy_frontend_limit_sessions{job="haproxy"} * 100 > 90
      for: 5m
      labels:
        severity: warning

로컬 파일에서 구성 변경사항을 적용하려면 다음 명령어를 실행합니다.

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Terraform을 사용하여 구성을 관리할 수도 있습니다.

클러스터에 규칙을 적용하는 방법에 대한 자세한 내용은 관리형 규칙 평가 및 알림을 참조하세요.

구성 확인

측정항목 탐색기를 사용하여 HAProxy 내보내기 도구를 올바르게 구성했는지 확인할 수 있습니다. Cloud Monitoring이 측정항목을 수집하는 데 1~2분 정도 걸릴 수 있습니다.

측정항목이 수집되었는지 확인하려면 다음을 수행하세요.

  1. Google Cloud 콘솔의 탐색 패널에서 Monitoring을 선택한 후 측정항목 탐색기를 선택합니다.

    측정항목 탐색기로 이동

  2. 쿼리 빌더 창의 툴바에서 이름이  MQL 또는  PromQL인 버튼을 선택합니다.
  3. 언어 전환 버튼에 PromQL이 선택되어 있는지 확인합니다. 언어 전환 버튼은 쿼리 형식을 지정할 수 있는 동일한 툴바에 있습니다.
  4. 다음 쿼리를 입력하고 실행합니다.
    up{job="haproxy", cluster="CLUSTER_NAME", namespace="NAMESPACE_NAME"}

대시보드 보기

Cloud Monitoring 통합에는 HAProxy Prometheus 개요 대시보드가 포함됩니다. 대시보드는 통합을 구성할 때 자동으로 설치됩니다. 통합을 설치하지 않고도 대시보드의 정적 미리보기를 볼 수 있습니다.

설치된 대시보드를 보려면 다음을 수행합니다.

  1. Google Cloud 콘솔의 탐색 패널에서 Monitoring을 선택한 후 대시보드를 선택합니다.

    대시보드로 이동

  2. 대시보드 목록 탭을 선택합니다.
  3. 통합 카테고리를 선택합니다.
  4. 대시보드의 이름을 클릭합니다(예: HAProxy Prometheus 개요).

대시보드의 정적 미리보기를 보려면 다음을 수행합니다.

  1. Google Cloud 콘솔의 탐색 패널에서 Monitoring을 선택한 후 통합을 선택합니다.

    통합으로 이동

  2. Kubernetes Engine 배포 플랫폼 필터를 클릭합니다.
  3. HAProxy 통합을 찾고 세부정보 보기를 클릭합니다.
  4. 대시보드 탭을 선택합니다.

문제 해결

측정항목 수집 문제 해결에 대한 자세한 내용은 수집 측 문제 해결에서 내보내기 도구의 수집 관련 문제를 참조하세요.