使用NFS卷时,容器无法在Kubernetes中启动

时间:2019-07-09 10:03:05

标签: docker kubernetes devops nfs pod

我正在使用nfs在kubernetes容器中部署卷。 以下是所有文件的详细信息。 文件名:-nfs-server.yaml

kind: Service
apiVersion: v1
metadata:
  name: nfs-service
spec:
  selector:
    role: nfs
  ports:
    # Open the ports required by the NFS server
    # Port 2049 for TCP
    - name: tcp-2049
      port: 2049
      protocol: TCP

    # Port 111 for UDP
    - name: udp-111
      port: 111
      protocol: UDP

---
kind: Pod
apiVersion: v1
metadata:
  name: nfs-server-pod
  labels:
    role: nfs
spec:
  containers:
    - name: nfs-server-container
      image: cpuguy83/nfs-server
      securityContext:
        privileged: true
      args:
        # Pass the paths to share to the Docker image
        - /exports

服务和pod都在运行。以下是输出。 enter image description here

现在我必须在Web服务器中使用它。以下是Web部署文件的详细信息。 文件名:-deployment.yaml

apiVersion: v1
kind: Service
metadata:
  name: apache-service
spec:
  selector:
    app: apache
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  type: NodePort

---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: apache-deployment
spec:
  selector:
    matchLabels:
      app: apache
  replicas: 1 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: apache
    spec:    
      volumes:
        - name: nfs-volume
          nfs: 
            server: 10.99.56.195
            path: /exports  
      containers:
        - name: apache
          image: mobingi/ubuntu-apache2-php7:7.2
          ports:
          - containerPort: 80
          volumeMounts:
          - name: nfs-volume
            mountPath: /var/www/html 

当我不带卷运行此文件时,一切正常。但是当我用nfs而不是pod运行它时,出现以下错误。

enter image description here

kubectl描述pod apache-deployment-577ffcf9bd-p8s75

提供以下输出:-

Name:           apache-deployment-577ffcf9bd-p8s75
Namespace:      default
Priority:       0
Node:           worker-node2/10.160.0.4
Start Time:     Tue, 09 Jul 2019 09:53:39 +0000
Labels:         app=apache
                pod-template-hash=577ffcf9bd
Annotations:    <none>
Status:         Pending
IP:             
Controlled By:  ReplicaSet/apache-deployment-577ffcf9bd
Containers:
  apache:
    Container ID:   
    Image:          mobingi/ubuntu-apache2-php7:7.2
    Image ID:       
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       ContainerCreating
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-p9qdb (ro)
      /var/www/html from nfs-volume (rw)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  nfs-volume:
    Type:      NFS (an NFS mount that lasts the lifetime of a pod)
    Server:    10.244.1.50
    Path:      /exports
    ReadOnly:  false
  default-token-p9qdb:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-p9qdb
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason       Age    From                   Message
  ----     ------       ----   ----                   -------
  Normal   Scheduled    6m21s  default-scheduler      Successfully assigned default/apache-deployment-577ffcf9bd-p8s75 to worker-node2
  Warning  FailedMount  4m16s  kubelet, worker-node2  MountVolume.SetUp failed for volume "nfs-volume" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/29114119-5815-442a-bb97-03fa491206a4/volumes/kubernetes.io~nfs/nfs-volume --scope -- mount -t nfs 10.244.1.50:/exports /var/lib/kubelet/pods/29114119-5815-442a-bb97-03fa491206a4/volumes/kubernetes.io~nfs/nfs-volume
Output: Running scope as unit: run-r3a55a8a3287448a59f7e4dbefa0333af.scope
mount.nfs: Connection timed out
  Warning  FailedMount  2m10s  kubelet, worker-node2  MountVolume.SetUp failed for volume "nfs-volume" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/29114119-5815-442a-bb97-03fa491206a4/volumes/kubernetes.io~nfs/nfs-volume --scope -- mount -t nfs 10.244.1.50:/exports /var/lib/kubelet/pods/29114119-5815-442a-bb97-03fa491206a4/volumes/kubernetes.io~nfs/nfs-volume
Output: Running scope as unit: run-r5fe7befa141d4f989e14b291afa43208.scope
mount.nfs: Connection timed out
  Warning  FailedMount  2m3s (x2 over 4m18s)  kubelet, worker-node2  Unable to mount volumes for pod "apache-deployment-577ffcf9bd-p8s75_default(29114119-5815-442a-bb97-03fa491206a4)": timeout expired waiting for volumes to attach or mount for pod "default"/"apache-deployment-577ffcf9bd-p8s75". list of unmounted volumes=[nfs-volume]. list of unattached volumes=[nfs-volume default-token-p9qdb]
  Warning  FailedMount  4s                    kubelet, worker-node2  MountVolume.SetUp failed for volume "nfs-volume" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/29114119-5815-442a-bb97-03fa491206a4/volumes/kubernetes.io~nfs/nfs-volume --scope -- mount -t nfs 10.244.1.50:/exports /var/lib/kubelet/pods/29114119-5815-442a-bb97-03fa491206a4/volumes/kubernetes.io~nfs/nfs-volume
Output: Running scope as unit: run-rd30c104228ae43df933839b6da469107.scope
mount.nfs: Connection timed out

任何人都可以帮助解决这个问题。

1 个答案:

答案 0 :(得分:0)

  1. 确保节点之间没有防火墙

  2. 确保在群集节点上安装了nfs-utils

  3. 这是有关用于nfs服务器的docker映像的博客文章,您需要对nfs服务器要使用的端口进行一些调整。

https://medium.com/@aronasorman/creating-an-nfs-server-within-kubernetes-e6d4d542bbb9