Using Kustomize I have a base deployment and overlays for each environment I want to deploy to. With ConfigMap set the environment variable
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
configMapGenerator:
- name: config
literals:
- env=prod
images:
- name: <image>
generatorOptions:
disableNameSuffixHash: true
I can use that ConfigMap when setting environment variables but am not able to reuse it on labels, i.e. tags.vendor.com/env
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-api
namespace: app
labels:
appName: app-api
tags.vendor.com/env: prod
spec:
template: ...
I realize I can use kustomize patches but that results in duplicated definitions (ConfigMap sets env for environment variables, patch path sets env for labels). Is it possible to reuse ConfigMap on labels or is patching the DRYest we can get?
Note: I've seen the pitfalls described with commonLabels here https://patrick-picard.medium.com/kustomization-applying-labels-gotchas-a53f87277661