Manu Chadha
Manu Chadha

Reputation: 16745

K8s: Error in applying yaml file after adding env values

The following yaml file works fine

apiVersion: apps/v1
kind: Deployment
metadata:
  name: something
spec:
  replicas: 2
  selector:
    matchLabels:
      app: something
  template:
    metadata:
      labels:
        app: something
    spec:
      volumes:
        - name: shared-logs
          emptyDir: {}
      containers:
        - name: something
          image: docker.io/manuchadha25/something
          volumeMounts:
            - name: shared-logs
              mountPath: /deploy/codingjediweb-1.0/logs/
          env:
            - name: DB_CASSANDRA_URI
              value: cassandra://34.91.5.44
            - name: DB_PASSWORD
              value: something
            - name: DB_KEYSPACE_NAME
              value: something
            - name: DB_USERNAME
              value: something
            - name: EMAIL_SERVER
              value: something
            - name: EMAIL_USER
              value: something
            - name: EMAIL_PASSWORD
              value: something
            - name: ALLOWED_NODES
              value: 34.105.134.5  
          ports:
            - containerPort: 9000
        #- name: logging
         # image: busybox
          #volumeMounts:
           # - name: shared-logs
            #  mountPath: /deploy/codingjediweb-1.0/logs/
          #command: ['sh', '-c', "while true; do sleep 86400; done"]

But when I add the following two lines in env section, I get error

apiVersion: apps/v1
kind: Deployment
metadata:
  name: something
spec:
  replicas: 2
  selector:
    matchLabels:
      app: something
  template:
    metadata:
      labels:
        app: something
    spec:
      volumes:
        - name: shared-logs
          emptyDir: {}
      containers:
        - name: something
          image: docker.io/manuchadha25/something
          volumeMounts:
            - name: shared-logs
              mountPath: /deploy/codingjediweb-1.0/logs/
          env:
            - name: DB_CASSANDRA_URI
              value: cassandra://34.91.5.44
            - name: DB_CASSANDRA_PORT <--- NEW LINE
              value: 9042<--- NEW LINE
            - name: DB_PASSWORD
              value: something
            - name: DB_KEYSPACE_NAME
              value: something
            - name: DB_USERNAME
              value: something
            - name: EMAIL_SERVER
              value: something
            - name: EMAIL_USER
              value: something
            - name: EMAIL_PASSWORD
              value: something
            - name: ALLOWED_NODES
              value: 34.105.134.5  
          ports:
            - containerPort: 9000
        #- name: logging
         # image: busybox
          #volumeMounts:
           # - name: shared-logs
            #  mountPath: /deploy/codingjediweb-1.0/logs/
          #command: ['sh', '-c', "while true; do sleep 86400; done"]


$ kubectl apply -f codingjediweb-nodes.yaml
Error from server (BadRequest): error when creating "codingjediweb-nodes.yaml": 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 9, error found in #10 byte of ...|,"value":9042},{"nam|..., bigger context ...|.1.85.10"},{"name":"DB_CASSANDRA_PORT","value":9042},{"name":"DB_PASSWORD","value":"1GFGc1Q|...

The following website validates that the YAML is correct.

What am I doing wrong?

Upvotes: 1

Views: 242

Answers (1)

Dashrath Mundkar
Dashrath Mundkar

Reputation: 9212

Could you please add 9042 in double qoutes “9042” and try this. I think it’s looking for string and getting numbers instead so please add the value in double quotes

Upvotes: 2

Related Questions