参考:

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. 2023 年 CCF 春季测试赛模拟赛 - 1

    T1 个人思路: 询问:求 \(1\) 到 \(t_i\) 路径上离 \(1\) 最远的 \(p\),使得 \(dis_{1,p} \times 2 \le d_i\).即 \(dis_{1,t} \ ...

  2. 文字icon

    1 <!DOCTYPE html> 2 <html lang="zh"> 3 <head> 4 <meta charset="U ...

  3. K8s集群安全机制

    安全机制说明 k8s作为一个分布式集群管理的工具,保证集群的安全性是其一个重要的任务.API Server是集群内部各个组件通信的中介,也是外部控制的入口,,所以K8s的安全机制就是围绕保护API S ...

  4. Spring随意总结

    Spring框架的优点 1.使用Spring的IOC容器,将对象之间的依赖关系交给Spring,降低组件之间的耦合性,让我们更专注于应用逻辑 2.可以提供众多服务,事务管理,WS等. 3.AOP的很好 ...

  5. maven打包springboot项目不能运行的解决办法

    前提是在开发工具中能正常运行,maven打包后无法运行. 打包后,进入打包文件路径 在dos下输出 java -version 显示jdk版本后,再 java -jar    xxxx.jar xxx ...

  6. iOS开发之权限申请说明key

    我们申请不同的权限需要对应的key,在info.plist内加上对用户的提示语 麦克风权限 NSMicrophoneUsageDescription 相机权限 NSCameraUsageDescrip ...

  7. js-惰性函数

    1. 需求:我们现在需要写一个 foo 函数,这个函数返回首次调用时的 Date 对象,注意是首次. 使用场景:当我们每次都需要进行条件判断,其实只需要判断一次,接下来的使用方式都不会发生改变的时候, ...

  8. pg9.6使用索引

    使用索引 索引是用于快速数据检索操作的结构.在数据库世界中,索引与表相关联并用于有效定位数据,而无需查询数据库表中的每一行.如果表没有索引,则需要全表扫描才能找到记录,这在磁盘 I/O 和 CPU 利 ...

  9. Python项目框架的搭建

    Python的框架搭建,有七个步骤 第一步:创建项目 首先我们打开pycharm,然后点击第一个Create New Project ,创建一个新的项目. 在选项里面是有一个Flask的,然后就是项目 ...

  10. Quartz.Net的简单使用

    1.安装Quartz.Net Install-Package Quartz -Version 2.5.0 2.需要执行定时任务的代码,新建一个类,继承IJob接口,并实现该接口 public clas ...