Search code examples
kuberneteskubernetes-helmkustomize

Is it possible to have a dynamic namePrefix/nameSuffix in kustomize?


In Helm, it is possible to specify a release name using

helm install my-release-name chart-path

This means, I can specify the release name and its components (using fullname) using the CLI.

In kustomize (I am new to kustomize), there is a similar concept, namePrefix and nameSuffix which can be defined in a kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namePrefix: overlook-

resources:
- deployment.yaml

However, this approach needs a custom file, and using a "dynamic" namePrefix would mean that a kustomization.yaml has to be generated using a template and kustomize is, well, about avoiding templating.

Is there any way to specify that value dynamically?


Solution

  • You can use kustomize edit to edit the nameprefix and namesuffix values.

    For example:

    Deployment.yaml

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: the-deployment
    spec:
      replicas: 5
      template:
        containers:
          - name: the-container
            image: registry/conatiner:latest
    

    Kustomization.yaml

    apiVersion: kustomize.config.k8s.io/v1beta1
    kind: Kustomization
    
    resources:
    - deployment.yaml
    

    Then you can run kustomize edit set nameprefix dev- and kustomize build . will return following:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: dev-the-deployment
    spec:
      replicas: 5
      template:
        containers:
        - image: registry/conatiner:latest
          name: the-container