kubernetes部署deployment报错----env子属性含数字异常

前言:

今天在给微服务项目部署对应的数据库(mysql)(通过k8s进行容器管理)。在创建好Service、PV、PVC之后,即将进行最后一步的部署

Pod控制器(Deployment),在我通过下面代码进行创建的时候

kubectl create -f mysql-deployment.yaml

报出了下面的ERROR:

Error from server (BadRequest): error when creating "mysql-deployment.yaml": Deployment in version "v1" 
cannot be handled as a Deployment: v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.Sp
ec: v1.PodSpec.Containers: []v1.Container: v1.Container.Env: []v1.EnvVar: v1.EnvVar.Value: ReadString: e
xpects " or n, but found 1, error found in #10 byte of ...|,"value":123456}],"i|..., bigger context ...|
":[{"env":[{"name":"MYSQL_ROOT_PASSWORD","value":123456}],"image":"mysql:5.6","name":"mysql","ports"|...

由于个人英语并不是很好,便去翻译软件进行了一番深入的研究探讨。最终得出一个结论(毛都看不懂)

 

随后对YAML文件重新进行了一遍审查, 也没有发现有格式或命名上的错误

(下附代码)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  namespace: kerry
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: 123456
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-storage
          mountPath: /root/zookeeper/kerryData
      volumes:
      - name: mysql-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim

 

 

解决:

最后经过查阅资料,发现这个错误犯得还算有意义。问题就出在了env中。如果 Deployment 中

使用了 env,并且 env 中有一些值是数字,就会抛出这个错误,解决办法就是将数字添加引号

类似下面截图中内容:

 

posted @ 2021-07-17 21:42  _kerry  阅读(1394)  评论(0编辑  收藏  举报