> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Kubernetes 모니터링

> ClickHouse Observability로 Kubernetes 로그 및 메트릭 수집하기

Kubernetes 클러스터에서 로그와 메트릭을 수집하여 **ClickHouse Observability**로 전송합니다. 기존 워크로드를 사용하거나, 필요에 따라 아래의 데모 애플리케이션을 배포하십시오. 데모 아키텍처와 애플리케이션 배포 방식은 완전 관리형 배포와 자가 관리형 배포 모두 동일합니다.

## 사전 요구 사항

* collector와 (사용하는 경우) 데모 애플리케이션을 실행할 수 있는 리소스를 갖춘, 실행 중인 **Kubernetes 클러스터**.
* ClickHouse Observability 서비스. [완전 관리형 시작 가이드](https://clickhouse.com/docs/ko/clickstack/observability/getting-started.md) 또는 [자가 관리형 시작 가이드](https://clickhouse.com/docs/ko/clickstack/self-configured/getting-started/managed.md)를 참조하십시오.
* **[Helm](https://helm.sh/)** v3 이상.
* 클러스터에 연결하도록 구성되어 있고 네임스페이스, Secret, ConfigMap, 클러스터 역할을 생성할 권한(permission)이 있는 **`kubectl`**.
* collector에서 선택한 배포 방식의 엔드포인트에 접근할 수 있는 네트워크 접근.

## 데모 애플리케이션

모니터링할 워크로드(workloads)가 이미 있다면 데모 배포를 건너뛰고 [수집 구성](#configure-collection)으로 이동하십시오.

[OpenTelemetry Demo](https://github.com/ClickHouse/opentelemetry-demo)의 ClickStack 포크는 계측된 마이크로서비스와 자동 생성 트래픽이 포함된 전자상거래 애플리케이션을 제공합니다.

### 데모 아키텍처

이 데모는 서로 다른 프로그래밍 언어로 작성된 마이크로서비스들과, gRPC와 HTTP를 통해 이들 서비스가 서로 통신하도록 구성되어 있으며, Locust를 사용해 사용자 트래픽을 모의하는 부하 생성기도 포함합니다. 이 데모의 원래 소스 코드는 [ClickStack instrumentation](https://clickhouse.com/docs/ko/clickstack/ingesting-data/sdks/index.md)을 사용하도록 수정되었습니다.

![아키텍처](https://mintcdn.com/private-7c7dfe99/Y7YJeVzyAMn9ugXv/images/use-cases/observability/hyperdx-demo/architecture.webp?fit=max\&auto=format\&n=Y7YJeVzyAMn9ugXv\&q=85\&s=76b5086a03fd753513254433b4911fe0)

*출처: [https://opentelemetry.io/docs/demo/architecture/](https://opentelemetry.io/docs/demo/architecture/)*

데모에 대한 자세한 내용은 다음 문서에서 확인할 수 있습니다.

* [OpenTelemetry 문서](https://opentelemetry.io/docs/demo/)
* [ClickStack에서 유지 관리하는 포크](https://github.com/ClickHouse/opentelemetry-demo)

### 데모 배포

데모 매니페스트를 다운로드하여 배포하십시오:

```shell theme={null}
curl -fSL -o opentelemetry-demo.yaml \
  https://raw.githubusercontent.com/ClickHouse/opentelemetry-demo/d658416d6b36381126eba4416877b6518c320921/kubernetes/opentelemetry-demo.yaml

kubectl apply --namespace otel-demo -f opentelemetry-demo.yaml
kubectl get pods --namespace otel-demo
```

애플리케이션 파드가 준비될 때까지 기다리십시오. 이 매니페스트는 `otel-demo` 네임스페이스를 생성하며 지원 서비스도 함께 포함합니다.

이 명령어는 특정 데모 revision으로 고정되어 있습니다. 애플리케이션을 배포한 후 아래에서 사용 중인 배포 방식의 탭 안내에 따라 collector를 설치하고 데모 텔레메트리를 연결하십시오. collector는 Kubernetes 로그와 인프라 메트릭을 수집하고, 계측된 데모 서비스는 OTLP를 통해 애플리케이션 텔레메트리를 전송합니다.

## 수집 구성

> [tab] 완전 관리형
>
> [베타 서비스](https://clickhouse.com/docs/reference/settings/beta-and-experimental-features.md#beta-features)
>
> Kubernetes 클러스터에 OpenTelemetry 수집기를 배포하여 로그와 메트릭을 수집하고 관리형 텔레메트리 엔드포인트로 전달하십시오. 데이터 수집, 스토리지, UI는 ClickHouse Observability가 관리하므로 클러스터에 ClickHouse, ClickStack UI, MongoDB를 배포할 필요가 없습니다.
>
> **1. 연결 정보를 복사하세요**
>
> ClickHouse Observability 서비스를 열고 **팀 설정 → 데이터 → 관리형 텔레메트리**로 이동하십시오. **OpenTelemetry Collector**에서 **URL** 탭을 선택한 다음 OTLP HTTP 엔드포인트와 API Key를 복사하십시오. 전체 값을 확인하려면 **Reveal key**를 선택하십시오.
>
> 이 연결 정보는 이후 단계에서 Kubernetes collector를 구성할 때 사용합니다.
>
> ![OTLP 엔드포인트 및 API Key 연결 정보가 표시된 관리형 텔레메트리 화면](https://mintcdn.com/private-7c7dfe99/Zk1feNn6fCQBpold/images/clickstack/getting-started/observability-managed-telemetry.png?fit=max\&auto=format\&n=Zk1feNn6fCQBpold\&q=85\&s=e63a2ac2e6ab996d3fc360ebe0f487a5)
>
> **2. 연결 정보를 저장하십시오**
>
> 관리형 텔레메트리 API Key는 Kubernetes Secret에, OTLP HTTP 엔드포인트는 ConfigMap에 저장하십시오. 두 리소스는 모두 collector를 설치할 네임스페이스에 생성해야 합니다. 아래 예시에서는 전용 네임스페이스인 `otel-collectors`를 사용합니다.
>
> ```shell theme={null}
> kubectl create namespace otel-collectors
>
> kubectl create secret generic hyperdx-secret \
>   --namespace otel-collectors \
>   --from-literal=HYPERDX_API_KEY='<api-key>'
>
> kubectl create configmap otel-config-vars \
>   --namespace otel-collectors \
>   --from-literal=YOUR_OTEL_COLLECTOR_ENDPOINT='<managed-otlp-http-endpoint>'
> ```
>
> 네임스페이스가 이미 있으면 첫 번째 명령은 건너뛰십시오. 자리표시자를 **Managed Telemetry**에 표시된 값으로 바꾸되, 엔드포인트의 HTTPS 스킴과 포트는 그대로 유지하십시오.
>
> **3. OpenTelemetry helm 리포지토리를 추가하십시오**
>
> 공식 OpenTelemetry Helm 차트를 사용하여 관리형 텔레메트리 엔드포인트로 로그와 메트릭을 전송하는 collector를 배포하십시오.
>
> 차트 리포지토리를 추가하고 인덱스를 갱신하십시오.
>
> ```shell theme={null}
> helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
> helm repo update open-telemetry
> ```
>
> **4. Kubernetes collector 구성 요소 배포**
>
> 클러스터 자체와 각 노드에서 로그와 메트릭을 모두 수집하려면, 각각 별도의 Helm 값 파일을 사용하는 두 개의 OpenTelemetry 수집기를 배포해야 합니다. 제공된 두 파일인 `k8s_deployment.yaml`과 `k8s_daemonset.yaml`은 함께 동작하여 Kubernetes 클러스터에서 포괄적인 텔레메트리 데이터를 수집합니다.
>
> * `k8s_deployment.yaml`은 **클러스터 전체 이벤트와 메타데이터**를 수집하는 **단일 OpenTelemetry Collector 인스턴스**를 배포합니다. 이 collector는 Kubernetes 이벤트와 클러스터 메트릭을 수집하고, 파드 레이블과 어노테이션으로 텔레메트리 데이터를 보강합니다. 데이터 중복을 방지하기 위해 이 collector는 레플리카 1개로 구성된 독립형 배포로 실행됩니다.
>
> * `k8s_daemonset.yaml`은 클러스터의 모든 노드에서 실행되는 **데몬셋 기반 collector**를 배포합니다. 이 collector는 `kubeletstats`, `hostmetrics`, Kubernetes Attribute Processor 등의 구성 요소를 사용하여 **노드 수준 및 파드 수준 메트릭**과 컨테이너 로그를 수집합니다. 또한 로그를 메타데이터로 보강한 후 OTLP HTTP 익스포터를 통해 관리형 텔레메트리 엔드포인트로 전송합니다.
>
> 두 collector 모두 데이터를 ClickHouse Observability로 직접 내보냅니다. 단일 노드 클러스터에서는 이 구성으로 collector 파드 2개가 생성됩니다. 또한 배포(Deployment)는 데모에서 생성되는 OTLP 애플리케이션 로그, 메트릭, 트레이스도 수신합니다.
>
> 아래 명령어는 각 collector를 설치하기 전에 해당 Helm 값 파일을 다운로드합니다. 각 명령어 아래의 구성을 펼쳐 내용을 확인하십시오. 이 예시에서는 Helm 차트 `0.175.0`과 Collector `0.161.0`을 사용합니다.
>
> 먼저 collector를 배포(Deployment)로 설치합니다:
>
> ```shell theme={null}
> curl -fSL -o k8s_deployment.yaml \
>   https://raw.githubusercontent.com/ClickHouse/ClickHouse/master/docs/clickstack/observability/example-datasets/_snippets/k8s_deployment.yaml
>
> helm install --namespace otel-collectors k8s-otel-deployment open-telemetry/opentelemetry-collector \
>   --version 0.175.0 -f k8s_deployment.yaml
> ```
>
> > [accordion] k8s\_deployment.yaml
> >
> > ```yaml theme={null}
> > # k8s_deployment.yaml
> > mode: deployment
> >
> > image:
> >   repository: otel/opentelemetry-collector-contrib
> >   tag: 0.161.0
> >
> > # We only want one of these collectors - any more and we'd produce duplicate data
> > replicaCount: 1
> >
> > presets:
> >   kubernetesAttributes:
> >     enabled: true
> >     # When enabled, the processor will extract all labels for an associated pod and add them as resource attributes.
> >     # The label's exact name will be the key.
> >     extractAllPodLabels: true
> >     # When enabled, the processor will extract all annotations for an associated pod and add them as resource attributes.
> >     # The annotation's exact name will be the key.
> >     extractAllPodAnnotations: true
> >   # Configures the collector to collect Kubernetes events.
> >   # Adds the k8sobject receiver to the logs pipeline and collects Kubernetes events by default.
> >   # More Info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubernetes-objects-receiver
> >   kubernetesEvents:
> >     enabled: true
> >   # Configures the Kubernetes Cluster Receiver to collect cluster-level metrics.
> >   # Adds the k8s_cluster receiver to the metrics pipeline and adds the necessary rules to ClusterRole.
> >   # More Info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubernetes-cluster-receiver
> >   clusterMetrics:
> >     enabled: true
> >
> > extraEnvs:
> >   - name: HYPERDX_API_KEY
> >     valueFrom:
> >       secretKeyRef:
> >         name: hyperdx-secret
> >         key: HYPERDX_API_KEY
> >   - name: YOUR_OTEL_COLLECTOR_ENDPOINT
> >     valueFrom:
> >       configMapKeyRef:
> >         name: otel-config-vars
> >         key: YOUR_OTEL_COLLECTOR_ENDPOINT
> >
> > config:
> >   exporters:
> >     otlp_http:
> >       endpoint: "${env:YOUR_OTEL_COLLECTOR_ENDPOINT}"
> >       compression: gzip
> >       headers:
> >         authorization: "Bearer ${env:HYPERDX_API_KEY}"
> >   service:
> >     pipelines:
> >       logs:
> >         exporters:
> >           - otlp_http
> >       metrics:
> >         exporters:
> >           - otlp_http
> >       traces:
> >         exporters:
> >           - otlp_http
> >
> > resources:
> >   requests:
> >     cpu: 100m
> >     memory: 128Mi
> >   limits:
> >     memory: 512Mi
> > ```
>
> 다음으로, 노드 및 파드 수준의 메트릭과 로그를 수집하기 위해 collector를 데몬셋(DaemonSet)으로 배포합니다:
>
> ```shell theme={null}
> curl -fSL -o k8s_daemonset.yaml \
>   https://raw.githubusercontent.com/ClickHouse/ClickHouse/master/docs/clickstack/observability/example-datasets/_snippets/k8s_daemonset.yaml
>
> helm install --namespace otel-collectors k8s-otel-daemonset open-telemetry/opentelemetry-collector \
>   --version 0.175.0 -f k8s_daemonset.yaml
> ```
>
> > [accordion] k8s\_daemonset.yaml
> >
> > ```yaml theme={null}
> > # k8s_daemonset.yaml
> > mode: daemonset
> >
> > image:
> >   repository: otel/opentelemetry-collector-contrib
> >   tag: 0.161.0
> >
> > # Required to use the kubeletstats cpu/memory utilization metrics
> > clusterRole:
> >   create: true
> >   rules:
> >     - apiGroups:
> >         - ''
> >       resources:
> >         - nodes/proxy
> >       verbs:
> >         - get
> >
> > presets:
> >   logsCollection:
> >     enabled: true
> >   hostMetrics:
> >     enabled: true
> >   # Configures the Kubernetes Processor to add Kubernetes metadata.
> >   # Adds the k8sattributes processor to all the pipelines and adds the necessary rules to ClusterRole.
> >   # More Info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubernetes-attributes-processor
> >   kubernetesAttributes:
> >     enabled: true
> >     # When enabled, the processor will extract all labels for an associated pod and add them as resource attributes.
> >     # The label's exact name will be the key.
> >     extractAllPodLabels: true
> >     # When enabled, the processor will extract all annotations for an associated pod and add them as resource attributes.
> >     # The annotation's exact name will be the key.
> >     extractAllPodAnnotations: true
> >   # Configures the collector to collect node, pod, and container metrics from the kubelet API.
> >   # Adds the kubeletstats receiver to the metrics pipeline and adds the necessary rules to ClusterRole.
> >   # More Info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubeletstats-receiver
> >   kubeletMetrics:
> >     enabled: true
> >
> > extraEnvs:
> >   - name: HYPERDX_API_KEY
> >     valueFrom:
> >       secretKeyRef:
> >         name: hyperdx-secret
> >         key: HYPERDX_API_KEY
> >   - name: YOUR_OTEL_COLLECTOR_ENDPOINT
> >     valueFrom:
> >       configMapKeyRef:
> >         name: otel-config-vars
> >         key: YOUR_OTEL_COLLECTOR_ENDPOINT
> >
> > config:
> >   receivers:
> >     kubeletstats:
> >       insecure_skip_verify: true
> >   exporters:
> >     otlp_http:
> >       endpoint: "${env:YOUR_OTEL_COLLECTOR_ENDPOINT}"
> >       compression: gzip
> >       headers:
> >         authorization: "Bearer ${env:HYPERDX_API_KEY}"
> >
> >   service:
> >     pipelines:
> >       logs:
> >         exporters:
> >           - otlp_http
> >       metrics:
> >         exporters:
> >           - otlp_http
> >
> > resources:
> >   requests:
> >     cpu: 100m
> >     memory: 128Mi
> >   limits:
> >     memory: 512Mi
> > ```
>
> 로컬 클러스터에서는 노드 주소를 포함하지 않는 인증서를 사용할 수 있으므로, 데몬셋 예시에서는 로컬 큐블릿 연결에 `insecure_skip_verify: true`를 설정합니다. 운영 환경에서는 신뢰할 수 있는 큐블릿 인증서를 구성하고 인증서 검증을 활성화하십시오. 이 설정은 관리형 텔레메트리 엔드포인트에 대한 TLS 검증에는 영향을 주지 않습니다.
>
> collector가 준비되었는지 확인하세요:
>
> ```shell theme={null}
> kubectl get pods --namespace otel-collectors -l app.kubernetes.io/name=opentelemetry-collector
> kubectl logs --namespace otel-collectors -l app.kubernetes.io/name=opentelemetry-collector --prefix --tail=50
> ```
>
> 로그에 인증, 내보내기 또는 스크레이프 오류가 있는지 확인하십시오. 파드가 실행 중이라는 것만으로는 텔레메트리가 실제로 전달되었는지 보장할 수 없습니다.
>
> **5. 데모 애플리케이션 연결**
>
> 데모를 배포했다면 데모의 익스포터가 클러스터 내 collector를 가리키도록 설정하십시오. collector는 텔레메트리를 전달할 때 관리형 엔드포인트의 인증 헤더를 추가합니다.
>
> ```shell theme={null}
> kubectl set env deployment --namespace otel-demo \
>   -l app.kubernetes.io/part-of=opentelemetry-demo \
>   OTEL_COLLECTOR_NAME=k8s-otel-deployment-opentelemetry-collector.otel-collectors.svc.cluster.local
>
> kubectl rollout status deployment --namespace otel-demo \
>   -l app.kubernetes.io/part-of=opentelemetry-demo --timeout=10m
> ```
>
> 관리형 API Key는 위에서 구성한 대로 `otel-collectors` 네임스페이스에 두어야 합니다. 데모는 클러스터 내 수신기로 데이터를 전송하므로 이 키가 필요하지 않습니다.

> [tab] 자가 관리형
>
> ClickHouse와 관측성 UI는 ClickHouse Cloud에서 실행됩니다. 이 구성에서는 collector와 관련 구성 요소를 사용자의 Kubernetes 클러스터에 배포합니다.
>
> 다음 명령어는 `otel-demo` 네임스페이스를 사용합니다. 데모 배포를 건너뛰었다면 먼저 네임스페이스를 생성하십시오:
>
> ```shell theme={null}
> kubectl create namespace otel-demo
> ```
>
> **1. ClickStack Helm 차트 리포지토리를 추가하십시오**
>
> collector와 관련 구성 요소는 [공식 Helm 차트](https://clickhouse.com/docs/ko/clickstack/deployment/helm.md)를 사용하여 배포합니다.
>
> 이를 위해 먼저 HyperDX Helm 리포지토리를 추가해야 합니다.
>
> ```shell theme={null}
> helm repo add hyperdx https://hyperdxio.github.io/helm-charts
> helm repo update
> ```
>
> **2. collector 및 보조 구성 요소 배포**
>
> Helm 차트를 설치했으면 데이터베이스로 ClickHouse Cloud를 사용하도록 하여 collector와 관련 지원 구성 요소를 클러스터에 배포하십시오.
>
> 차트를 배포하고 [포함된 ClickHouse를 비활성화하십시오](https://clickhouse.com/docs/ko/clickstack/deployment/helm.md#using-clickhouse-cloud).
>
> > [!NOTE]
> >
> > 현재 이 차트는 항상 ClickStack UI와 MongoDB를 함께 배포합니다. 이러한 구성 요소는 별도의 액세스 경로를 제공하지만, ClickHouse Cloud 인증과는 통합되어 있지 않습니다. 이 배포 모델에서 해당 구성 요소는 관리자 전용으로, 배포된 OTel collector를 통해 데이터를 수집하는 데 필요한 [보안 수집 키에 대한 액세스를 제공](#retrieve-ingestion-api-key-self-configured)하는 용도이며, 최종 사용자에게 노출해서는 안 됩니다.
>
> ```shell theme={null}
> # specify ClickHouse Cloud credentials
> export CLICKHOUSE_URL=<CLICKHOUSE_CLOUD_URL> # full https url
> export CLICKHOUSE_USER=<CLICKHOUSE_USER>
> export CLICKHOUSE_PASSWORD=<CLICKHOUSE_PASSWORD>
>
> helm install my-hyperdx hyperdx/hdx-oss-v2 --version 0.8.4 --set clickhouse.enabled=false --set clickhouse.persistence.enabled=false --set otel.clickhouseEndpoint=${CLICKHOUSE_URL} --set clickhouse.config.users.otelUserName=${CLICKHOUSE_USER} --set clickhouse.config.users.otelUserPassword=${CLICKHOUSE_PASSWORD} --set global.storageClassName="standard-rwo" -n otel-demo
> ```
>
> 배포 상태를 확인하려면 다음 명령을 실행하여 모든 구성 요소가 `Running` 상태인지 확인하십시오. ClickHouse는 ClickHouse Cloud에서 실행되므로 파드 목록에 나타나지 않습니다:
>
> ```shell theme={null}
> kubectl get pods -l "app.kubernetes.io/name=hdx-oss-v2" -n otel-demo
>
> NAME                                                    READY   STATUS    RESTARTS   AGE
> my-hyperdx-hdx-oss-v2-app-78876d79bb-565tb              1/1     Running   0          14m
> my-hyperdx-hdx-oss-v2-mongodb-984845f96-czb6m           1/1     Running   0          14m
> my-hyperdx-hdx-oss-v2-otel-collector-64cf698f5c-8s7qj   1/1     Running   0          14m
> ```
>
> **3. ClickStack UI에 액세스**
>
> > [!NOTE]
> >
> > ClickHouse Observability — Self-managed를 사용하더라도 Kubernetes 클러스터에 배포된 로컬 ClickStack UI 인스턴스는 여전히 필요합니다. 이 인스턴스는 ClickStack UI에 번들로 포함된 OpAMP 서버가 관리하는 수집 키를 제공하며, 이 키로 배포된 OTel collector를 통한 수집을 보호합니다. 이 기능은 현재 ClickHouse Observability — Self-managed에서 제공되지 않습니다.
>
> 보안을 위해 이 서비스는 `ClusterIP`를 사용하며, 기본적으로 외부에 노출되지 않습니다.
>
> ClickStack UI에 액세스하려면 포트 3000을 로컬 포트 8080으로 포워딩하십시오.
>
> ```shell theme={null}
> kubectl port-forward \
>  deployment/my-hyperdx-hdx-oss-v2-app \
>   8080:3000 \
>  -n otel-demo
> ```
>
> ClickStack UI에 액세스하려면 [http://localhost:8080](http://localhost:8080)으로 이동하십시오.
>
> 복잡성 요구 사항을 충족하는 사용자 이름과 비밀번호를 입력하여 사용자를 생성하십시오.
>
> **4. 수집 API key 가져오기**
>
> ClickStack 수집기가 배포한 OTel collector로의 수집은 수집 키로 보호됩니다.
>
> [`Team Settings`](http://localhost:8080/team)로 이동한 후 `API Keys` 섹션에서 `Ingestion API Key`를 복사하십시오. 이 API Key를 사용하면 OpenTelemetry collector를 통한 데이터 수집이 안전하게 이루어집니다.
>
> **5. API Key용 Kubernetes 시크릿 생성**
>
> 수집 API Key를 담은 새 Kubernetes 시크릿과, ClickStack Helm 차트로 배포한 OTel collector의 위치 정보를 담은 ConfigMap을 생성하십시오. 이후 배포하는 구성 요소는 이를 사용해 ClickStack Helm 차트로 배포한 collector로 데이터를 수집할 수 있습니다:
>
> ```shell theme={null}
> # create secret with the ingestion API key
> kubectl create secret generic hyperdx-secret \
> --from-literal=HYPERDX_API_KEY=<ingestion_api_key> \
> -n otel-demo
>
> # create a ConfigMap pointing to the ClickStack OTel collector deployed above
> kubectl create configmap -n=otel-demo otel-config-vars --from-literal=YOUR_OTEL_COLLECTOR_ENDPOINT=http://my-hyperdx-hdx-oss-v2-otel-collector:4318
> ```
>
> 데모를 배포했다면 데모의 collector 서비스 이름을 이 Helm 배포에 맞게 업데이트하십시오. 환경을 업데이트하면 애플리케이션 파드도 재시작되어 수집 키가 적용됩니다.
>
> ```shell theme={null}
> kubectl set env deployment --namespace otel-demo \
>   -l app.kubernetes.io/part-of=opentelemetry-demo \
>   OTEL_COLLECTOR_NAME=my-hyperdx-hdx-oss-v2-otel-collector
>
> kubectl rollout status deployment --namespace otel-demo \
>   -l app.kubernetes.io/part-of=opentelemetry-demo --timeout=10m
> ```
>
> 데모 애플리케이션의 익스포터는 이 서비스 이름을 사용하여 collector에 연결합니다. 자체 애플리케이션은 OTLP 엔드포인트와 수신기 인증을 별도로 구성하십시오.
>
> **6. OpenTelemetry helm 리포지토리를 추가하십시오**
>
> Kubernetes 메트릭을 수집하기 위해 표준 OTel collector를 배포하고, 앞서 생성한 수집 API key를 사용하여 ClickStack 수집기로 데이터를 안전하게 전송하도록 구성합니다.
>
> 이를 위해 먼저 OpenTelemetry Helm 리포지토리를 추가해야 합니다:
>
> ```shell theme={null}
> # Add Otel Helm repo
> helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
> ```
>
> **7. Kubernetes collector 구성 요소 배포**
>
> 클러스터 자체와 각 노드 모두에서 로그와 메트릭을 수집하려면 서로 다른 OpenTelemetry collector 2개를 각각 별도의 매니페스트로 배포해야 합니다. 제공되는 두 매니페스트인 `k8s_deployment.yaml`과 `k8s_daemonset.yaml`은 함께 작동하여 Kubernetes 클러스터에서 포괄적인 텔레메트리 데이터를 수집합니다.
>
> * `k8s_deployment.yaml`은 **클러스터 전체 이벤트와 메타데이터** 수집을 담당하는 **단일 OpenTelemetry Collector 인스턴스**를 배포합니다. 이 collector는 Kubernetes 이벤트와 클러스터 메트릭을 수집하고, 파드 레이블과 어노테이션으로 텔레메트리 데이터를 보강합니다. 데이터 중복을 방지하기 위해 이 collector는 레플리카 1개로 구성된 독립형 배포로 실행됩니다.
>
> * `k8s_daemonset.yaml`은 클러스터의 모든 노드에서 실행되는 **데몬셋 기반 collector**를 배포합니다. 이 collector는 `kubeletstats`, `hostmetrics`, Kubernetes Attribute Processor 등의 구성 요소를 사용하여 **노드 수준 및 파드 수준 메트릭**과 컨테이너 로그를 수집합니다. 이 collector들은 로그를 메타데이터로 보강한 후 OTLP 익스포터를 통해 ClickStack으로 전송합니다.
>
> 이러한 매니페스트를 함께 사용하면 인프라부터 애플리케이션 수준의 텔레메트리까지 클러스터 전반에 걸친 풀스택 관측성을 확보할 수 있으며, 보강된 데이터를 서비스로 전송하여 중앙에서 분석할 수 있습니다.
>
> 먼저 collector를 배포(Deployment)로 설치합니다:
>
> ```shell theme={null}
> # download manifest file
> curl -O https://raw.githubusercontent.com/ClickHouse/clickhouse-docs/refs/heads/main/docs/use-cases/observability/clickstack/example-datasets/_snippets/k8s_deployment.yaml
> # install the helm chart
> helm install --namespace otel-demo k8s-otel-deployment open-telemetry/opentelemetry-collector -f k8s_deployment.yaml
> ```
>
> > [accordion] k8s\_deployment.yaml
> >
> > ```yaml theme={null}
> > # k8s_deployment.yaml
> > mode: deployment
> >
> > image:
> >   repository: otel/opentelemetry-collector-contrib
> >   tag: 0.123.0
> >
> > # We only want one of these collectors - any more and we'd produce duplicate data
> > replicaCount: 1
> >
> > presets:
> >   kubernetesAttributes:
> >     enabled: true
> >     # When enabled, the processor will extract all labels for an associated pod and add them as resource attributes.
> >     # The label's exact name will be the key.
> >     extractAllPodLabels: true
> >     # When enabled, the processor will extract all annotations for an associated pod and add them as resource attributes.
> >     # The annotation's exact name will be the key.
> >     extractAllPodAnnotations: true
> >   # Configures the collector to collect Kubernetes events.
> >   # Adds the k8sobject receiver to the logs pipeline and collects Kubernetes events by default.
> >   # More Info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubernetes-objects-receiver
> >   kubernetesEvents:
> >     enabled: true
> >   # Configures the Kubernetes Cluster Receiver to collect cluster-level metrics.
> >   # Adds the k8s_cluster receiver to the metrics pipeline and adds the necessary rules to ClusteRole.
> >   # More Info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubernetes-cluster-receiver
> >   clusterMetrics:
> >     enabled: true
> >
> > extraEnvs:
> >   - name: HYPERDX_API_KEY
> >     valueFrom:
> >       secretKeyRef:
> >         name: hyperdx-secret
> >         key: HYPERDX_API_KEY
> >         optional: true
> >   - name: YOUR_OTEL_COLLECTOR_ENDPOINT
> >     valueFrom:
> >       configMapKeyRef:
> >         name: otel-config-vars
> >         key: YOUR_OTEL_COLLECTOR_ENDPOINT
> >
> > config:
> >   exporters:
> >     otlphttp:
> >       endpoint: "${env:YOUR_OTEL_COLLECTOR_ENDPOINT}"
> >       compression: gzip
> >       headers:
> >         authorization: "${env:HYPERDX_API_KEY}"
> >   service:
> >     pipelines:
> >       logs:
> >         exporters:
> >           - otlphttp
> >       metrics:
> >         exporters:
> >           - otlphttp
> > ```
>
> 다음으로, 노드 및 파드 수준의 메트릭과 로그를 수집하기 위해 collector를 데몬셋(DaemonSet)으로 배포합니다:
>
> ```shell theme={null}
> # download manifest file
> curl -O https://raw.githubusercontent.com/ClickHouse/clickhouse-docs/refs/heads/main/docs/use-cases/observability/clickstack/example-datasets/_snippets/k8s_daemonset.yaml
> # install the helm chart
> helm install --namespace otel-demo k8s-otel-daemonset open-telemetry/opentelemetry-collector -f k8s_daemonset.yaml
> ```
>
> > [accordion] k8s\_daemonset.yaml
> >
> > ```yaml theme={null}
> > # k8s_daemonset.yaml
> > mode: daemonset
> >
> > image:
> >   repository: otel/opentelemetry-collector-contrib
> >   tag: 0.123.0
> >
> > # Required to use the kubeletstats cpu/memory utilization metrics
> > clusterRole:
> >   create: true
> >   rules:
> >     - apiGroups:
> >         - ''
> >       resources:
> >         - nodes/proxy
> >       verbs:
> >         - get
> >
> > presets:
> >   logsCollection:
> >     enabled: true
> >   hostMetrics:
> >     enabled: true
> >   # Configures the Kubernetes Processor to add Kubernetes metadata.
> >   # Adds the k8sattributes processor to all the pipelines and adds the necessary rules to ClusterRole.
> >   # More Info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubernetes-attributes-processor
> >   kubernetesAttributes:
> >     enabled: true
> >     # When enabled, the processor will extract all labels for an associated pod and add them as resource attributes.
> >     # The label's exact name will be the key.
> >     extractAllPodLabels: true
> >     # When enabled, the processor will extract all annotations for an associated pod and add them as resource attributes.
> >     # The annotation's exact name will be the key.
> >     extractAllPodAnnotations: true
> >   # Configures the collector to collect node, pod, and container metrics from the API server on a kubelet..
> >   # Adds the kubeletstats receiver to the metrics pipeline and adds the necessary rules to ClusterRole.
> >   # More Info: https://opentelemetry.io/docs/kubernetes/collector/components/#kubeletstats-receiver
> >   kubeletMetrics:
> >     enabled: true
> >
> > extraEnvs:
> >   - name: HYPERDX_API_KEY
> >     valueFrom:
> >       secretKeyRef:
> >         name: hyperdx-secret
> >         key: HYPERDX_API_KEY
> >         optional: true
> >   - name: YOUR_OTEL_COLLECTOR_ENDPOINT
> >     valueFrom:
> >       configMapKeyRef:
> >         name: otel-config-vars
> >         key: YOUR_OTEL_COLLECTOR_ENDPOINT
> >
> > config:
> >   receivers:
> >     # Configures additional kubelet metrics
> >     kubeletstats:
> >       collection_interval: 20s
> >       auth_type: 'serviceAccount'
> >       endpoint: '${env:K8S_NODE_NAME}:10250'
> >       insecure_skip_verify: true
> >       metrics:
> >         k8s.pod.cpu_limit_utilization:
> >           enabled: true
> >         k8s.pod.cpu_request_utilization:
> >           enabled: true
> >         k8s.pod.memory_limit_utilization:
> >           enabled: true
> >         k8s.pod.memory_request_utilization:
> >           enabled: true
> >         k8s.pod.uptime:
> >           enabled: true
> >         k8s.node.uptime:
> >           enabled: true
> >         k8s.container.cpu_limit_utilization:
> >           enabled: true
> >         k8s.container.cpu_request_utilization:
> >           enabled: true
> >         k8s.container.memory_limit_utilization:
> >           enabled: true
> >         k8s.container.memory_request_utilization:
> >           enabled: true
> >         container.uptime:
> >           enabled: true
> >
> >   exporters:
> >     otlphttp:
> >       endpoint: "${env:YOUR_OTEL_COLLECTOR_ENDPOINT}"
> >       compression: gzip
> >       headers:
> >         authorization: "${env:HYPERDX_API_KEY}"
> >
> >   service:
> >     pipelines:
> >       logs:
> >         exporters:
> >           - otlphttp
> >       metrics:
> >         exporters:
> >           - otlphttp
> > ```

## Kubernetes 데이터 탐색

ClickHouse Observability 서비스를 엽니다. [검색](https://clickhouse.com/docs/ko/clickstack/observability/features/search.md)에서 **로그** 소스를 선택하고, collector가 실행 중이던 시점이 포함된 시간 범위를 선택합니다. 워크로드에서 생성된 로그 메시지를 하나 찾아 `k8s.namespace.name`, `k8s.pod.name` 등의 Kubernetes 리소스 속성을 확인하십시오.

아래 예시는 로컬 Kubernetes 클러스터의 로그로, `Kubernetes documentation test` 메시지를 출력하는 `sample-logs` 워크로드가 포함되어 있습니다. 서비스 이름과 로그 메시지는 실제 워크로드에 따라 달라집니다.

![로컬 클러스터에서 수집된 샘플 워크로드 및 Kubernetes 시스템 로그를 보여 주는 검색 화면](https://mintcdn.com/private-7c7dfe99/Zk1feNn6fCQBpold/images/clickstack/getting-started/observability-kubernetes-logs.png?fit=max\&auto=format\&n=Zk1feNn6fCQBpold\&q=85\&s=e07a2339b917a09a36d514f35c58658a)

**차트 탐색기**에서 **Time Series**와 **메트릭** 소스를 선택합니다. `k8s.pod.memory.usage`의 **Average**를 선택하고 `ResourceAttributes['k8s.pod.name']` 기준으로 그룹화한 뒤, **Delta**는 선택 해제된 상태로 둡니다. collector가 실행 중이던 시점이 포함된 시간 범위를 선택한 다음 **실행**을 클릭하여 파드별 메모리 사용량(memory usage)을 비교합니다. 차트에 빈 구간이 있으면 시간 세분화 수준을 수집 인터벌 이상으로 설정하십시오.

![파드 이름별로 그룹화된 Kubernetes 파드 평균 메모리 사용량을 보여 주는 차트 탐색기](https://mintcdn.com/private-7c7dfe99/Zk1feNn6fCQBpold/images/clickstack/getting-started/observability-kubernetes-metrics.png?fit=max\&auto=format\&n=Zk1feNn6fCQBpold\&q=85\&s=ff2698712a19fb9cd35f7d36e979534a)

사전 구성된 Kubernetes 대시보드를 살펴보려면 사이드바에서 **대시보드**를 열고 **Preset 대시보드** 아래의 **Kubernetes**를 선택합니다. **로그** 및 **메트릭** 소스를 선택하고, collector가 실행 중이던 시점이 포함된 시간 범위를 선택하십시오.

**파드**, **노드**, **네임스페이스** 탭에서 클러스터를 탐색할 수 있습니다. 파드, 배포, 노드, 네임스페이스, 클러스터 필터로 표시 범위를 좁힐 수도 있습니다.

![파드 CPU 및 메모리 사용량, 파드 상태, Kubernetes 경고 이벤트를 보여 주는 Kubernetes 대시보드](https://mintcdn.com/private-7c7dfe99/Zk1feNn6fCQBpold/images/clickstack/getting-started/observability-kubernetes-dashboard.png?fit=max\&auto=format\&n=Zk1feNn6fCQBpold\&q=85\&s=e81a725f8f2186f60f26397d46fc4fed)
