问题
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