kubectl是一个用于操作kubernetes集群的命令行接口,通过利用kubectl的各种命令可以实现各种功能。
Kubectl 的主要主要参数
get #显示一个或多个资源describe #显示资源详情create #从文件或标准输入创建资源update #从文件或标准输入更新资源delete #通过文件名、标准输入、资源名或者 label 删除资源log #输出 pod 中一个容器的日志rolling-update #对指定的 RC 执行滚动升级exec #在容器内部执行命令port-forward #将本地端口转发到 Podproxy #为 Kubernetes API server 启动代理服务器run #在集群中使用指定镜像启动容器expose #将 SVC 或 pod 暴露为新的 kubernetes servicelabel #更新资源的 labelconfig #修改 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个podcpu: 1ephemeral-storage: 51473888Kihugepages-2Mi: 0memory: 1882352Kipods: 110Allocatable: #节点容许分配的资源情况,部分预留的资源会排出在Allocatable范畴 cpu: 1ephemeral-storage: 47438335103hugepages-2Mi:0memory:1779952Kipods:110Non-terminated Pods:(3 in total) #节点上运行pod的资源的情况,除了nginx-demo之外还有多个podAllocated resources: #已经分配的cpu和memory的资源情况(Total limits may be over 100 percent, i.e., overcommitted.)Resource--------cpumemoryephemeral-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-demoName: nginx-demoNamespace: defaultPriority:0Node:node-3/10.254.100.103 #表明pod所在的nodeStart Time:Sat, 28 Sep 2019 12:10:49 +0800Labels:name=nginx-demoAnnotations: kubectl.kubernetes.io/last-applied-configuration:{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labelStatus: RunningIP: 10.244.2.13Containers:nginx-demo:Container ID:docker://55d28fdc992331c5c58a51154cd072cd6ae37e03e05ae829a97129Image:nginx:1.7.9 #代表该pod是基于哪一个docker image创建的Image ID:docker-pullable://nginx@sha256:e3456c851a152494c3e4ff5fcc26f240Port:80/TCPHost Port:0/TCPState:RunningStarted:Sat, 28 Sep 2019 12:10:51 +0800Ready:TrueRestart Count: 0Limits: #限制资源cpu: 500mmemory: 256MiRequests:#请求资源cpu:250mmemory: 128MiEnvironment: <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




