【问题标题】:Deployment file error but can not find where issued from部署文件错误,但找不到从哪里发出
【发布时间】:2021-07-28 04:12:00
【问题描述】:

我希望人们可以帮助指出我的部署文件中的问题所在,当我部署时出现以下错误 感谢您的帮助

"Deployment.apps "my-app" is invalid: [spec.template.spec.containers[0].volumeMounts[0].name: Not found: "audioSources", spec.template.spec.containers[0].volumeMounts[1].name: Not found: "authors", spec.template.spec.containers[0].volumeMounts[2].name: Not found: "covers"]"

这是我的部署文件

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: my-app
  name: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - image: myname/myimage
        name: my-app
        ports:
        - containerPort: 3000
        volumeMounts:
        - name: audioSources
          mountPath: /usr/share/nginx/html/audioSources
        - name: authors
          mountPath: /usr/share/nginx/html/authors
        - name: covers
          mountPath: /usr/share/nginx/html/covers
  volumes:
    - name: audioSources
      hostPath:
        path: /home/websites/audioSources
    - name: authors
      hostPath:
        path: /home/websites/authors
    - name: covers
      hostPath:
        path: /home/websites/covers

【问题讨论】:

    标签: kubernetes deployment


    【解决方案1】:

    这是一个固定的部署:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: my-app
      name: my-app
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: my-app
      template:
        metadata:
          labels:
            app: my-app
        spec:
          containers:
          - image: myname/myimage
            name: my-app
            ports:
            - containerPort: 3000
            volumeMounts:
            - name: audio-sources
              mountPath: /usr/share/nginx/html/audioSources
            - name: authors
              mountPath: /usr/share/nginx/html/authors
            - name: covers
              mountPath: /usr/share/nginx/html/covers
          volumes:
          - name: audio-sources
            hostPath:
              path: /home/websites/audioSources
          - name: authors
            hostPath:
              path: /home/websites/authors
          - name: covers
            hostPath:
              path: /home/websites/covers
    
    1. 卷应在spec 下,与containers 处于同一级别。
    2. 另外,audioSource 的名称更改为 audio-source

    【讨论】:

      【解决方案2】:

      看起来这是由于您的 YAML 文件中的缩进错误

      Volume 应该在 spec 部分下

      示例 YAML 我正在使用

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        labels:
          app: hello-app
        name: hello-app
        namespace: default
      spec:
        progressDeadlineSeconds: 600
        replicas: 1
        revisionHistoryLimit: 10
        selector:
          matchLabels:
            app: hello-app
        strategy:
          rollingUpdate:
            maxSurge: 25%
            maxUnavailable: 25%
          type: RollingUpdate
        template:
          metadata:
            creationTimestamp: null
            labels:
              app: hello-app
          spec:
            containers:
            - name: nginx
              image: nginx
              imagePullPolicy: IfNotPresent
              volumeMounts:
                - mountPath: /etc/cert/
                  name: foo
                - mountPath: /etc/nginx/conf.d
                  name: nginxconf
                  readOnly: true
            - image: gcr.io/google-samples/hello-app:1.0
              imagePullPolicy: IfNotPresent
              name: hello-app
              resources: {}
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
            dnsPolicy: ClusterFirst
            restartPolicy: Always
            schedulerName: default-scheduler
            securityContext: {}
            terminationGracePeriodSeconds: 30 
            volumes:
            - configMap:
                defaultMode: 256
                name: nginxthroughpass
                optional: false
              name: nginxconf
            - name: foo
              secret:
                defaultMode: 420
                items:
                - key: tls.crt
                  path: tls.crt
                - key: tls.key
                  path: tls.key
                secretName: nginx-prod
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多