<p>I'm not finding any answers to this on Google but I may just not know what terms to search for.</p>

<p>In a CRD, is there a way to define a field in the spec that is a secret (and therefore shouldn't be stored in plain text)?  For example, if the custom resource needs to have an API token included in it, how do you define that in the CRD?  </p>

<p>One thought I had was to just have the user create a Secret outside of the CRD and then provide the secret's name in a custom resource field so the operator can query it from the K8s API on demand when needed (and obviously associated RBAC needs to be configured so the operator has read access to the Secret).  So the field in the CRD would just be a normal string that is the name of the target Secret.</p>

<p>But is there a better way?  Any existing best practices around this?</p>

<p>You do indeed just store the value in an actual Secret and reference it. You'll find the same pattern all over k8s. Then in your controller code you get your custom object, find the ref, get that secret, and then you have your data.</p>
