【kube-capacity】Resource LimitとRequestを一覧で取得する
はじめに
kube-capacity
を使って、KubernetesのResource limitとrequestを一覧で取得したり、合計値を取得したりする方法を紹介します。
kube-capacityとは
kube-capacity
とは、Resource limitやrequest、その使用率などを取得できるCLIになります。
GitHub - robscott/kube-capacity: A simple CLI that provides an overview of the resource requests, limits, and utilization in a Kubernetes cluster
A simple CLI that provides an overview of the resource requests, limits, and utilization in a Kubernetes cluster - robscott/kube-capacity
インストール
brewを使ったインストールは下記の通りです。
1brew tap robscott/tap
2brew install robscott/tap/kube-capacity
krewを使ってもインストールできます。
1kubectl krew install resource-capacity
使い方
簡単にkube-capacity
の使い方を紹介します。
クラスタとノードのリソース
デフォルトでは、クラスタのResource limitとrequestの合計と各ノードのResource limitとrequestが表示されます。
1kube-capacity
1❯ kube-capacity
2
3NODE CPU REQUESTS CPU LIMITS MEMORY REQUESTS MEMORY LIMITS
4docker-desktop 1325m (33%) 375m (9%) 696Mi (8%) 596Mi (7%)
括弧の中のパーセント表示は利用可能なリソースと比べてどのくらいの割合であるかを表しています。
Podのリソース
-p
か--pods
でPodごとのResource limitとrequestも確認できます。
1kube-capacity -p
1❯ kube-capacity -p -n default
2NODE POD CPU REQUESTS CPU LIMITS MEMORY REQUESTS MEMORY LIMITS
3
4docker-desktop * 375m (9%) 375m (9%) 256Mi (3%) 256Mi (3%)
5docker-desktop myapp1-5cdd4bc574-4x2k4 225m (5%) 225m (5%) 160Mi (2%) 160Mi (2%)
6docker-desktop myapp2-d5b4df486-zqvtr 150m (3%) 150m (3%) 96Mi (1%) 96Mi (1%)
コンテナのリソース
-c
か--containers
でPodの中のコンテナごとのResource limitとrequestを確認できます。
1kube-capacity -c
1❯ kube-capacity -c -n default
2NODE POD CONTAINER CPU REQUESTS CPU LIMITS MEMORY REQUESTS MEMORY LIMITS
3
4docker-desktop * * 375m (9%) 375m (9%) 256Mi (3%) 256Mi (3%)
5docker-desktop myapp1-5cdd4bc574-4x2k4 * 225m (5%) 225m (5%) 160Mi (2%) 160Mi (2%)
6docker-desktop myapp1-5cdd4bc574-4x2k4 container1 50m (1%) 50m (1%) 32Mi (0%) 32Mi (0%)
7docker-desktop myapp1-5cdd4bc574-4x2k4 container2 100m (2%) 100m (2%) 64Mi (0%) 64Mi (0%)
8docker-desktop myapp1-5cdd4bc574-4x2k4 container3 75m (1%) 75m (1%) 64Mi (0%) 64Mi (0%)
9docker-desktop myapp2-d5b4df486-zqvtr * 150m (3%) 150m (3%) 96Mi (1%) 96Mi (1%)
10docker-desktop myapp2-d5b4df486-zqvtr container1 50m (1%) 50m (1%) 32Mi (0%) 32Mi (0%)
11docker-desktop myapp2-d5b4df486-zqvtr container2 100m (2%) 100m (2%) 64Mi (0%) 64Mi (0%)
利用状況
-u
か--util
でリソースの利用状況を確認できます。
1kube-capacity -u
1❯ kube-capacity -c -u -n default
2NODE POD CONTAINER CPU REQUESTS CPU LIMITS CPU UTIL MEMORY REQUESTS MEMORY LIMITS MEMORY UTIL
3
4docker-desktop * * 375m (9%) 375m (9%) 0m (0%) 256Mi (3%) 256Mi (3%) 1Mi (0%)
5docker-desktop myapp1-5cdd4bc574-4x2k4 * 225m (5%) 225m (5%) 0m (0%) 160Mi (2%) 160Mi (2%) 1Mi (0%)
6docker-desktop myapp1-5cdd4bc574-4x2k4 container1 50m (1%) 50m (1%) 0m (0%) 32Mi (0%) 32Mi (0%) 1Mi (0%)
7docker-desktop myapp1-5cdd4bc574-4x2k4 container2 100m (2%) 100m (2%) 0m (0%) 64Mi (0%) 64Mi (0%) 1Mi (0%)
8docker-desktop myapp1-5cdd4bc574-4x2k4 container3 75m (1%) 75m (1%) 0m (0%) 64Mi (0%) 64Mi (0%) 1Mi (0%)
9docker-desktop myapp2-d5b4df486-zqvtr * 150m (3%) 150m (3%) 0m (0%) 96Mi (1%) 96Mi (1%) 1Mi (0%)
10docker-desktop myapp2-d5b4df486-zqvtr container1 50m (1%) 50m (1%) 0m (0%) 32Mi (0%) 32Mi (0%) 1Mi (0%)
11docker-desktop myapp2-d5b4df486-zqvtr container2 100m (2%) 100m (2%) 0m (0%) 64Mi (0%) 64Mi (0%) 1Mi (0%)
利用可能なリソース
-a
か--available
でノードの利用可能なリソースを表示した形式になります。
1kube-capacity --available
1❯ kube-capacity -a
2NODE CPU REQUESTS CPU LIMITS MEMORY REQUESTS MEMORY LIMITS
3docker-desktop 2675m/4000m 3625m/4000m 7164Mi/7860Mi 7264Mi/7860Mi
ソート
--sort
で各リソースや名前でソートすることができます。(デフォルトは名前です)
1kube-capacity --sort [name|cpu.request|cpu.limit|cpu.util|mem.request|mem.limit|mem.util]
1❯ kube-capacity -c --sort cpu.limit -n default
2NODE POD CONTAINER CPU REQUESTS CPU LIMITS MEMORY REQUESTS MEMORY LIMITS
3
4docker-desktop * * 375m (9%) 375m (9%) 256Mi (3%) 256Mi (3%)
5docker-desktop myapp1-5cdd4bc574-4x2k4 * 225m (5%) 225m (5%) 160Mi (2%) 160Mi (2%)
6docker-desktop myapp1-5cdd4bc574-4x2k4 container2 100m (2%) 100m (2%) 64Mi (0%) 64Mi (0%)
7docker-desktop myapp1-5cdd4bc574-4x2k4 container3 75m (1%) 75m (1%) 64Mi (0%) 64Mi (0%)
8docker-desktop myapp1-5cdd4bc574-4x2k4 container1 50m (1%) 50m (1%) 32Mi (0%) 32Mi (0%)
9docker-desktop myapp2-d5b4df486-zqvtr * 150m (3%) 150m (3%) 96Mi (1%) 96Mi (1%)
10docker-desktop myapp2-d5b4df486-zqvtr container2 100m (2%) 100m (2%) 64Mi (0%) 64Mi (0%)
11docker-desktop myapp2-d5b4df486-zqvtr container1 50m (1%) 50m (1%) 32Mi (0%) 32Mi (0%)
Pod数
--pod-count
でクラスタやノードのPodの数を表示できます。
1kube-capacity --pod-count
1❯ kube-capacity --pod-count
2NODE CPU REQUESTS CPU LIMITS MEMORY REQUESTS MEMORY LIMITS POD COUNT
3docker-desktop 1325m (33%) 375m (9%) 696Mi (8%) 596Mi (7%) 12/110
参考
- robscott/kube-capacity: A simple CLI that provides an overview of the resource requests, limits, and utilization in a Kubernetes cluster
- How can I summarize all the resource limits and requests in Kubernetes with kubectl? - Stack Overflow