create a custom resource in kubernetes using generateName field

安稳与你 提交于 2021-02-08 07:20:56

问题


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

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.


回答1:


You should use kubectl create to create your CR with 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



来源:https://stackoverflow.com/questions/59030069/create-a-custom-resource-in-kubernetes-using-generatename-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!