【问题标题】:K8s: Error in applying yaml file after adding env valuesK8s:添加 env 值后应用 yaml 文件时出错
【发布时间】:2020-11-16 03:57:06
【问题描述】:

以下yaml 文件可以正常工作

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"]

但是当我在env 部分添加以下两行时,我得到了错误

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|...

以下网站验证 YAML 是否正确。

我做错了什么?

【问题讨论】:

标签: kubernetes


【解决方案1】:

您能否在双引号“9042”中添加 9042 并试试这个。我认为它正在寻找字符串并获取数字,所以请在双引号中添加值

【讨论】:

    猜你喜欢
    • 2021-11-04
    • 2023-04-02
    • 1970-01-01
    • 2019-07-05
    • 2021-09-02
    • 1970-01-01
    • 2023-02-21
    • 2020-06-25
    • 2018-01-18
    相关资源
    最近更新 更多