kubernetes nfs存储

kx5bkwkv  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(481)

我在virtualbox中运行了一个3节点集群,我正在尝试使用pv和pvc创建一个nfs存储,但似乎我做错了什么。
我有以下几点:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: redis-pv
  labels:
    type: nfs
spec:
  capacity:
    storage: 100Mi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: slow
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /redis/data
    server: 192.168.56.2 #ip of my master-node
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: redis-pvc
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 100Mi
  storageClassName: slow
  selector:
    matchLabels:
      type: nfs
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-master
  labels:
    app: redis
spec:
  selector:
    matchLabels:
      app: redis
      role: master
      tier: backend
  replicas: 1
  template:
    metadata:
      labels:
        app: redis
        role: master
        tier: backend
    spec:
      containers:
      - name: master
        image: redis
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        volumeMounts:
        - name: data
          mountPath: "/redis/data"
        ports:
        - containerPort: 6379
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: redis-pvc

我已经安装了 nfs-common 在我所有的节点中。
每当创建pv、pvc和pod时,pod不会启动,我得到以下结果:

Warning  FailedMount  30s    kubelet, kubenode02  MountVolume.SetUp failed for volume "redis-pv" : mount failed: exit status 32
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/9326d818-b78a-42cc-bcff-c487fc8840a4/volumes/kubernetes.io~nfs/redis-pv --scope -- mount -t nfs -o hard,nfsvers=4.1 192.168.56.2:/redis/data /var/lib/kubelet/pods/9326d818-b78a-42cc-bcff-c487fc8840a4/volumes/kubernetes.io~nfs/redis-pv
Output: Running scope as unit run-rc316990c37b14a3ba24d5aedf66a3f6a.scope.
mount.nfs: Connection timed out

以下是 kubectl get pv, pvc ```
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/redis-pv 100Mi RWO Retain Bound default/redis-pvc slow 8s

NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/redis-pvc Bound redis-pv 100Mi RWO slow 8s

你知道我遗漏了什么吗?
shstlldc

shstlldc1#

1-您需要安装nfs服务器:按照此链接中的说明进行操作:
https://vitux.com/install-nfs-server-and-client-on-ubuntu/
2-在要保存数据的位置创建共享文件夹<

mount 192.168.56.2:/mnt/sharedfolder /mnt/shared/folder_client

3-pv.yaml中的变更遵循以下说明:

apiVersion: v1

    kind: PersistentVolume
    metadata:
      name: redis-pv
      labels:
        type: nfs
    spec:
      capacity:
        storage: 100Mi
      volumeMode: Filesystem
      accessModes:
        - ReadWriteOnce
      persistentVolumeReclaimPolicy: Retain
      storageClassName: slow
      mountOptions:
        - hard
        - nfsvers=4.1
      nfs:
        path: /mnt/sharedfolder
        server: 192.168.56.2 #ip of my master-node

相关问题