kubectl explain资源文档命令

学习并使用了一段时间的kubernetes,发现对k8s还是了解甚少,于是利用上下班通勤的时间又去B站看一些大佬的视频,又来重学巩固一遍知识,并做些记录。

之前在学习使用过程中未成了解过explain这个命令,因为自己部署的版本跟课本内容有差异,有些在文件编写时老师不清楚版本号,走了较多弯路。最近才了解到explian这个命令。因此这里做些记录,后面如果有更深入学习使用会做些补充和更新。

1、explain简介

kubectl explain:资源文档,获取资源及其字段的文档。在定义资源配置文件时,使用该命令可以输出资源对应的属性字段及定义。

可能的资源类型包括:

pods (po), services (svc), replicationcontrollers (rc), nodes (no), events (ev), componentstatuses (cs), limitranges (limits), persistentvolumes (pv), persistentvolumeclaims (pvc), resourcequotas (quota), namespaces (ns), horizontalpodautoscalers (hpa) 或 endpoints (ep)

2、Kubectl语法

kubectl explain RESOURCE

[root@master ~]# kubectl explain --help  # 命令帮助文档
List the fields for supported resources.

 This command describes the fields associated with each supported API resource. Fields are identified via a simple
JSONPath identifier:

  <type>.<fieldName>[.<fieldName>]
  
 Add the --recursive flag to display all of the fields at once without descriptions. Information about each field is
retrieved from the server in OpenAPI format.

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

Examples:
  # Get the documentation of the resource and its fields
  kubectl explain pods
  
  # Get the documentation of a specific field of a resource
  kubectl explain pods.spec.containers

Options:
      --api-version='': Get different explanations for particular API version (API group/version)
      --recursive=false: Print the fields of fields (Currently only 1 level deep)

Usage:
  kubectl explain RESOURCE [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).
 

3、kubectl explain  使用介绍

1)kubectl explain pod   获取pod资源文档

通过这个命令我们可以查看编辑pod yml文档的字段、版本号等信息

[root@master ~]# kubectl explain pod  #查看pod资源文档
KIND:     Pod    # 资源类型
VERSION:  v1 # 资源版本号

DESCRIPTION:
     Pod is a collection of containers that can run on a host. This resource is
     created by clients and scheduled onto hosts.

FIELDS: #资源文件的字段和字段值类型
   apiVersion   <string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

   kind <string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

   metadata     <Object>
     Standard object's metadata. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata

   spec <Object>
     Specification of the desired behavior of the pod. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

   status       <Object>
     Most recently observed status of the pod. This data may not be up to date.
     Populated by the system. Read-only. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
 

2)kubectl explain svc 查看service资源字段的文档

图示对照

 3)获取资源的特定字段的文档

kubectl explain pods.spec.containers

我们可以看到每个字段后面都跟着<String>、<Object>之类的释义,说明如下:

<Object>       在下一级写数据内容
<String>后边填写字符串内容
<[]Object>(数组对象),需要在下一级开始写内容,下面的第一个内容需要加“-”,作为数据的第一个对象
<Boolean>后边填写ture或者false
<Integer>对应的是整形,后边填写数字
<map[String] string>go语言的map类型,自定义的键值对(key是字符串,value也是字符串)

4、kubectl explain选项

1)选项

--recursive[=false]: 打印字段的字段(目前只有1级深)。

2)从父命令继承的选项

选项

说明

--alsologtostderr[=false]

记录到标准错误和文件。

--certificate-authority=""

证书颁发机构的证书文件的路径。

--client-certificate=""

用于TLS的客户端证书文件的路径。

--client-key=""

用于TLS的客户端密钥文件的路径。

--cluster=""

要使用的kubeconfig集群的名称

--context=""

要使用的kubeconfig上下文的名称

--insecure-skip-tls-verify[=false]

如果为true,则不会检查服务器证书的有效性。

这将使HTTPS连接不安全。

--kubeconfig=""

用于CLI请求的kubeconfig文件的路径。

--log-backtrace-at=:0

当日志记录达到line file:N时,发出堆栈跟踪

--log-dir=""

如果非空,则将日志文件写入此目录

--log-flush-frequency=5s

两次日志刷新之间的最大秒数

--logtostderr[=true]

日志到标准错误而不是文件

--match-server-version[=false]

要求服务器版本与客户端版本匹配

--namespace=""

如果存在,则此CLI请求的名称空间作用域。

--password=""

API服务器基本身份验证密码。

-s, --server=""

Kubernetes API服务器的地址和端口

--stderrthreshold=2

达到或超过这个阈值的日志将发送到stderr

--token=""

API服务器身份验证的Bearer token。

--user=""

要使用的kubeconfig用户的名称

--username=""

API服务器基本认证的用户名。

--v=0

日志级别为V日志

--vmodule=

用逗号分隔的pattern=N个

用于文件过滤日志记录的设置列表

 参考链接: https://www.cjavapy.com/article/2802/

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值