参考:

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

Kubernetes学习笔记(一)的更多相关文章

  1. Kubernetes 学习笔记(一):基础概念

    个人笔记,仅本人查阅使用,不保证正确. 零.微服务 微服务架构专注于应用解耦合,通过将应用彻底地组件化和服务化,每个微服务只包含一个非常小的功能,比如权限管理.日志收集等等.由这一组微服务组合起来,提 ...

  2. Kubernetes学习笔记(八):Deployment--声明式的升级应用

    概述 本文核心问题是:如何升级应用. 对于Pod的更新有两种策略: 一是删除全部旧Pod之后再创建新Pod.好处是,同一时间只会有一个版本的应用存在:缺点是,应用有一段时间不可用. 二是先创建新Pod ...

  3. Kubernetes学习笔记(四):服务

    服务介绍 服务是一种为一组相同功能的pod提供单一不变接入点的资源.当服务存在时,他的IP和端口不会改变.客户端通过IP和端口建立连接,这些连接会被路由到任何一个pod上.如此,客户端不需要知道每个单 ...

  4. Kubernetes学习笔记之认识Kubernetes组件

    前言:笔记知识点来源于Kubernetes官方文档说明,链接:https://kubernetes.io/docs/concepts/overview/components/ ,本记录仅仅是学习笔记记 ...

  5. 深入剖析Kubernetes学习笔记:开篇词(00)

    一.关于Kubernetes初学的疑惑 就在这场因"容器"而起的技术变革中,kubernetes项目已经成为容器技术的事实标准,重新定义了基础设置领域对应用编排与管理的种种可能 1 ...

  6. kubernetes学习笔记(二)——部署服务

    文章目录 (1)创建app (2)创建app的docker镜像 (3)部署app到k8s (4)参考资料 前面一篇文章部署好了minikube环境,这次学习下怎么部署app到kubernetes环境当 ...

  7. kubernetes学习笔记(一)——minikube安装记录

    想学习一下kubernetes,于是先安装一个单机版来学习一下.但是就是这个最简单的单机版安装方式都倒腾了我好久,记录下自己的安装过程.博主是在windows利用vmware workstation安 ...

  8. Kubernetes 学习笔记(二):本地部署一个 kubernetes 集群

    前言 前面用到过的 minikube 只是一个单节点的 k8s 集群,这对于学习而言是不够的.我们需要有一个多节点集群,才能用到各种调度/监控功能.而且单节点只能是一个加引号的"集群&quo ...

  9. 【Kubernetes学习笔记】-使用Minikube快速部署K8S单机学习环境

    介绍 https://minikube.sigs.k8s.io/docs/ Minikube 用于快速在本地搭建 Kubernetes 单节点集群环境,它对硬件资源没有太高的要求,方便开发人员学习试用 ...

  10. 【Kubernetes学习笔记】-服务访问之 IP & Port & Endpoint 辨析

    目录 不同类型的IP Pod IP Cluster IP 不同类型的Port port nodePort TargetPort containerPort hostPort Endpoint Endp ...

随机推荐

  1. mybatis中的土鸡杂鱼

    mybatis中的土鸡杂鱼 目录 mybatis中的土鸡杂鱼 1.mapper接口为什么要和mapper.xml在同一个路径下? 2.主键生成为什么配置一个字段就可以? 原理 3.为什么默认使用的是预 ...

  2. JavaScript查找两个节点的最近的一个共同父节点,可以包括节点自身

  3. go 程序设计语言 命令行参数

    最近打算读一读 go程序设计语言这本书, 读语言类的书是一件十分头疼的事情, 因为读一本书就意味着,看着一堆钳子 锥子工具的图片, 概念背了一大堆,仍然不知道怎么用,还是要通过实践. 还是习惯任务驱动 ...

  4. 使用oledb读写excel出现“操作必须使用一个可更新的查询”的解决办法

    使用oledb读写excel出现"操作必须使用一个可更新的查询"的解决办法 转自:http://www.cnblogs.com/Richinger/archive/2008/09/ ...

  5. java double/float转BigDecimal,精度问题

    double/float 转BigDecimal,会有精度问题.所以需要转String类型,然后再转BigDecimal

  6. nodejs基础知识点

    nodejs 模块调用的几种方式 nodejs 模块分三大类 自定义模块,第三方模块,核心模块 核心模块是用nodejs自带的模块组件,比如fs path http url buffer等 直接加载 ...

  7. C6657子卡模块设计资料:268-基于FMC接口的DSP TMS320C6657子卡模块

    基于FMC接口的DSP TMS320C6657子卡模块 一. 概述        FMC连接器是一种高速多pin的互连器件,广泛应用于板卡对接的设备中,特别是在xilinx公司的所有开发板中都使用.该 ...

  8. ssm框架下的拦截器过滤静态资源以及拦截jsp

    这篇文章如果能给你带来帮助 不胜荣幸,如果有错误 ,欢迎批评指正,共同进步. 今天啊搭了一个ssm的框架 虽然说现在大部分都在使用shiro权限,可是正如mybatis.hibernate和jdbc的 ...

  9. Veeva_001常见问题总结

    1.时间互动轴:其他代表与该医生的互动记录 2.Call的拜访流程 : 用户在Ipad端先制定计划拜访(已计划:青色)后,需手动同步到服务器上: 进入拜访详细,选择联系人和产品及相关拜访信息等,并'保 ...

  10. Web学习篇—Http协议

    Http协议简介 h3 { background: rgba(0, 154, 205, 1); color: rgba(255, 255, 255, 1); border-radius: 6px; f ...