使用generateName字段在kubernetes中创建自定义资源 [英] create a custom resource in kubernetes using generateName field
问题描述
我有一个示例crd定义为
I have a sample crd defined as
crd.yaml
kind: CustomResourceDefinition
metadata:
name: testconfig.demo.k8s.com
namespace: testns
spec:
group: demo.k8s.com
versions:
- name: v1
served: true
storage: true
scope: Namespaced
names:
plural: testconfigs
singular: testconfig
kind: TestConfig
我想基于上述crd创建一个自定义资源,但是我不想为该资源分配一个固定的名称,而是使用generateName字段.所以我生成了以下cr.yaml.但是当我应用它时,错误提示名称字段为必填
I want to create a custom resource based on above crd but i dont want to assign a fixed name to the resource rather use the generateName field. So i generated the below cr.yaml. But when i apply it gives error that name field is mandatory
kind: TestConfig
metadata:
generateName: test-name-
namespace: testns
spec:
image: testimage
我们非常感谢您的帮助.
Any help is highly appreciated.
推荐答案
您应使用kubectl create
和generateName
创建CR.
"kubectl apply
将在执行操作之前验证资源是否存在.如果资源不存在,则会首先创建它们.如果使用generateName
,则在验证资源是否存在时尚未生成资源名称.资源." 来源
"kubectl apply
will verify the existence of the resources before take action. If the resources do not exist, it will firstly create them. If use generateName
, the resource name is not yet generated when verify the existence of the resource." source
这篇关于使用generateName字段在kubernetes中创建自定义资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!