2

I got an error in my Deoloyment.ysml file. I have made env in this file and assign values in values file. I got a syntax error in this file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}
  labels:
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/name: {{ include "name" . }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/instance: {{ .Release.Name }}
      app.kubernetes.io/name: {{ include "name" . }}
  template:
    metadata:
      labels:
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/name: {{ include "name" . }}
    spec:
      containers:
        - name: {{ .Release.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          resources: {}
          env:
            - name: MONGODB_ADDRESS
              value: {{ .Values.mongodb.db.address }}
            - name: MONGODB
              value: "akira-article"
            - name: MONGODB_USER
              value: {{ .Values.mongodb.db.user | quote }}
            - name: MONGODB_PASS
              valueFrom:
                secretKeyRef:
                  name: {{ include "name" . }}
                  key: mongodb-password
            - name: MONGODB_AUTH_DB
              value: {{ .Values.mongodb.db.name | quote }}
            - name: DAKEN_USERID
              value: {{ .Values.mongodb.db.userId | quote }}
            - name: DAKEN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ include "name" . }}
                  key: daken-pass
            - name: JWT_PRIVATE_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ include "name" . }}
                  key: jwt-Privat-Key
            - name: WEBSITE_NAME
              value: {{ .Values.website.Name }}
            - name: WEBSITE_SHORT_NAME
              value: {{ .Values.website.shortName }}
            - name: AKIRA_HTTP_PORT
              value: {{ .Values.website.port }}
          ports:
            - containerPort: {{ .Values.service.port }}

I got this error:

Error: Deployment in version "v1" cannot be handled as a Deployment: v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Env: []v1.EnvVar: v1.EnvVar.Value: ReadString: expects " or n, but found 8, error found in #10 byte of ...|,"value":8080}],"ima|..., bigger context ...|,"value":"AA"},{"name":"AKIRA_HTTP_PORT","value":8080}],"image":"dr.xenon.team/websites/akira-fronte|...

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • 1
    What's your helm version. piping it to quote should work but still ports are supposed to be integers, so there might be some problem with your specific helm version. Change the value of port to 8080 in values file instead of quoting it. Also try the int pipe in the deployment manifest. – rohanmehto2 Feb 10 '20 at 08:59

2 Answers2

3

Answer to your problem is available in Helm documentation QUOTE STRINGS, DON’T QUOTE INTEGERS.

When you are working with string data, you are always safer quoting the strings than leaving them as bare words:

name: {{ .Values.MyName | quote }}

But when working with integers do not quote the values. That can, in many cases, cause parsing errors inside of Kubernetes.

port: {{ .Values.Port }}

This remark does not apply to env variables values which are expected to be string, even if they represent integers:

env:
 - name: HOST
   value: "http://host"
 - name: PORT
   value: "1234"

I'm assuming you have put the port value of AKIRA_HTTP_PORT inside quotes, that's why you are getting the error.

You can read the docs about Template Functions and Pipelines.

Crou
  • 10,232
  • 2
  • 26
  • 31
1

With AKIRA_HTTP_PORT: "8080" in values.yaml, in the env variables write:

env:
  - name:  AKIRA_HTTP_PORT
    value: {{ .Values.website.port | quote }}

It should have to work

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • @SoumyaSingh glad to hear that you can mark it as an answer and update the status if that works. that's how SO works thanks. – Harsh Manvar Feb 12 '20 at 03:42