<p>I have a sample crd defined as </p>

<p>crd.yaml</p>

<pre><code>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
</code></pre>

<p>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</p>

<pre><code>kind: TestConfig
metadata:
  generateName: test-name-
  namespace: testns
spec:
  image: testimage
</code></pre>

<p>Any help is highly appreciated.</p>

PREETI BANSAL
<p>You should use <code>kubectl create</code> to create your CR with <code>generateName</code>.</p>

<p>"<code>kubectl apply</code> will verify the existence of the resources before take action. If the resources do not exist, it will firstly create them. If use <code>generateName</code>, the resource name is not yet generated when verify the existence of the resource." <a href="https://github.com/kubernetes/kubernetes/issues/44501#issuecomment-294255660" rel="noreferrer">source</a></p>
