k 8 s常用コマンド(qbit)


  • ヘルプ
  • kubectl help
  • バージョン情報
  • [root@host ~]# kubectl version
    Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"clean", BuildDate:"2020-05-20T12:52:00Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
    Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"clean", BuildDate:"2020-05-20T12:43:34Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
  • クラスタ情報を表示する(masterノードを表示する)
  • root@host ~]# kubectl cluster-info 
    Kubernetes master is running at https://192.168.31.27:6443
    KubeDNS is running at https://192.168.31.27:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
  • ノードリストを表示
  • [root@host68 ~]# kubectl get nodes
    NAME      STATUS   ROLES    AGE    VERSION
    host68   Ready    master   131d   v1.18.3
    host69   Ready       70d    v1.18.6
    host70   Ready       38d    v1.18.3
    host71   Ready       70d    v1.18.6
    host72   Ready       66d    v1.18.3
    host73   Ready       66d    v1.18.3
    host74   Ready       126d   v1.18.3
  • すべてのpodとnamespace
  • を表示
    [root@vip-068 ~]# kubectl get pods --all-namespaces
    NAMESPACE    NAME                  READY   STATUS    RESTARTS   AGE
    default      gitlab-86hgh          1/1     Running   0          124d
    default      mysql-qqghr           1/1     Running   0          129d
    es           es-46tml              1/1     Running   0          37d
    es           es-5twv5              1/1     Running   1          37d
    es           es-g4tnp              1/1     Running   0          29d
    es           es-vx9r9              1/1     Running   0          30d
    es           es-xj8kk              1/1     Running   0          27d
  • すべてのnodeとpod
  • がリストされます.
    kubectl get pod -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName --all-namespaces
  • あるpodの中の容器を見て
  • [root@host68 ~]# kubectl -n es get pod es-46tml -o jsonpath="{.spec['containers','initContainers'][*].name}"
    es
    #   
    kubectl -n es describe pod es-46tml
  • コンテナ内のディレクトリ
  • がリストされています.
    #   
    kubectl -n  -c  exec  -- ls -la /
    #   
    kubectl -n es -c es exec es-46tml -- ls -la /usr/share/elasticsearch/config
    [root@host68 ~]# kubectl -n es -c es exec es-46tml -- ls -la /usr/share/elasticsearch/config
    total 1360
    drwxrwxr-x 1 elasticsearch root    4096 Oct 12 13:28 .
    drwxrwxr-x 1 elasticsearch root    4096 Sep  5 06:03 ..
    -rw-rw---- 1 elasticsearch root     199 Sep  5 06:03 elasticsearch.keystore
    -rw-rw---- 1 elasticsearch root      53 May 28 16:33 elasticsearch.yml
    -rw-rw---- 1 elasticsearch root    2301 May 28 16:28 jvm.options
    drwxrwxr-x 2 elasticsearch root    4096 May 28 16:31 jvm.options.d
    -rw-rw---- 1 elasticsearch root    7860 May 28 16:33 log4j2.properties
    -rw-rw---- 1 elasticsearch root     473 May 28 16:32 role_mapping.yml
    -rw-rw---- 1 elasticsearch root     197 May 28 16:32 roles.yml
    -rw-r--r-- 1 root          root 1345763 Oct 12 13:28 synonym.txt
    -rw-rw---- 1 elasticsearch root       0 May 28 16:32 users
    -rw-rw---- 1 elasticsearch root       0 May 28 16:32 users_roles
  • コンテナ内のファイルを削除
  • kubectl -n es -c es exec es-46tml -- rm /usr/share/elasticsearch/config/synonym.txt
  • ディレクトリ
  • を作成
    kubectl -n es -c es exec es-46tml -- mkdir /usr/share/elasticsearch/config/analysis
  • コンテナディレクトリ
  • にファイルをコピー
    #   
    kubectl -n es -c es cp synonym.txt es-46tml:/usr/share/elasticsearch/config/analysis
    #   
    [root@host68 test]# kubectl -n es -c es exec es-46tml -- ls -la /usr/share/elasticsearch/config/analysis
    total 1324
    drwxr-xr-x 2 root          root    4096 Oct 13 05:57 .
    drwxrwxr-x 1 elasticsearch root    4096 Oct 13 05:56 ..
    -rw-r--r-- 1 root          root 1345763 Oct 13 05:57 synonym.txt

    qbit snap