<p>Lets say I need to create environment variables or ConfigMap entries like this:</p>
<pre><code>- name: JDBC_URL
  value: &quot;jdbc:db2://alice-service-a:50000/db1&quot;
- name: KEYCLOAK_BASE_URL
  value: &quot;http://alice-keycloak:8080/auth&quot;
</code></pre>
<p>Where <code>alice-</code> is the namePrefix. How do I do this using Kustomize?</p>
<p>The containers I use actually do need references to other containers that are string concatenations of &quot;variables&quot; like above.</p>
<p>It doesn't look like Kustomize's <code>vars</code> can do this. The documentation entry <a href="https://kubectl.docs.kubernetes.io/faq/kustomize/eschewedfeatures/#unstructured-edits" rel="nofollow noreferrer">Unstructured Edits</a> seems to describe this and is under a heading called &quot;Eschewed Features&quot;, so I guess that isn't going to happen. A similar feature request, <a href="https://github.com/kubernetes-sigs/kustomize/issues/775" rel="nofollow noreferrer">#775 Support envsubst style variable expansion</a> was closed.</p>
<p>Coming from Helm, that was easy.</p>
<p>What are my options if I want to move from Helm to Kustomize, but need to create an env or ConfigMap entry like e.g. <code>jdbc:db2://${namePrefix}-service-b:${dbPort}/${dbName}</code> (admittedly a contrived example)?</p>
<p>I'm guessing I'll have to resort to functionality external to Kustomize, like <code>envsubst</code>. Are there any best practices for cobbling this together, or am I writing my own <code>custom-deploy-script.sh</code>?</p>

<p>I'm afraid I've come up against one of the limitations of Kustomize.</p>
<p><a href="https://blog.argoproj.io/the-state-of-kubernetes-configuration-management-d8b06c1205" rel="nofollow noreferrer">The State of Kubernetes Configuration Management: An Unsolved Problem | by Jesse Suen | Argo Project</a> has this to say under &quot;Kustomize: The Bad&quot;:</p>
<blockquote>
<p><em><strong>No parameters &amp; templates</strong></em>. The same property that makes kustomize applications so readable, can also make it very limiting. For example, I was recently trying to get the kustomize CLI to set an image tag for a custom resource instead of a Deployment, but was unable to. Kustomize does have a concept of “vars,” which look a lot like parameters, but somehow aren’t, and can only be used in Kustomize’s sanctioned whitelist of field paths. I feel like this is one of those times when the solution, despite making the hard things easy, ends up making the easy things hard.</p>
</blockquote>
<p>Instead, I've started using <a href="https://github.com/hairyhenderson/gomplate" rel="nofollow noreferrer">gomplate: A flexible commandline tool for template rendering</a> in addition to Kustomize to solve the challenge above, but having to use two tools that weren't designed to work together is not ideal.</p>
<p>EDIT: We ended up using <a href="https://carvel.dev/ytt/" rel="nofollow noreferrer">ytt</a> for this instead of <code>gomplate</code>.</p>
<p>I can heavily recommend the article: <a href="https://blog.argoproj.io/the-state-of-kubernetes-configuration-management-d8b06c1205" rel="nofollow noreferrer">The State of Kubernetes Configuration Management: An Unsolved Problem</a>. Nice to know I'm not the only one hitting this road block.</p>
