暂无图片
暂无图片
2
暂无图片
暂无图片
暂无图片

kubectl describe 简介

五分钟学SRE 2021-12-03
10776

kubectl是一个用于操作kubernetes集群的命令行接口,通过利用kubectl的各种命令可以实现各种功能。

Kubectl 的主要主要参数

get       #显示一个或多个资源
describe #显示资源详情
create #从文件或标准输入创建资源
update #从文件或标准输入更新资源
delete #通过文件名、标准输入、资源名或者 label 删除资源
log #输出 pod 中一个容器的日志
rolling-update #对指定的 RC 执行滚动升级
exec #在容器内部执行命令
port-forward #将本地端口转发到 Pod
proxy #为 Kubernetes API server 启动代理服务器
run #在集群中使用指定镜像启动容器
expose #将 SVC 或 pod 暴露为新的 kubernetes service
label #更新资源的 label
config #修改 kubernetes 配置文件
cluster-info #显示集群信息
api-versions #以”组/版本”的格式输出服务端支持的 API 版本
version #输出服务端和客户端的版本信息
help #显示各个命令的帮助信息
ingress-nginx #管理 ingress 服务的插件(官方安装和使用方式)

主要了解下 kubectl describe

kubectl describe命令同样用于查看资源信息,describe聚合了相关资源的信息并输出。比如,在describe node信息时,同时会输出该node下的pod的资源利用情况,所以describe命令在排错和调试时非常有用。

官方说明如下

Show details of a specific resource or group of resources.

Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, provide a name prefix, or label selector. For example:

$ kubectl describe TYPE NAME_PREFIX


will first check for an exact match on TYPE and NAME_PREFIX. If no such resource exists, it will output details for every resource that has a name prefixed with NAME_PREFIX.

Use "kubectl api-resources" for a complete list of supported resources



支持的资源包括但不限于(大小写不限):

pods (po)、services (svc)、 replicationcontrollers (rc)、nodes (no)、events (ev)、componentstatuses (cs)、 limitranges (limits)、persistentvolumes (pv)、persistentvolumeclaims (pvc)、 resourcequotas (quota)和secrets。

kubectl describe (-f FILENAME | TYPE [NAME_PREFIX | -l label] | TYPE/NAME)

示例

Describe a node

kubectl describe nodes kubernetes-node-emt8.c.myproject.internal

kubectl describe node 需要关注的几个字段:

Capacity: #节点上资源的总资源情况,1个cpu,2g内存,110个pod
cpu: 1
ephemeral-storage: 51473888Ki
hugepages-2Mi: 0
memory: 1882352Ki
pods: 110
Allocatable: #节点容许分配的资源情况,部分预留的资源会排出在Allocatable范畴 cpu: 1
ephemeral-storage: 47438335103
hugepages-2Mi:0
memory:1779952Ki
pods:110
Non-terminated Pods:(3 in total) #节点上运行pod的资源的情况,除了nginx-demo之外还有多个pod
Allocated resources: #已经分配的cpu和memory的资源情况
(Total limits may be over 100 percent, i.e., overcommitted.)
Resource
--------
cpu
memory
ephemeral-storage


Describe a pod

kubectl describe pods/nginx

Describe a pod identified by type and name in "pod.json"

kubectl describe -f pod.json

Describe all pods

kubectl describe pods
[root@node-1 demo]# kubectl describe pods nginx-demo
Name: nginx-demo
Namespace: default
Priority:0
Node:node-3/10.254.100.103 #表明pod所在的node
Start Time:Sat, 28 Sep 2019 12:10:49 +0800
Labels:name=nginx-demo
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"label
Status: Running
IP: 10.244.2.13
Containers:
nginx-demo:
Container ID:docker://55d28fdc992331c5c58a51154cd072cd6ae37e03e05ae829a97129
Image:nginx:1.7.9 #代表该pod是基于哪一个docker image创建的
Image ID:docker-pullable://nginx@sha256:e3456c851a152494c3e4ff5fcc26f240
Port:80/TCP
Host Port:0/TCP
State:Running
Started:Sat, 28 Sep 2019 12:10:51 +0800
Ready:True
Restart Count: 0
Limits: #限制资源
cpu: 500m
memory: 256Mi
Requests:#请求资源
cpu:250m
memory: 128Mi
Environment: <none>
...省略...

Describe pods by label name=myLabel

kubectl describe po -l name=myLabel

Describe all pods managed by the 'frontend' replication controller (rc-created pods # get the name of the rc as a prefix in the pod the name)

kubectl describe pods frontend


更详细部分可以看文档:https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#describe



文章转载自五分钟学SRE,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论