2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

kubectl get pods でPod名だけを抜き出す2パターン

Posted at

通常のkubectl get pods の出力

$ kubectl get pod
NAME                             READY   STATUS    RESTARTS   AGE
details-v1-b649ff69-mdqg7        2/2     Running   0          20h
productpage-v1-64bc9d48c-lm4qr   2/2     Running   0          20h
ratings-v1-5fc49bf9cb-9bqwr      2/2     Running   0          20h
reviews-v1-7bcff9b8d6-w8x8r      2/2     Running   0          20h
reviews-v2-cf6f69b7d-gmzt9       2/2     Running   0          20h
reviews-v3-55c7b5f478-s85gb      2/2     Running   0          20h

シェルなどでこのPod名を再帰的に利用したくてPod名だけを抜き出す場合の2パターン。

kubectl get pods -o name

$ kubectl get pods -oname
pod/details-v1-b649ff69-mdqg7
pod/productpage-v1-64bc9d48c-lm4qr
pod/ratings-v1-5fc49bf9cb-9bqwr
pod/reviews-v1-7bcff9b8d6-w8x8r
pod/reviews-v2-cf6f69b7d-gmzt9
pod/reviews-v3-55c7b5f478-s85gb

このpod/を入れたくない場合はawkで整形する。

$ kubectl get pods -oname | awk -F '/' '{print $2}'
details-v1-b649ff69-mdqg7
productpage-v1-64bc9d48c-lm4qr
ratings-v1-5fc49bf9cb-9bqwr
reviews-v1-7bcff9b8d6-w8x8r
reviews-v2-cf6f69b7d-gmzt9
reviews-v3-55c7b5f478-s85gb

kubectl get pods -o jsonpath

$ kubectl get pods -n bookinfo -o jsonpath={.items..metadata.name}
details-v1-b649ff69-mdqg7 productpage-v1-64bc9d48c-lm4qr ratings-v1-5fc49bf9cb-9bqwr reviews-v1-7bcff9b8d6-w8x8r reviews-v2-cf6f69b7d-gmzt9 reviews-v3-55c7b5f478-s85gb

この場合Pod名がスペース区切りで出てくる。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?