kubectl命令范例

1、查看集群状态

  1. [root@clientvm ~]# kubectl cluster-info
  2. Kubernetes master is running at https://192.168.133.129:6443
  3. KubeDNS is running at https://192.168.133.129:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
  4. To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

2、查看集群版本

  1. [root@clientvm ~]# kubectl version
  2. Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.4", GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f", GitTreeState:"clean", BuildDate:"2020-11-11T13:17:17Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}
  3. Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:23:04Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}

3、查看集群API信息

  1. [root@clientvm ~]# kubectl api-versions
  2. [root@clientvm ~]# kubectl api-resources

4、查看节点状态

  1. [root@clientvm ~]# kubectl get node
  2. NAME STATUS ROLES AGE VERSION
  3. master.example.com Ready master 9m18s v1.19.4
  4. worker1.example.com Ready <none> 4m9s v1.19.4
  5. worker2.example.com Ready <none> 3m51s v1.19.4

5、查看节点扩展信息

  1. [root@clientvm ~]# kubectl get node -o wide
  2. NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
  3. master.example.com Ready master 10m v1.19.4 192.168.241.129 <none> CentOS Linux 7 (Core) 3.10.0-1160.6.1.el7.x86_64 docker://19.3.11
  4. worker1.example.com Ready <none> 5m10s v1.19.4 192.168.241.130 <none> CentOS Linux 7 (Core) 3.10.0-1160.6.1.el7.x86_64 docker://19.3.11
  5. worker2.example.com Ready <none> 4m52s v1.19.4 192.168.241.131 <none> CentOS Linux 7 (Core) 3.10.0-1160.6.1.el7.x86_64 docker://19.3.11

6、查看节点详细描述

  1. [root@clientvm ~]# kubectl describe nodes master.example.com

7、将资源信息以yaml格式输出

  1. [root@clientvm ~]# kubectl get nodes master.example.com -o yaml

8、将资源信息以json格式输出

  1. [root@clientvm ~]# kubectl get nodes master.example.com -o json

9、explain命令

  1. [root@clientvm ~]# kubectl explain namespace
  2. KIND: Namespace
  3. VERSION: v1
  4. ......