# Mount File System (K8s)

Mounting notes:
1. If the K8s product used is the UK8S product service officially provided by DezaiCloud, please refer to UK8S Mounting UPFS for the specific mounting method.
2. If the K8s product used is a self-built K8s service, please refer to the following mounting steps for the specific mounting method.

## Step 1: Install the client

When mounting in K8s mode, you need to install the UPFS client on all work nodes of K8s first. Please check [UPFS client installation](/docs/upfs/client_install) for the client installation steps.

## Step 2: Install the csi tool package

It is necessary to install the CSI toolkit on the master node. For detailed steps, please see below.

   1. Obtain the csi tool package. Before obtaining the csi tool package, please confirm that the current K8s cluster has configured Eip for flexible external network. After confirming, execute the following command to get the csi tool package.

```shell
wget https://upfs-public.cn-bj.ufileos.com/csi-upfs.tar.gz
```

   2. Execute the following command to unzip the csi tool package.

```shell
tar zxvf csi-upfs.tar.gz
```
   3. Execute the following command under the node where kubectl is installed to install the csi tool package.

```shell
kubectl apply -f rbac-controller.yml
kubectl apply -f rbac-node.yml
kubectl apply -f csi-controller.yml
kubectl apply -f csi-node.yml
```
   4. Execute the following command to verify whether the installation is successful.

```shell
kubectl get po -A | grep upfs
```

   If there is POD information and the status is Running, it means that the installation is successful.

   <!-- image-todo -->

## Step 3: Create the UPFS file system K8s cluster configuration file

It is necessary to create the UPFS file system K8s cluster configuration file on the master node. For detailed steps, please see below.

   1. Here you need to create a StorageClass and PVC. The content of the configuration file refers to the following content, and name the configuration file ```storageclass.yaml``` (the file name can be customized). Note the following points:
   
      - uri: File System URL (For the detailed rules of the URL, please see the file system URL part in [Main Concepts](/docs/upfs/upfs_manual_instruction/concept))
      - path: The subdirectory for container to mount UPFS file system, and default is ```/```

```yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: csi-upfs
provisioner: upfs.csi.ucloud.cn
parameters:
  uri: 100.64.240.97:10109,100.64.240.95:10109/upfs-y0gprzs5a12
  path: /mnt
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: logupfs-claim
spec:
  storageClassName: csi-upfs
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi  # The theoretical limit of UPFS storage space is high, so the capacity parameters in PV and PVC have no actual significance, and the request information here will not actually take effect
```

   2. Run the following command to create StorageClass and PVC,

```shell
kubectl apply -f storageclass.yaml
```

## Step 4: Create a POD to use the UPFS file system

It is necessary to create a POD on the master node to use the UPFS file system. For detailed steps, please see below.

   1. Create a POD to use the UPFS file system. The configuration file content is as follows, and name the configuration file pod.yaml (the file name can be customized). Note the following points:

       - containers: Configuration information, configured according to actual circumstances
       - mountPath: The path in containers to mount UPFS
       - claimName: Here you need to specify the name of the UPFS PVC created in step 3

```yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx-upfs
spec:
  containers:
    - name: nginx
      image: uhub.service.ucloud.cn/ucloud/nginx:latest
      ports:
        - containerPort: 80
      volumeMounts:
        - name: test
          mountPath: /data
  volumes:
    - name: test
      persistentVolumeClaim:
        claimName: logupfs-claim
```

   2. Run the following command to create the POD:

```shell
kubectl apply -f pod.yaml
```
UPFS supports multi-POD mounting to access the UPFS file system. Similarly, create multi-POD configuration files as above.

## Step 5: Verify if the POD is running normally

   1. Execute the following command to Enter the POD created in the last step.

```shell
kubectl exec -it <POD name> /bin/bash
```
   2. Execute the following command to check whether the file system is mounted. If the result includes the ID of the file system resource to be mounted in step 3, it means that the mount is successful.

```shell
kubectl apply -f pod.yaml
```
<!-- image-todo -->

**If there is a problem with mounting the file system, please contact the technical support of DezaiCloud in time.**
