How to render helm template yaml file using kubectl command

Hi,

I am trying to deploy helm charts to AWS EKS cluster using Flux cd. Having an issue with helm template yaml files.

Example: configMap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include “sample-api.fullname” . | indent 2 }}-env
{{- with .Values.envVariables }}
data:
{{- toYaml . | nindent 2 }}
{{- end }}

I’m testing it locally with command “kubectl apply -k sample-api/templates”

getting this error
error parsing analytics-api/templates/env-configmap.yml: error converting YAML to JSON: yaml: line 3: did not find expected key

Its not able to render the template., its complaing about {{}} statemets in the yaml file. However I tried hardcoded values instead of {{ }} statements that works fine.

my sample-api/templates folder has Kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
-configmap.yml

In my case I wanted to auto deploy helm charts to EKS using flux.
Any suggestions please.

Thanks!

kubectl cannot render helm templates, helm can do that first then they can be applied with helm.

Got it. Locally, I can run with helm command successfully.

But how do we deploy the helm templates with {{ }} values in EKS with flux
Again, I tried with hardcoded values instead of {{ }} and can deploy successfully.

I have my helm repository added to flux , here is the configuration file


apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
kind: Kustomization
metadata:
  name: fleet-helm
  namespace: flux-system
spec:
  interval: 10m0s
  path: ./charts/src/analytics/sample-api/templates
  prune: true
  sourceRef:
    kind: GitRepository
    name: fleet-helm

I set path: ./charts/src/analytics/sample-api/templates to templates dir where I have yaml files with {{ }}. Throws below error when I check
flux get all

False False failed to decode Kubernetes YAML from /tmp/kustomization-2772309989/charts/src/analytics/analytics-api/templates/sample-api.yaml: MalformedYAMLError: yaml: line 3: did not find expected key.