参考:

kubectl Cheat Sheet | Kubernetes

Kubernetes kubectl 命令表 _ Kubernetes(K8S)中文文档_Kubernetes中文社区

Play with Kubernetes (play-with-k8s.com) (模拟环境)

[k8s系统情况]

1) kubernetes config指令:

>kubectl config view                                      # Show Merged kubeconfig settings

>kubectl config get-contexts                         # display list of contexts

>kubectl config current-context                     # display the current-context

2) API resource指令:

>kubectl api-resources                                   # for a complete list of supported resources

>kubectl api-resources --verbs=list,get         # All resources that support the "list" and "get" request verbs

3) node详细情况:

>kubectl describe node <node name>

# 含有该node的详细信息,例如:NetworkUnavailable /MemoryPressure /DiskPressure /PIDPressure /Ready;

OS版本信息;cpu/momery/pods数量;IP地址;各个pod的cpu/memory利用率;Event事件

4)

>kubectl describe <api resource>                             #获取api对象详细信息

>kubectl explain pods                                #Get the documentation of the resource and its fields

>kubectl explain pods.spec.containers         #JSONPath identifier

>kubectl get node -o wide                                        #output带wide参数,获取详细信息,含node ip地址信息

>kubectl get nodes --show-labels                           #含failure domain信息

>kubectl cluster-info

>kubectl get componentstatus                            #component状态信息

>kubectl get apiservices

>kubectl diff -f <filename>                                   # Compares the current state of the cluster against the state that the cluster would be in if the manifest was applied.

[查看各种API Resource]

1) Get commands with basic output:

>kubectl get services -n <namespace>                           # List all services in the namespace

>kubectl get pods --all-namespaces                               # List all pods in all namespaces

>kubectl get pods -A                                                        # List all pods in all namespaces

>kubectl get deployment my-dep                                   # List a particular deployment

>kubetctl get rc,pods                                                       # resource type will be added before the resource name

2) Describe commands with verbose output:

>kubectl describe nodes my-node

>kubectl describe pods my-pod                                     #包含详细信息,Events项会提供重要信息

>kubectl describe pods -A                                             #所有pods

3) 排序输出:

>kubectl get pods -A --sort-by=.metadata.name

>kubectl get pods -n <ns> --sort-by='.status.containerStatuses[0].restartCount'    #按重启次数

>kubectl get pv --sort-by=.spec.capacity.storage    #按容量排序

[查看pod信息]

>kubectl get pods -o name -A                                              #output,显示name

>kubectl get pods -o wide                                                   #output,显示详细信息,含pod的IP地址,所在node

>kubectl get pods -n <ns> -owide -w                                #观察pod的创建终止等动态变化:After listing/getting the requested object, watch for changes.

>kubectl get pods -o json                                                   #output,以json格式显示详细信息

>kubectl get pod <pod name> -o yaml                           #Get a pod's YAML

>kubectl get pod -n <namespace>                                  #List all pods in the current namespace

>kubectl get pods --show-labels                                     #Show labels for all pods (or any other Kubernetes object that supports labelling)

>kubectl get pods --no-headers                                     #不显示column名

>kubectl get pods -L app                                                #output,显示Label=app信息

>kubectl get pods -L role                                                #output,显示pod的role信息:如master,replica,data,logger等

>kubectl get pods -L label1,lablel2 或者

>kubectl get pods -L label1 -L label2

>kubectl get pods -l app                                                #selector过滤

>kubectl get pods -A                                                     #获取所有namespace的pods

>kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'            # List pods Sorted by Restart Count?

>kubectl get pod my-con --template="{{range .status.containerStatuses}}{{.name}}:{{.restartCount}}{{end}}"     #查看某个pod的每个container的重启次数

>kubectl get pods --field-selector=status.phase=Running                                 # Get all running pods in the namespace

>kubectl get pod mysql --template="{{.status.phase}}"                                      #查看pod生命周期

>kubectl get pods --all-namespaces -o jsonpath='{range.items[*].status.initContainerStatuses[*]}{.containerID}{"\n"}{end}' | cut -d/ -f3

               # List all containerIDs of initContainer of all pods

               # Helpful when cleaning up stopped containers, while avoiding removal of initContainers.

>kubectl exec <pod> -- <command>                                              #在pod里运行command

>kubectl exec <pod> -c <container> -- <command>                    #在pod的container里运行command

最新文章

  1. 相克军_Oracle体系_随堂笔记009-检查点队列
  2. CefBrowser 复制图片解决办法
  3. ios AFNetworking 3.0 报错 : *** Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error:],
  4. [分享] RT7LITE精简后无法封装解决办法
  5. ManyToMany关联方式----
  6. 配置Qt开发环境下的OpenCV开发
  7. javascript运动框架(二)
  8. 如何改变Myeclipse编辑区背景色(转)
  9. Bootstrap框架的了解和使用(一)
  10. PostMan如何做Post请求测试
  11. HBase Rowkey 设计指南
  12. json 百分比转化
  13. Java 数据库简单操作类
  14. SpringSecurity实现记住我功能
  15. js 基本包装类型 String
  16. mfc CFileFind查找类
  17. Tornado使用-简介
  18. 【链表】Insertion Sort List
  19. Nginx总结.md
  20. node中的require

热门文章

  1. ps4双手柄inputManager设置
  2. 编程基础与python介绍
  3. mysql 数据库的一些参数,常用模版和调优方式
  4. http协议与tcp协议的理解
  5. 看图王 10.9.1.9791 With X64 去广告绿色版
  6. u8g2 资料汇集
  7. Windows 设置当前路径 临时环境变量 查看、修改、删除与添加
  8. oracle system 账户被锁或者忘记密码
  9. Typora的一些基础用法
  10. nginx 配置443 域名