Basic Commands (Beginner): create Create a resource from a file or from stdin expose Take a replication controller, service, deployment or pod and expose it as a new Kubernetes service run 在集群中运行一个指定的镜像 set 为 objects 设置一个指定的特征
Basic Commands (Intermediate): explain Get documentation for a resource get 显示一个或更多 resources edit 在服务器上编辑一个资源 delete Delete resources by file names, stdin, resources and names, or by resources and label selector
Deploy Commands: rollout Manage the rollout of a resource scale Set a new size for a deployment, replica set, or replication controller autoscale Auto-scale a deployment, replica set, stateful set, or replication controller
Cluster Management Commands: certificate 修改 certificate 资源. cluster-info Display cluster information top Display resource (CPU/memory) usage cordon 标记 node 为 unschedulable uncordon 标记 node 为 schedulable drain Drain node in preparation for maintenance taint 更新一个或者多个 node 上的 taints
Troubleshooting and Debugging Commands: describe 显示一个指定 resource 或者 group 的 resources 详情 logs 输出容器在 pod 中的日志 attach Attach 到一个运行中的 container exec 在一个 container 中执行一个命令 port-forward Forward one or more local ports to a pod proxy 运行一个 proxy 到 Kubernetes API server cp Copy files and directories to and from containers auth Inspect authorization debug Create debugging sessions for troubleshooting workloads and nodes
Advanced Commands: diff Diff the live version against a would-be applied version apply Apply a configuration to a resource by file name or stdin patch Update fields of a resource replace Replace a resource by file name or stdin wait Experimental: Wait for a specific condition on one or many resources kustomize Build a kustomization target from a directory or URL.
Settings Commands: label 更新在这个资源上的 labels annotate 更新一个资源的注解 completion Output shell completion code for the specified shell (bash, zsh or fish)
Other Commands: alpha Commands for features in alpha api-resources Print the supported API resources on the server api-versions Print the supported API versions on the server, in the form of "group/version" config 修改 kubeconfig 文件 plugin Provides utilities for interacting with plugins version 输出 client 和 server 的版本信息
kubectl get pod -n kube -n 后跟 namespace, 查看指定的命名空间中的pod
3、查看RC和Service列表:
kubectl get rc,svc svc是service简写,也可以写全拼
kubectl get pod,svc -o wide -o wide 查看详细信息
kubectl get pod <pod-name> -o yaml # 获取节点和服务版本信息 kubectl get nodes # 获取节点和服务版本信息,并查看附加信息 kubectl get nodes -o wide # 获取pod信息,默认是default名称空间 kubectl get pod # 获取pod信息,默认是default名称空间,并查看附加信息【如:pod的IP及在哪个节点运行】 kubectl get pod -o wide # 获取指定名称空间的pod kubectl get pod -n kube-system # 获取指定名称空间中的指定pod kubectl get pod -n kube-system podName # 获取所有名称空间的pod kubectl get pod -A # 查看pod的详细信息,以yaml格式或json格式显示 kubectl get pods -o yaml kubectl get pods -o json # 查看pod的标签信息 kubectl get pod -A --show-labels # 根据Selector(label query)来查询pod kubectl get pod -A --selector="k8s-app=kube-dns" # 查看运行pod的环境变量 kubectl exec podName env # 查看指定pod的日志 kubectl logs -f --tail 500 -n kube-system kube-apiserver-k8s-master # 查看所有名称空间的service信息 kubectl get svc -A # 查看指定名称空间的service信息 kubectl get svc -n kube-system # 查看componentstatuses信息 kubectl get cs # 查看所有configmaps信息 kubectl get cm -A # 查看所有serviceaccounts信息 kubectl get sa -A # 查看所有daemonsets信息 kubectl get ds -A # 查看所有deployments信息 kubectl get deploy -A # 查看所有replicasets信息 kubectl get rs -A # 查看所有statefulsets信息 kubectl get sts -A # 查看所有jobs信息 kubectl get jobs -A # 查看所有ingresses信息 kubectl get ing -A # 查看有哪些名称空间 kubectl get ns # 查看pod的描述信息 kubectl describe pod podName kubectl describe pod -n kube-system kube-apiserver-k8s-master # 查看指定名称空间中指定deploy的描述信息 kubectl describe deploy -n kube-system coredns # 查看node或pod的资源使用情况 # 需要heapster 或metrics-server支持 kubectl top node kubectl top pod # 查看集群信息 kubectl cluster-info 或 kubectl cluster-info dump # 查看各组件信息【172.16.1.110为master机器】 kubectl -s https://172.16.1.110:6443 get componentstatuses