了解API对象属性的方法
在准备manifest文件时,可以参考kubernetes官网的http://kubernetes.io/docs/api参考文档,来了解API对象支持的属性,也可以使用kubectl explain命令。很多时候,使用后者更便捷。
如何使用kubectl explain命令
从零开始以编写POD的manifest文件,可以使用该命令先了解pod的相关规格:
[jinguang1@m104120196 ~]$ kubectl explain pods
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/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/api-conventions.md#types-kinds
metadata <Object>
Standard object's metadata. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
spec <Object>
Specification of the desired behavior of the pod. More info:
https://git.k8s.io/community/contributors/devel/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/api-conventions.md#spec-and-status
从显示的帮助信息来看,Pod的manifest文件包含apiVersion, kind, metadata, spec, status属性,其中status属性为只读,编写manifest文件时并不需要提供。
如果我们需要进一步了解metadata更详细的信息,那么可以通过下列命令来显示帮助信息:
[jinguang1@m104120196 ~]$ kubectl explain pod.metadata
KIND: Pod
VERSION: v1
RESOURCE: metadata <Object>
DESCRIPTION:
Standard object's metadata. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
ObjectMeta is metadata that all persisted resources must have, which
includes all objects users must create.
FIELDS:
annotations <map[string]string>
Annotations is an unstructured key value map stored with a resource that
may be set by external tools to store and retrieve arbitrary metadata. They
are not queryable and should be preserved when modifying objects. More
info: http://kubernetes.io/docs/user-guide/annotations
clusterName <string>
The name of the cluster which the object belongs to. This is used to
distinguish resources with same name and namespace in differe

本文介绍了如何通过kubectl explain命令便捷地了解Kubernetes API对象的属性。在创建manifest文件时,除了参考官方文档,使用kubectl explain可以更快速地获取对象如Pod的规格信息,例如apiVersion, kind, metadata, spec等字段。对于metadata的深入理解,可以进一步使用kubectl explain来获取详细帮助。"
79493395,7419939,Java JAX-RS与Spring MVC创建RESTful服务的区别,"['RESTFul WebService', 'Spring MVC', 'Java API for RESTful Services', 'jersey', 'Apache CXF']
最低0.47元/天 解锁文章
5066

被折叠的 条评论
为什么被折叠?



