Technology Encyclopedia Home >How to mount CFS/NFS in Container Service?

How to mount CFS/NFS in Container Service?

To mount CFS (Cloud File System) or NFS (Network File System) in Container Service, you typically follow these steps:

  1. Create a File System: First, you need to create a CFS or NFS file system in your cloud environment. For example, in Tencent Cloud, you would create a CFS instance through the Tencent Cloud Console.

  2. Configure Access Permissions: Ensure that the file system has the appropriate access permissions set up so that your container service can access it. This might involve setting up security groups or network policies.

  3. Mount the File System in Container Service:

    • For Kubernetes: You can use Persistent Volumes (PVs) and Persistent Volume Claims (PVCs) to mount the file system. You would define a PV that references your CFS or NFS instance and then create a PVC that requests storage from this PV. Finally, you would mount the PVC to your pod.

      apiVersion: v1
      kind: PersistentVolume
      metadata:
        name: cfs-pv
      spec:
        capacity:
          storage: 10Gi
        accessModes:
          - ReadWriteMany
        nfs:
          server: cfs-server-address
          path: "/path/to/cfs"
      ---
      apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: cfs-pvc
      spec:
        accessModes:
          - ReadWriteMany
        resources:
          requests:
            storage: 10Gi
      

      Then, in your pod definition, you would mount the PVC:

      apiVersion: v1
      kind: Pod
      metadata:
        name: mypod
      spec:
        containers:
        - name: mycontainer
          image: myimage
          volumeMounts:
          - mountPath: "/mnt/cfs"
            name: cfs-volume
        volumes:
        - name: cfs-volume
          persistentVolumeClaim:
            claimName: cfs-pvc
      
    • For Docker Swarm: You can mount the file system directly when deploying a service. For example:

      docker service create \
        --name myservice \
        --mount type=volume,src=cfs-volume,dst=/mnt/cfs \
        myimage
      

      You would need to create the volume cfs-volume beforehand, specifying the CFS or NFS details.

  4. Verify the Mount: After deploying your container service, verify that the file system is correctly mounted by accessing the mount point inside your container.

Example with Tencent Cloud:

  • Create CFS: Go to the Tencent Cloud Console, navigate to CFS, and create a new file system.
  • Configure Permissions: Ensure the CFS instance is accessible from your container service's network.
  • Mount in Kubernetes: Use the PV and PVC method described above, replacing cfs-server-address and /path/to/cfs with the actual details from your Tencent Cloud CFS instance.

By following these steps, you can effectively mount CFS or NFS in your container service, enabling shared storage across multiple containers or services.