How to set metadata.name from dynamic variable

10/30/2019

How to set metadata.name from a dynamic variable when creating for example a namespace we don’t know the name in advance but need to “kustomize” like adding commonLabels etc to it?

-- Anthony Perot
kubernetes
kustomize

1 Answer

10/31/2019

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.

-- OhHiMark
Source: StackOverflow