kubectlのオプションメモ

  2017-10-26


tips

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

-w で結果をリアルタイムに出力できる(表示がおかしくなることが多々ある)

  • -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

    getサブコマンド一覧

  • all

  • certificatesigningrequests (aka ‘csr’)

  • clusterrolebindings

  • clusterroles

  • clusters (valid only for federation apiservers)

  • componentstatuses (aka ‘cs’)

  • configmaps (aka ‘cm’)

  • controllerrevisions

  • cronjobs

  • daemonsets (aka ‘ds’)

  • deployments (aka ‘deploy’)

  • endpoints (aka ‘ep’)

  • events (aka ‘ev’)

  • horizontalpodautoscalers (aka ‘hpa’)

  • ingresses (aka ‘ing’)

  • jobs

  • limitranges (aka ‘limits’)

  • namespaces (aka ‘ns’)

  • networkpolicies (aka ‘netpol’)

  • nodes (aka ‘no’)

  • persistentvolumeclaims (aka ‘pvc’)

  • persistentvolumes (aka ‘pv’)

  • poddisruptionbudgets (aka ‘pdb’)

  • podpreset

  • pods (aka ‘po’)

  • podsecuritypolicies (aka ‘psp’)

  • podtemplates

  • replicasets (aka ‘rs’)

  • replicationcontrollers (aka ‘rc’)

  • resourcequotas (aka ‘quota’)

  • rolebindings

  • roles

  • secrets

  • serviceaccounts (aka ‘sa’)

  • services (aka ‘svc’)

  • statefulsets

  • storageclasses

  • thirdpartyresources

    describeサブコマンド一覧

  • all

  • certificatesigningrequests (aka ‘csr’)

  • clusterrolebindings

  • clusterroles

  • clusters (valid only for federation apiservers)

  • componentstatuses (aka ‘cs’)

  • configmaps (aka ‘cm’)

  • controllerrevisions

  • cronjobs

  • daemonsets (aka ‘ds’)

  • deployments (aka ‘deploy’)

  • endpoints (aka ‘ep’)

  • events (aka ‘ev’)

  • horizontalpodautoscalers (aka ‘hpa’)

  • ingresses (aka ‘ing’)

  • jobs

  • limitranges (aka ‘limits’)

  • namespaces (aka ‘ns’)

  • networkpolicies (aka ‘netpol’)

  • nodes (aka ‘no’)

  • persistentvolumeclaims (aka ‘pvc’)

  • persistentvolumes (aka ‘pv’)

  • poddisruptionbudgets (aka ‘pdb’)

  • podpreset

  • pods (aka ‘po’)

  • podsecuritypolicies (aka ‘psp’)

  • podtemplates

  • replicasets (aka ‘rs’)

  • replicationcontrollers (aka ‘rc’)

  • resourcequotas (aka ‘quota’)

  • rolebindings

  • roles

  • secrets

  • serviceaccounts (aka ‘sa’)

  • services (aka ‘svc’)

  • statefulsets

  • storageclasses

  • thirdpartyresources

クラスタの状態

kubectl get componentstatuses

出力例

NAME STATUS MESSAGE ERROR
etcd-0 Healthy {"health": "true"}
scheduler Healthy ok
controller-manager Healthy ok