K8s: 持久化存储之卷, NFS卷

  • $ vi nfs-demo1.yaml 编写yaml文件进行测试
    apiVersion: v1
    kind: Pod
    metadata:
      name: nfs-pd
    spec:
      containers:
      - name: test-container
        image: nginx
        volumeMounts: # 上面的容器内挂载目录为
        - mountPath: /usr/share/nginx/html
          name: test-volume
      volumes: # 物理机
      - name: test-volume
        nfs:
          server: master.k8s # 这里配置的是 master 节点的 hostname
          path: /nfsdata
    
  • $ kubectl get po -w 监控 nfs pod 的状态
    NAME           READY   STATUS    RESTARTS       AGE
    nfs-pd         1/1     Running   0              36s
    
  • $ kubectl exec -it nfs-pd -- sh 进入pod
  • $ mount 执行 mount 看容器起来后,挂载哪些卷,这里是全部的
    overlay on / type overlay (rw,relatime,lowerdir=/var/lib/docker/overlay2/l/TGJN2AK5DUCHXGQSXLTICMH6CV:/var/lib/docker/overlay2/l/4EYRGAW5MFRGLIJKCOJFKWNRDT:/var/lib/docker/overlay2/l/Y5QO2NJ6REXYEVRYLCHKIWZOLG:/var/lib/docker/overlay2/l/T5HUWMG4LKHET6APDBVJ25QIPE:/var/lib/docker/overlay2/l/PCJEGNJOYLSPYYP5TJBFNNAPF6:/var/lib/docker/overlay2/l/4EUOTLMHJJFA2AXOALXRHNAIOA:/var/lib/docker/overlay2/l/7WCTJFFWY4TZNAN3GM4JWTIBSV:/var/lib/docker/overlay2/l/UI7F22MIRB2NZSHHGF6U6IJU2U,upperdir=/var/lib/docker/overlay2/f3010a94dda626c9b3f8249c61f03b3e6caf6557b1193d7f9979308f7bf8d4e5/diff,workdir=/var/lib/docker/overlay2/f3010a94dda626c9b3f8249c61f03b3e6caf6557b1193d7f9979308f7bf8d4e5/work)
    proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
    tmpfs on /dev type tmpfs (rw,nosuid,size=65536k,mode=755,inode64)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
    sysfs on /sys type sysfs (ro,nosuid,nodev,noexec,relatime)
    cgroup on /sys/fs/cgroup type cgroup2 (ro,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)
    mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
    shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=65536k,inode64)
    /dev/mapper/cs-root on /dev/termination-log type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
    /dev/mapper/cs-root on /etc/resolv.conf type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
    /dev/mapper/cs-root on /etc/hostname type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
    /dev/mapper/cs-root on /etc/hosts type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
    master.k8s:/nfsdata on /usr/share/nginx/html type nfs4 (rw,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.211.55.12,local_lock=none,addr=10.211.55.13)
    tmpfs on /run/secrets/kubernetes.io/serviceaccount type tmpfs (ro,relatime,size=1704516k,inode64)
    proc on /proc/asound type proc (ro,nosuid,nodev,noexec,relatime)
    proc on /proc/bus type proc (ro,nosuid,nodev,noexec,relatime)
    proc on /proc/fs type proc (ro,nosuid,nodev,noexec,relatime)
    proc on /proc/irq type proc (ro,nosuid,nodev,noexec,relatime)
    proc on /proc/sys type proc (ro,nosuid,nodev,noexec,relatime)
    proc on /proc/sysrq-trigger type proc (ro,nosuid,nodev,noexec,relatime)
    tmpfs on /proc/acpi type tmpfs (ro,relatime,inode64)
    tmpfs on /proc/kcore type tmpfs (rw,nosuid,size=65536k,mode=755,inode64)
    tmpfs on /proc/keys type tmpfs (rw,nosuid,size=65536k,mode=755,inode64)
    tmpfs on /proc/timer_list type tmpfs (rw,nosuid,size=65536k,mode=755,inode64)
    tmpfs on /proc/scsi type tmpfs (ro,relatime,inode64)
    tmpfs on /sys/firmware type tmpfs (ro,relatime,inode64)
    
  • $ mount | grep nfs 查看 nfs 挂载效果
    master.k8s:/nfsdata on /usr/share/nginx/html type nfs4 (rw,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.211.55.12,local_lock=none,addr=10.211.55.13)
    
  • 在 node 节点上创建文件并写入数据
    • $ cd /usr/share/nginx/html
    • $ touch x.txt
    • $ echo nfs > x.txt
    • $ cat x.txt
      nfs
      
  • 上一篇:无人机GB42590接收端 +接收端模组,同时支持2.4G与5.8G双频


    下一篇:【数据结构】顺序表