LoginSignup
3
3

More than 5 years have passed since last update.

kubectlでpod名のみの一覧を取得する方法

Posted at

pod名のみを取得したいときに、 kubectl get podsでは過分な情報を含むので、jsonpathでフィルターをする。

これを

$ kubectl get pods
NAME                                     READY   STATUS      RESTARTS   AGE
hoge-788cf54966-mdk2p                   1/1     Running     0          1h
fuga-788cf54966-ngh5w                   1/1     Running     0          2h

こう

$ kubectl get pods -o=jsonpath={.items[*].metadata.name}
hoge-788cf54966-mdk2p fuga-788cf54966-ngh5w

順番にshellで処理したいときはそのままforを使う

#!/bin/bash

for name in $(kubectl get pods -o=jsonpath={.items[*].metadata.name}); do
  echo ${name}
done
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3