1

kustomize build --enable-helm .I have the following project structure:

project
  - helm-k8s
   - values.yml
   - Chart.yml
   - templates
    - base
      - project-namespace.yml
      - grafana
        - grafana-service.yml
        - grafana-deployment.yml
        - grafana-datasource-config.yml
      - prometheus
        - prometheus-service.yml
        - prometheus-deployment.yml
        - prometheus-config.yml
        - prometheus-roles.yml
      - kustomization.yml
    - prod
      - kustomization.yml
    - test
      - kustomization.yml

I'm trying to build my kustomization file using helm like below:

project/helm-k8s/templates/base/$ kubectl kustomize build . --enable-helm -> dummy.yml

I get an error message like this:

project/helm-k8s/templates/base$ kubectl kustomize . --enable-helm
error: accumulating resources: accumulation err='accumulating resources from 'project-namespace.yml': missing metadata.name in object {{v1 Namespace} {{ } map[name:] map[]}}': must build at directory: '/home/my-user/project/helm-k8s/templates/base/project-namespace.yml': file is not directory

Is it not possible for kustomize to use the values.yml which is located directly under helm-k8s folder and create the final manifest for my cluster? What am I doing wrong here?

EDIT: Here is how my kustomization.yml looks like:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
metadata:
  name: open-electrons-monitoring-kustomization
resources:
  # 0. Get the namespaces first
  - project-namespace.yml

  # 1. Set up monitoring services (prometheus)
  #- monitoring/prometheus/prometheus-roles.yml
  - prometheus/prometheus-config.yml
  - prometheus/prometheus-roles.yml
  - prometheus/prometheus-deployment.yml
  - prometheus/prometheus-service.yml

  # 2. Set up monitoring services (grafana)
  - grafana/grafana-datasource-config.yml
  - grafana/grafana-deployment.yml
  - grafana/grafana-service.yml
joesan
  • 13,963
  • 27
  • 95
  • 232
  • What does your `kustomization.yaml` look like? It would be great if you could update your question to include an [mcve] -- a minimal kustomization.yaml (and any required files) that reproduces the problem you're asking about. – larsks Feb 03 '23 at 03:28
  • I have updated my post with my kustomization.yml. – joesan Feb 03 '23 at 05:09

1 Answers1

1

I think you may have misunderstood the use of the --enable-helm parameter. It does not allow kustomize to perform helm-style templating on files, so when you write:

apiVersion: v1
kind: Namespace
metadata:
  name: {{ .Values.app.namespace }}
  labels:
    name: {{ .Values.app.namespace }}

That doesn't do anything useful. It just generates invalid YAML output.


The --enable-helm option allows you to explode Helm charts using Kustomize; see here for the documentation, but for example it allows you to process a kustomization.yaml file like this:

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

helmCharts:
  - name: traefik
    repo: https://helm.traefik.io/traefik
    includeCRDs: true
    releaseName: example
    version: 20.8.0
    valuesInline:
      deployment:
        replicas: 3
      logs:
        access:
          enabled: true

Running kubectl kustomize --enable-helm will cause kustomize to fetch the helm chart and run helm template on it, producing YAML manifests on stdout.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • So how does this fit my needs here? I mean, how can I generate for my project a single deployment file out of kustomize with the helm values applied? – joesan Feb 03 '23 at 12:41
  • 1
    That seems like a different question. Kustomize doesn't perform variable substitution or any other sort of templating. If you want to work with kustomize, you need to design your deployment manifests with that in mind. If your use case requires templating, you could package up everything as a helm chart instead, and just use helm. – larsks Feb 03 '23 at 15:08
  • There is this chartInflator and I thought that it could do the trick? – joesan Feb 04 '23 at 02:04
  • The chart inflator does what I've shown in this answer: it inflates a helm chart and allows you to apply kustomize transformations to the result. It does not allow you to perform helm templating on your kustomize manifests. – larsks Feb 04 '23 at 12:24