LoginSignup
9
3

More than 5 years have passed since last update.

kubectlのオプションメモ

Last updated at Posted at 2017-10-26

ネットの拾い読みで勉強していたが、最近本を買って勉強しだしたので、なるほどと思ったことをメモしておく。

とりあえず今回はkubectlについて。

-w で結果をリアルタイムに出力できる

getやdescribeサブコマンドはカンマ区切りで複数指定できる

# 例
$ kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
po/nfs-server-1786322612-p0pw3 1/1 Running 0 1d

NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.0.0.1 <none> 443/TCP 3d

-o wideで情報をより多く出すことができる

# 例
$ kubectl get  pods -o wide
NAME                          READY     STATUS    RESTARTS   AGE       IP           NODE
nfs-server-1786322612-p0pw3   1/1       Running   0          1d        172.17.0.6   minikube

-o json-o yamlでそれぞれの形式で出力することができる (情報もより多く出る)

例
$ kubectl get  pods -o json
{
    "apiVersion": "v1",
    "items": [
        {
            "apiVersion": "v1",
            "kind": "Pod",
            "metadata": {
                "annotations": {
                    "kubernetes.io/created-by": "{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicaSet\",\"namespace\":\"default\",\"name\":\"nfs-server-1786322612\",\"uid\":\"e8cf196e-b80f-11e7-87c4-080027159c1b\",\"apiVersion\":\"extensions\",\"resourceVersion\":\"13198\"}}\n"
                },
                "creationTimestamp": "2017-10-23T16:33:32Z",
                "generateName": "nfs-server-1786322612-",
                "labels": {
                    "pod-template-hash": "1786322612",
                    "role": "nfs-server"
                },
                "name": "nfs-server-1786322612-p0pw3",
                "namespace": "default",
                略

--no-headersでヘッダーを取り除くことができる (パイプを使うときに便利)

# 例
$ kubectl get  pods --no-headers
nfs-server-1786322612-p0pw3   1/1       Running   0         1d

-o jsonpath --template={(フィールド)}で指定のフィールドのみを出力することができる

# 例
$ kubectl get  pods -o jsonpath --template {.items[].metadata.name}
nfs-server-1786322612-p0pw3

kubectl get componentstatuses でクラスタの状態を取得することができる

#例
NAME                 STATUS    MESSAGE              ERROR
etcd-0               Healthy   {"health": "true"}
scheduler            Healthy   ok
controller-manager   Healthy   ok
9
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
9
3