首页 > 其他分享 >K8s中编写yaml资源清单的小技巧

K8s中编写yaml资源清单的小技巧

时间:2023-02-12 19:33:05浏览次数:36  
标签:info metadata devel yaml io 清单 pod K8s More

可以通过kubectl explain ...来查询字段

例如

查询pod的字段

$ kubectl explain 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

查询pod中metadata中的字段

$ 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/sig-architecture/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

.............................................

   uid	<string>
     UID is the unique in time and space value for this object. It is typically
     generated by the server on successful creation of a resource and is not
     allowed to change on PUT operations.

     Populated by the system. Read-only. More info:
     http://kubernetes.io/docs/user-guide/identifiers#uids

一个简单的pod配置文件

---
apiVersion: v1
kind: Pod
metadata:
  name: filehttp
  labels:
    app: http
spec:
  containers:
    - name: http1
      ports:
        - containerPort: 80
      image: httpd:latest
      imagePullPolicy: IfNotPresent

注意:

  • 如果字段后面带有 -required- 标记,则表示该字段为必需有的字段

标签:info,metadata,devel,yaml,io,清单,pod,K8s,More
From: https://www.cnblogs.com/guangdelw/p/17114523.html

相关文章

  • k8s安装指南
    安装机器说明ubuntu2h16g只有一台机器开始安装一,安装kubectl,kubeadm,kubeletesudocurlhttps://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg|apt-k......
  • 012k8s node oom记录
    一、腾讯云事件总线报警(1)根据如下报警,如何查看受影响的应用及处理:云服务产品告警通知尊敬的腾讯云用户,您好!您的腾讯云账号(账号ID:xxx)云服务服务产品云服务器事......
  • k8s相关服务执行计划
    1、微服务执行计划apiVersion:apps/v1kind:Deploymentmetadata:name:microservice-howear-gatewaynamespace:microservice-testlabels:app:micros......
  • K8s:类似 dashboard 的K8s开源 Web/桌面 客户端工具 Headlamp
    写在前面分享一个k8s客户端开源项目Headlamp给小伙伴博文内容涉及:Headlamp桌面/集群Web端安装启动导入集群简单查看集群信息理解不足小伙伴帮忙指正<font......
  • k8s集群角色管理
    查看集群各节点角色:[root@k8s-master-2~]#kubectlgetnodesNAMESTATUSROLESAGEVERSIONk8s-master-1Readymaster......
  • K8S基础
    一.K8S概述1.1什么是K8SKubernetes或简称k8s,是一个用于自动执行应用程序部署的系统。用于自动部署、扩展和管理“容器化(containerized)应用程序”的开源系统。K8S是......
  • go yaml文件转化
    packageyamlimport("bufio""bytes""io""path/filepath""strings"fileutil"github.com/labring/sealos/pkg/utils/file""k8s.io/apimachinery/pkg/......
  • 执行kubectl api-resources 报错error: unable to retrieve the complete list of ser
    1、故障现象:error:unabletoretrievethecompletelistofserverAPIs:metrics.k8s.io/v1beta1:theserveriscurrentlyunabletohandletherequest2、分析原因......
  • Kubernetes:分享一个可以展示资源视图的 K8s开源 Web/桌面 客户端工具 Octant
    写在前面博文内容主要为Octant介绍以及桌面/Web端的安装教程涉及Linux/Windows的安装。理解不足小伙伴帮忙指正其实当你什么都经历了,会发现,人生无论你怎么精心......
  • K8s集群证书过期或延期(kubeadm)
    不同的K8S版本操作有些许不同,所以建议在遇到问题时先查询K8S官方文档1、连接Api-server失败,报证书已过期不可用$kubectlgetnode,podUnabletoconnecttotheser......