K8S uses NFS of Synology DS218 +

Synology and K8S +

  1. Network storage is often used when learning K8S, so I want to find a stable NFS service. The Synology DS218 + at home is open for a long time, and the space is sufficient. It is suitable for providing NFS services. This article is a reminder of the process of setting up and using;
  2. The picture below is what DS218 + just bought. Two NAS hard drives have been in stable service:
    Insert picture description here

Full text overview

  1. Set up NFS;
  2. NFS client installs NFS application;
  3. Settings on K8S;
  4. Create a storage volume;
  5. Create Tomcat
  6. Access Tomcat service

Environmental information

  1. Synology System: DSM 6.2.2-24922 Update 4
  2. Governors : 1.15
  3. Kubernetes host: CentOS Linux release 7.7.1908
  4. Helm:2.16.1

Reference article

This article focuses on K8S actual combat, so a certain K8S foundation is required, please refer to:

  1. "Kubespray2.11 install kubernetes1.15"
  2. "Deploy and Experience Helm (Version 2.16.1)"
  3. "Install and use NFS in Ubuntu16 environment"

If you have already prepared Synology, K8S, Helm, let's go to combat.

Setting up NFS

  1. Log in to Synology on the web, control panel-> shared folder ;
    Insert picture description here
  2. New shared folder:
    Insert picture description here
  3. Next is the encryption settings, here is to set no encryption, click next directly :
    Insert picture description here
  4. Advanced settings page, please set as needed, here is the next step for simplicity :
    Insert picture description here
  5. Click Apply to create the folder, and then do NFS settings, as shown below:
    Insert picture description here
  6. As shown below, write down the NFS path / volume1 / nfs-tomcat in red box 1 (will be used later), and then click on red box 2:
    Insert picture description here
  7. In addition to NFS setting, also set permissions for this folder, or when the remote will write error , as shown below, open the File Station to see the red box 2 nfs-Tomcat , this is a local disk directory corresponding directory NFS , Click the right mouse button on the top, select properties :
    Insert picture description here
  8. In the pop-up property page, add a permission configuration. Please set it according to your actual needs. Here, it is set to be anyone can operate in order to save trouble:
    Insert picture description here
    At this point, the NFS on Synology is set up, then run an application on K8S This NFS storage;

NFS client installation

NFS users need to install the client. Here is K8S to use NFS, so to install the client application on the K8S host, for CentOS is to execute the command: yum install nfs-utils -y

Create a storage volume (PersistentVolume referred to as PV)

PV is a commonly used storage type in K8S. Here we create an NFS type PV:

  1. SSH login to K8S;
  2. 创建namespace:kubectl create namespace tomcat-test
  3. Create a new file named tomcat-test-pv.yaml . The content is as follows. Note that the value of nfs.server is the IP address of Synology. The value of nfs.path is the / volume1 / nfs-tomcat that was recorded when the shared file was created. :
apiVersion: v1
kind: PersistentVolume
metadata:
 name: pv-tomcat-test
 namespace: tomcat-test
 labels:
   pv: pv-tomcat-test
spec:
 capacity:
   storage: 10Gi
 accessModes:
   - ReadWriteOnce
 persistentVolumeReclaimPolicy: Recycle
 nfs:
   path: /volume1/nfs-tomcat
   server: 192.168.50.42
  1. Create PV: kubectl apply -f tomcat-test-pv.yaml
  2. Check the PV, as shown in the figure below, the PV state named pv-tomcat-test is Available , which indicates that it is idle and can be used by K8S:
    Insert picture description here
  3. Now that the PV has been successfully created, the next step is to create a tomcat through Helm to use this PV;

Create Tomcat

  1. Add helm warehouse (warehouse with tomcat): helm repo add bitnami https://charts.bitnami.com/bitnami
  2. Download the chart of tomcat: helm fetch bitnami / tomcat
  3. After the download chart success, the current directory appears tomcat configuration archive tomcat-6.2.4.tgz, unpack: tar -zxvf tomcat-6.2.4.tgz
  4. After decompression, the tomcat folder appears. After entering, open the file templates / pvc.yaml . All the content remains unchanged. Only add the content in the red box at the end:
    Insert picture description here
  5. The content in the red box above is easy to understand: add a selector and use the PV just created
  6. Go back to the tomcat folder and execute the command to create tomcat: helm install --name-template tomcat001 -f values.yaml. --Namespace tomcat-test
  7. Check the PV status, you can see that it has been used (the other PV is still idle, indicating that the selector set in pvc.yaml is valid):
    Insert picture description here
  8. Continue to check the pod and service, everything is normal, and found that the tomcat service port is mapped to the host's port 30512:
    Insert picture description here
  9. The browser accesses the host IP: 30512 , and the tomcat welcome page can be opened normally:
    Insert picture description here
  10. Go back to the Synology webpage, open File Station, you can see that a lot of content has been written in the nfs-tomcat directory, which are all internal files of tomcat: So
    Insert picture description here
    far, K8S has successfully used the NFS service provided by Synology and will learn in the future K8S Among them, with the stable NFS service, and thanks to the security of Synology file system, the data security has also been improved;

Welcome to pay attention to my public number: programmer Xinchen

Insert picture description here

Published 376 original articles · praised 986 · 1.28 million views

Guess you like

Origin blog.csdn.net/boling_cavalry/article/details/105465233