

 **이 페이지 개선에 도움 주기** 

이 사용자 가이드에 기여하려면 모든 페이지의 오른쪽 창에 있는 **GitHub에서 이 페이지 편집** 링크를 선택합니다.

# 컨트롤 플레인 원시 지표를 Prometheus 형식으로 가져오기
<a name="view-raw-metrics"></a>

Kubernetes 컨트롤 플레인은 [Prometheus 형식](https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md)으로 표시되는 여러 지표를 노출합니다. 이러한 지표는 모니터링 및 분석에 유용합니다. 지표 엔드포인트를 통해 내부적으로 노출되며 Prometheus를 완전히 배포하지 않고도 액세스할 수 있습니다. 그러나 Prometheus를 더 쉽게 배포하면 시간 경과에 따른 지표를 분석할 수 있습니다.

원시 지표 출력을 보려면 `endpoint`를 바꾸고 다음 명령을 실행합니다.

```
kubectl get --raw endpoint
```

이 명령을 사용하면 엔드포인트 경로를 전달할 수 있으며 원시 응답이 반환됩니다. 출력에 다양한 지표가 줄별로 나열되며 각 줄에는 지표 이름, 태그, 값이 포함됩니다.

```
metric_name{tag="value"[,...]} value
```

## API 서버에서 지표 가져오기
<a name="fetch-metrics"></a>

일반 API 서버 엔드포인트는 Amazon EKS 컨트롤 플레인에 노출됩니다. 이 엔드포인트는 주로 특정 지표를 살펴보는 데 유용합니다.

```
kubectl get --raw /metrics
```

예제 출력은 다음과 같습니다.

```
[...]
# HELP rest_client_requests_total Number of HTTP requests, partitioned by status code, method, and host.
# TYPE rest_client_requests_total counter
rest_client_requests_total{code="200",host="127.0.0.1:21362",method="POST"} 4994
rest_client_requests_total{code="200",host="127.0.0.1:443",method="DELETE"} 1
rest_client_requests_total{code="200",host="127.0.0.1:443",method="GET"} 1.326086e+06
rest_client_requests_total{code="200",host="127.0.0.1:443",method="PUT"} 862173
rest_client_requests_total{code="404",host="127.0.0.1:443",method="GET"} 2
rest_client_requests_total{code="409",host="127.0.0.1:443",method="POST"} 3
rest_client_requests_total{code="409",host="127.0.0.1:443",method="PUT"} 8
# HELP ssh_tunnel_open_count Counter of ssh tunnel total open attempts
# TYPE ssh_tunnel_open_count counter
ssh_tunnel_open_count 0
# HELP ssh_tunnel_open_fail_count Counter of ssh tunnel failed open attempts
# TYPE ssh_tunnel_open_fail_count counter
ssh_tunnel_open_fail_count 0
```

이 원시 출력은 API 서버가 표시하는 축자를 반환합니다.

## `metrics.eks.amazonaws.com`의 컨트롤 플레인 지표 가져오기
<a name="fetch-metrics-prometheus"></a>

Kubernetes 버전 `1.28` 이상인 클러스터의 경우 Amazon EKS는 API 그룹 `metrics.eks.amazonaws.com`에도 지표를 공개합니다. 이러한 지표에는 `kube-scheduler` 및 `kube-controller-manager`와 같은 컨트롤 플레인 구성 요소가 포함됩니다.

**참고**  
클러스터에서 새 `APIService` 리소스 `v1.metrics.eks.amazonaws.com`의 생성을 차단할 수 있는 웹후크 구성이 있는 경우 지표 엔드포인트 기능을 사용하지 못할 수 있습니다. `v1.metrics.eks.amazonaws.com` 키워드를 검색하여 `kube-apiserver` 감사 로그에서 확인할 수 있습니다.

### `kube-scheduler` 지표 가져오기
<a name="fetch-metrics-scheduler"></a>

다음 명령을 사용하여 `kube-scheduler` 지표를 검색합니다.

```
kubectl get --raw "/apis/metrics.eks.amazonaws.com/v1/ksh/container/metrics"
```

예제 출력은 다음과 같습니다.

```
# TYPE scheduler_pending_pods gauge
scheduler_pending_pods{queue="active"} 0
scheduler_pending_pods{queue="backoff"} 0
scheduler_pending_pods{queue="gated"} 0
scheduler_pending_pods{queue="unschedulable"} 18
# HELP scheduler_pod_scheduling_attempts [STABLE] Number of attempts to successfully schedule a pod.
# TYPE scheduler_pod_scheduling_attempts histogram
scheduler_pod_scheduling_attempts_bucket{le="1"} 79
scheduler_pod_scheduling_attempts_bucket{le="2"} 79
scheduler_pod_scheduling_attempts_bucket{le="4"} 79
scheduler_pod_scheduling_attempts_bucket{le="8"} 79
scheduler_pod_scheduling_attempts_bucket{le="16"} 79
scheduler_pod_scheduling_attempts_bucket{le="+Inf"} 81
[...]
```

잠재적으로 많은 데이터가 반환되므로 `kube_pod_resource_request` 및 `kube_pod_resource_limit` 지표를 검색하기 위한 추가 `kube-scheduler` 지표 엔드포인트가 있습니다. 이러한 지표를 검색하려면 다음 명령을 사용합니다.

```
kubectl get --raw "/apis/metrics.eks.amazonaws.com/v1/ksh/container/resourcemetrics"
```

예제 출력은 다음과 같습니다.

```
# HELP kube_pod_resource_limit [STABLE] Resources limit for workloads on the cluster, broken down by pod. This shows the resource usage the scheduler and kubelet expect per pod for resources along with the unit for the resource if any.
# TYPE kube_pod_resource_limit gauge
kube_pod_resource_limit{namespace="kube-system",node="ip-192-168-87-3.us-west-2.compute.internal",pod="coredns-7bf648ff5d-dj4ss",priority="2000000000",resource="memory",scheduler="default-scheduler",unit="bytes"} 1.7825792e+08
# HELP kube_pod_resource_request [STABLE] Resources requested by workloads on the cluster, broken down by pod. This shows the resource usage the scheduler and kubelet expect per pod for resources along with the unit for the resource if any.
# TYPE kube_pod_resource_request gauge
kube_pod_resource_request{namespace="kube-system",node="ip-192-168-87-3.us-west-2.compute.internal",pod="aws-node-x7znh",priority="2000001000",resource="cpu",scheduler="default-scheduler",unit="cores"} 0.05
kube_pod_resource_request{namespace="kube-system",node="ip-192-168-87-3.us-west-2.compute.internal",pod="coredns-7bf648ff5d-dj4ss",priority="2000000000",resource="cpu",scheduler="default-scheduler",unit="cores"} 0.1
[...]
```

### `kube-controller-manager` 지표 가져오기
<a name="fetch-metrics-controller"></a>

다음 명령을 사용하여 `kube-controller-manager` 지표를 검색합니다.

```
kubectl get --raw "/apis/metrics.eks.amazonaws.com/v1/kcm/container/metrics"
```

예제 출력은 다음과 같습니다.

```
[...]
workqueue_work_duration_seconds_sum{name="pvprotection"} 0
workqueue_work_duration_seconds_count{name="pvprotection"} 0
workqueue_work_duration_seconds_bucket{name="replicaset",le="1e-08"} 0
workqueue_work_duration_seconds_bucket{name="replicaset",le="1e-07"} 0
workqueue_work_duration_seconds_bucket{name="replicaset",le="1e-06"} 0
workqueue_work_duration_seconds_bucket{name="replicaset",le="9.999999999999999e-06"} 0
workqueue_work_duration_seconds_bucket{name="replicaset",le="9.999999999999999e-05"} 19
workqueue_work_duration_seconds_bucket{name="replicaset",le="0.001"} 109
workqueue_work_duration_seconds_bucket{name="replicaset",le="0.01"} 139
workqueue_work_duration_seconds_bucket{name="replicaset",le="0.1"} 181
workqueue_work_duration_seconds_bucket{name="replicaset",le="1"} 191
workqueue_work_duration_seconds_bucket{name="replicaset",le="10"} 191
workqueue_work_duration_seconds_bucket{name="replicaset",le="+Inf"} 191
workqueue_work_duration_seconds_sum{name="replicaset"} 4.265655885000002
[...]
```

### 스케줄러 및 컨트롤러 관리자 지표 이해
<a name="scheduler-controller-metrics"></a>

다음 표에서는 Prometheus 스타일 스크레이핑에 사용할 수 있는 스케줄러 및 컨트롤러 관리자 지표를 설명합니다. 이러한 지표에 대한 자세한 내용은 Kubernetes Documentation의 [Kubernetes Metrics Reference](https://kubernetes.io/docs/reference/instrumentation/metrics/)를 참조하세요.


| 지표 | 컨트롤 플레인 구성 요소 | 설명 | 
| --- | --- | --- | 
| scheduler\_pending\_pods | scheduler | 실행을 위해 노드에 예약되기를 기다리는 포드 수입니다. | 
| scheduler\_schedule\_attempts\_total | scheduler | 포드를 예약하기 위해 시도한 횟수입니다. | 
| scheduler\_preemption\_attempts\_total | scheduler | 우선순위가 낮은 포드를 제거하여 우선순위가 높은 포드를 예약하기 위해 스케줄러가 시도한 횟수입니다. | 
| scheduler\_preemption\_victims | scheduler | 우선순위가 더 높은 포드를 위한 공간을 만들기 위해 제거하기로 선택한 포드 수입니다. | 
| scheduler\_pod\_scheduling\_attempts | scheduler | 포드를 성공적으로 예약하기 위해 시도한 횟수입니다. | 
| scheduler\_scheduling\_attempt\_duration\_seconds | scheduler | 스케줄러가 리소스 가용성 및 예약 규칙과 같은 다양한 요인을 기반으로 포드를 실행할 적절한 위치를 얼마나 빨리 또는 느리게 찾을 수 있는지를 나타냅니다. | 
| scheduler\_pod\_scheduling\_sli\_duration\_seconds | scheduler | 포드가 예약 대기열에 진입한 시점부터 예약 중인 포드의 엔드 투 엔드 지연 시간입니다. 여기에는 여러 번의 예약 시도가 포함될 수 있습니다. | 
| kube\_pod\_resource\_limit | scheduler | 클러스터의 워크로드에 대한 리소스 제한으로, 포드별로 분류됩니다. 이는 리소스에 대해 포드당 스케줄러와 kubelet이 예상하는 리소스 사용량과 함께 리소스의 단위가 있는 경우 이를 보여줍니다. | 
| kube\_pod\_resource\_request | scheduler | 클러스터의 워크로드에서 요청한 리소스로, 포드별로 분류됩니다. 이는 리소스에 대해 포드당 스케줄러와 kubelet이 예상하는 리소스 사용량과 함께 리소스의 단위가 있는 경우 이를 보여줍니다. | 
| cronjob\_controller\_job\_creation\_skew\_duration\_seconds | 컨트롤러 관리자 | cronjob이 실행되도록 예약된 시점과 해당 작업이 생성된 시점 사이의 시간입니다. | 
| workqueue\_depth | 컨트롤러 관리자 | 현재 대기열 깊이입니다. | 
| workqueue\_adds\_total | 컨트롤러 관리자 | 작업 대기열에서 처리한 총 추가 수입니다. | 
| workqueue\_queue\_duration\_seconds | 컨트롤러 관리자 | 항목이 요청되기 전에 작업 대기열에 남아 있는 시간(초)입니다. | 
| workqueue\_work\_duration\_seconds | 컨트롤러 관리자 | 작업 대기열에서 항목을 처리하는 데 걸리는 시간(초)입니다. | 

## Prometheus 스크레이퍼를 배포하여 지표를 일관되게 스크레이핑
<a name="deploy-prometheus-scraper"></a>

Prometheus 스크레이퍼를 배포하여 지표를 일관되게 스크레이핑하려면 다음 구성을 사용합니다.

```
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-conf
data:
  prometheus.yml: |-
    global:
      scrape_interval: 30s
    scrape_configs:
    # apiserver metrics
    - job_name: apiserver-metrics
      kubernetes_sd_configs:
      - role: endpoints
      scheme: https
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        insecure_skip_verify: true
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      relabel_configs:
      - source_labels:
          [
            __meta_kubernetes_namespace,
            __meta_kubernetes_service_name,
            __meta_kubernetes_endpoint_port_name,
          ]
        action: keep
        regex: default;kubernetes;https
    # Scheduler metrics
    - job_name: 'ksh-metrics'
      kubernetes_sd_configs:
      - role: endpoints
      metrics_path: /apis/metrics.eks.amazonaws.com/v1/ksh/container/metrics
      scheme: https
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        insecure_skip_verify: true
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      relabel_configs:
      - source_labels:
          [
            __meta_kubernetes_namespace,
            __meta_kubernetes_service_name,
            __meta_kubernetes_endpoint_port_name,
          ]
        action: keep
        regex: default;kubernetes;https
    # Controller Manager metrics
    - job_name: 'kcm-metrics'
      kubernetes_sd_configs:
      - role: endpoints
      metrics_path: /apis/metrics.eks.amazonaws.com/v1/kcm/container/metrics
      scheme: https
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        insecure_skip_verify: true
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      relabel_configs:
      - source_labels:
          [
            __meta_kubernetes_namespace,
            __meta_kubernetes_service_name,
            __meta_kubernetes_endpoint_port_name,
          ]
        action: keep
        regex: default;kubernetes;https
---
apiVersion: v1
kind: Pod
metadata:
  name: prom-pod
spec:
  containers:
  - name: prom-container
    image: prom/prometheus
    ports:
    - containerPort: 9090
    volumeMounts:
    - name: config-volume
      mountPath: /etc/prometheus/
  volumes:
  - name: config-volume
    configMap:
      name: prometheus-conf
```

포드가 새 지표 엔드포인트에 액세스하려면 다음 권한이 필요합니다.

```
{
  "effect": "allow",
  "apiGroups": [
    "metrics.eks.amazonaws.com"
  ],
  "resources": [
    "kcm/metrics",
    "ksh/metrics"
  ],
  "verbs": [
    "get"
  ] },
```

사용 중인 역할을 패치하려면 다음 명령을 사용할 수 있습니다.

```
kubectl patch clusterrole <role-name> --type=json -p='[
  {
    "op": "add",
    "path": "/rules/-",
    "value": {
      "verbs": ["get"],
      "apiGroups": ["metrics.eks.amazonaws.com"],
      "resources": ["kcm/metrics", "ksh/metrics"]
    }
  }
]'
```

그런 다음 Prometheus 스크레이퍼의 포트를 로컬 포트로 프록시하여 Prometheus 대시보드를 볼 수 있습니다.

```
kubectl port-forward pods/prom-pod 9090:9090
```

Amazon EKS 클러스터의 경우 코어 Kubernetes 컨트롤 플레인 지표도 `AWS/EKS` 네임스페이스 아래의 Amazon CloudWatch 지표에 수집됩니다. 이를 보려면 [CloudWatch 콘솔](https://console.aws.amazon.com/cloudwatch/home#logs:prefix=/aws/eks)을 열고 왼쪽 탐색 창에서 **모든 지표**를 선택합니다. **지표** 선택 페이지에서 클러스터의 `AWS/EKS` 네임스페이스와 지표 차원을 선택합니다.