0

How to set metadata.name from a variable value, when kustomizing a base ressource.

For creating for example a namespace, but we don’t know its name in advance but need to “kustomize” like adding commonLabels etc to it?

The way Kustomize operates is that you kustomize a base resource already defined with an apiVersion, kind, metadata.name. So I haven't found a way to afterwards set the final resource name.

DevLounge
  • 8,313
  • 3
  • 31
  • 44
  • I found my answer in this question: https://stackoverflow.com/questions/57594001/how-can-i-create-a-namespace-with-kustomize – DevLounge Mar 31 '21 at 00:51

1 Answers1

0

If I understand you correctly there are few options depending on your needs:

  1. Use Helm

Helm helps you manage Kubernetes applications — Helm Charts help you define, install, and upgrade even the most complex Kubernetes application.

  1. Use PodPreset

You can use a PodPreset object to inject information like secrets, volume mounts, and environment variables etc into pods at creation time.

  1. Use ConfigMaps

ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable.

  1. You can modify your deployments dynamically and than run kubectl replace -f FILE command. Or use kubectl edit DEPLOYMENT command in order to automatically applly the changes.

Please let me know if that helped.

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37