View a markdown version of this page

コントロールプレーンの未加工メトリクスを Prometheus 形式で取得する - Amazon EKS

このページの改善にご協力ください

このユーザーガイドに貢献するには、すべてのページの右側のペインにある「GitHub でこのページを編集する」リンクを選択してください。

コントロールプレーンの未加工メトリクスを Prometheus 形式で取得する

Kubernetes コントロールプレーンは、Prometheus 形式で表される多数のメトリクスを公開します。これらのメトリクスはモニタリングおよび分析に役立ちます。これらはメトリクスエンドポイントを通じて内部的に公開され、Prometheus を完全にデプロイしなくてもアクセスできます。ただし、Prometheus をデプロイすることで、時間の経過に伴うメトリクスの分析がより簡単になります。

未加工メトリクス出力を表示するには、endpointを置き換えて次のコマンドを実行してください。

kubectl get --raw endpoint

このコマンドを使用すると、任意のエンドポイントパスを渡して未加工のレスポンスを返すことができます。出力にはさまざまなメトリクスが行ごとにリストされ、各行にはメトリクス名、タグ、および値が含まれます。

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

API サーバーからメトリクスを取得する

一般的な 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 を使用してコントロールプレーンのメトリクスを取得する

Kubernete バージョン 1.28 以降のクラスターの場合、Amazon EKS は API グループ metrics.eks.amazonaws.com のメトリクスも公開します。これらのメトリクスにはkube-schedulerkube-controller-manager などのコントロールプレーンコンポーネントが含まれます。

注記

クラスターに新しい APIService リソース v1.metrics.eks.amazonaws.com の作成をブロックするウェブフック設定がある場合、メトリクスエンドポイント機能が使用できない可能性があります。v1.metrics.eks.amazonaws.com キーワードを検索することで、kube-apiserver 監査ログで確認することができます。

kube-scheduler メトリクスを取得する

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 メトリクスを取得する

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 [...]

スケジューラーとコントローラーマネージャーのメトリクスを理解します

Prometheus スタイルスクレイピングに使用できるスケジューラとコントローラーマネージャーのメトリクスを次の表に示します。これらのメトリクスの詳細については、Kubernetes ドキュメントの「Kubernetes Metrics Reference」を参照してください。

メトリクス コントロールプレーンのコンポーネント 説明

scheduler_pending_pods

スケジューラ

実行のためにノードにスケジュールされるのを待っているポッドの数です。

scheduler_schedule_attempts_total

スケジューラ

ポッドのスケジュールの試行回数です。

scheduler_preemption_attempts_total

スケジューラ

優先度の低いポッドをエビクションさせて、優先度の高いポッドをスケジュールするためにスケジューラーによって実行された試行回数です。

scheduler_preemption_victims

スケジューラ

優先順位の高いポッドのスペースを確保するためにエビクション対象として選択されたポッドの数です。

scheduler_pod_scheduling_attempts

スケジューラ

ポッドの正常なスケジュールの試行回数です。

scheduler_scheduling_attempt_duration_seconds

スケジューラ

リソースの可用性やスケジューリングルールなどのさまざまな要因に基づいて、スケジューラーがポッドを実行するのに適した場所をどの程度迅速に見つけることができるかを示します。

scheduler_pod_scheduling_sli_duration_seconds

スケジューラ

ポッドがスケジューリングキューに入る時点からの、スケジュールされているポッドのエンドツーエンドのレイテンシーです。これには複数のスケジューリング試行が含まれる場合があります。

kube_pod_resource_limit

スケジューラ

クラスター上のワークロードに対するリソース制限のポッド別の内訳です。これはスケジューラーと kubelet がリソースのポッドごとに想定するリソースの使用状況と、リソースの単位がある場合はそれを示します。

kube_pod_resource_request

スケジューラ

クラスター上のワークロードによってリクエストされリソースのポッド別の内訳です。これはスケジューラーと kubelet がリソースのポッドごとに想定するリソースの使用状況と、リソースの単位がある場合はそれを示します。

cronjob_controller_job_creation_skew_duration_seconds

コントローラーマネージャー

cronjob の実行がスケジュールされてから、対応するジョブが作成されるまでの時間です。

workqueue_depth

コントローラーマネージャー

現在のキューの深さです。

workqueue_adds_total

コントローラーマネージャー

ワークキューが処理する合計追加数。

workqueue_queue_duration_seconds

コントローラーマネージャー

項目がリクエストされる前にワークキューに留まる時間 (秒)です。

workqueue_work_duration_seconds

コントローラーマネージャー

ワークキューからの項目の処理にかかる時間 (秒)です。

プロメテウス スクレイパーをデプロイしてメトリクスを一貫してスクレイピングする

プロメテウス スクレイパーをデプロイしてメトリクスを一貫してスクレイピングするには次の設定を使用します:

--- 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 コンソールを開き、左側のナビゲーションペインから [すべてのメトリクス] を選択してください。[メトリクス] の選択ページで、クラスターの AWS/EKS 名前空間とメトリクスディメンションを選択してください。