参考:

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. 从源码MessageSource的三个实现出发实战spring·i18n国际化

    1.前言 互联网业务出海,将已有的业务Copy to Global,并且开始对各个国家精细化,本土化的运营.对于开发人员来说,国际化很重要,在实际项目中所要承担的职责是按照客户指定的语言让服务端返回相 ...

  2. LVS的NAT,TUN,DR原理及区别

    原理及其区别 Linux Virtual Server是通过ipvs内核模块和ipvsadm用户空间命令行工具来实现负载均衡的它支持三种工作模式: NAT模式:LVS调度器将请求转发给后端服务器,同时 ...

  3. 关于Intent Uri页面跳转

    android browser支持支持Intent Scheme URL语法的可以在wrap页面加载或点击时,通过特定的intent uri链接可以打开对应app页面,例如 <a href=&q ...

  4. DevExpress GridControl 在窗体默认皮肤下 设置其他皮肤

    gridControl 属性里 LookAndFeel.UseDefaultLookAndFeel = False SkinName 可以选择自带的皮肤

  5. 41.Sentinel

    Feign 整合 Sentinel 依赖 <!--Feign--> <dependency> <groupId>org.springframework.cloud& ...

  6. ElasticSearch、ElasticSearch-head的安装和问题解决

    前言:elasticsearch作为一个基于Lucene的分布式搜索引擎,其搜索功能的强大之处不用多说,而elasticsearch-head作为一个node项目,能够轻松管理elasticsearc ...

  7. CSS控制背景图片100%自适应填充布局

    原文地址:http://blog.csdn.net/wd4java/article/details/50537562 .personal_head { width: 100%; height: 35% ...

  8. Java设计模式——装饰器模式(Decorator)

    今天上课讲了java设计模式中的装饰器模式--Decorator,由于早上起的很早,肚子也很饿,知识点本身也晦涩难懂,听的云里雾里的,所以在课下对这块的知识做出一些总结. 定义 装饰器模式又名包装(W ...

  9. python安装及简单爬虫(爬取导师信息)

    1.下载: 解释器(我下的是3.8.2版本):https://www.python.org/downloads/ pycharm(我下的是2019.3.3版本):https://www.jetbrai ...

  10. npm升级报错,没有权限.ERRERR!The operation was rejected by your operating system. npm ERR!Error: EPERM: operation not permitted, rename

    问题描述 Windows system32>npm installg npm 2335 error code EEXIST2336 error path D:\Program Files\nod ...