Kubernetes 未安装卷

Kubernetes 未安装卷

我有以下 daemonset.yaml 文件,在部署该文件时出现错误

**Please mount it as a Docker volume before starting the container.**

在本地,我有一个名为 keys 的文件夹,其中包含两个文件 ->mail.privatemail.txt。我尝试使用卷和 volumeMounts 将这些文件复制到容器,但出现此错误

Cannot load the 'mail.private' file from '/etc/opendkim/domainkeys/mail.private'. Please mount it as a Docker volume before starting the container.
kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: postfix
  namespace: mailserver
  labels:
    app: postfix
spec:
  selector:
    matchLabels:
      app: postfix
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: postfix
    spec:
      serviceAccountName: postfix
      terminationGracePeriodSeconds: 30
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet      
      containers:
      - image: <domain>/postfix:2.0        
        name: postfix
        env:
        - name: DOMAIN
          value: iogrids.com
        volumeMounts:
        - mountPath: /etc/opendkim/domainkeys/mail.private
          name: dkim-volume
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 2
          tcpSocket:
            port: 25
          initialDelaySeconds: 10
          periodSeconds: 60
        readinessProbe:
          failureThreshold: 2
          tcpSocket:
            port: 25
          periodSeconds: 60
        resources:
          requests:
            memory: "32Mi"
            cpu: "50m"
          limits:
            memory: "64Mi"
            cpu: "50m"
        ports:
        - name: smtp
          containerPort: 25
          hostPort: 25
        securityContext:
          capabilities:
            drop:
            - ALL
            add:
            - DAC_OVERRIDE
            - FOWNER
            - SETUID
            - SETGID
            - NET_BIND_SERVICE
      volumes:
      - name: dkim-volume
        hostPath:
          # directory location on host
          path: /root/keys/mail.private

答案1

这是社区 Wiki 答案,发布它是为了提高可见性,因此请随意编辑它并添加您认为重要的任何其他详细信息。

正如评论中提到的那样,该问题已经通过以下方式解决初始化容器以确保在主容器启动之前加载该文件。

最初的问题是由于主容器启动后卷被挂载引起的。

相关内容