创建 kubernetes 部署时出错

getting error while creating kubernetes deployment

我的部署工作正常。我只是尝试使用本地持久卷在我的应用程序本地存储数据。之后我遇到了错误。

error: error validating "xxx-deployment.yaml": error validating data: ValidationError(Deployment.spec.template.spec.imagePullSecrets[0]): unknown field "volumeMounts" in io.k8s.api.core.v1.LocalObjectReference; if you choose to ignore these errors, turn validation off with --validate=false

apiVersion: apps/v1
kind: Deployment
metadata:
  name: xxx
  namespace: xxx
spec:
  selector:
    matchLabels:
      app: xxx
  replicas: 3
  template:
    metadata:
      labels:
        app: xxx
    spec:
     containers:
     - name: xxx
       image: xxx:1.xx
       imagePullPolicy: "Always"
       stdin: true
       tty: true
       ports:
       - containerPort: 80
       imagePullPolicy: Always
     imagePullSecrets:
     - name: xxx
       volumeMounts:
        - mountPath: /data
          name: xxx-data
     restartPolicy: Always
     volumes:
      - name: xx-data
        persistentVolumeClaim:
          claimName: xx-xx-pvc

你的 yaml 中有一个缩进拼写错误,volumeMountsimagePullSecrets 下面,而它应该在同一层:

     imagePullSecrets:
     - name: xxx
     volumeMounts:
     - mountPath: /data
       name: xxx-data

您需要将 imagePullSecret 进一步向下移动。它打破了容器规范。 imagePullSecret 是在 pod 规范级别定义的,而 volumeMounts 属于容器规范

apiVersion: apps/v1
kind: Deployment
metadata:
  name: xxx
  namespace: xxx
spec:
  selector:
    matchLabels:
      app: xxx
  replicas: 3
  template:
    metadata:
      labels:
        app: xxx
    spec:
     containers:
     - name: xxx
       image: xxx:1.xx
       imagePullPolicy: "Always"
       stdin: true
       tty: true
       ports:
       - containerPort: 80
       imagePullPolicy: Always
       volumeMounts:
        - mountPath: /data
          name: xxx-data
     imagePullSecrets:
     - name: xxx
     restartPolicy: Always
     volumes:
      - name: xx-data
        persistentVolumeClaim:
          claimName: xx-xx-pvc

volumeMounts:是一个容器子。

和卷:是规格子。

此外,volumeMounts 和 Vloume 名称应该相同。