K8s uses NFS of Qunhui ds218 +

Time:2021-1-12

Welcome to my GitHub

https://github.com/zq2599/blog_demos

Content: all the original articles and supporting source code, including Java, docker, kubernetes, Devops, etc;

Qunhui and k8s+

  1. When learning k8s, you often use network storage, so you want to find a stable NFS service. It happens that the Qunhui ds218 + at home has been open for a long time, and the space is sufficient, which is very suitable for providing NFS service. This article is a note on the process of setting and using;
  2. The following figure shows what ds218 + just bought. It has two NAS hard disks and has been serving stably
    在这里插入图片描述

Full text overview

  1. Set NFS;
  2. NFS client installs NFS application;
  3. Setting on k8s;
  4. Create storage volume;
  5. Create Tomcat
  6. Access Tomcat service

environmental information

  1. Qunhui system: DSM 6.2.2-24922 update 4
  2. Kubernetes:1.15
  3. Kubernetes host: CentOS Linux release 7.7.1908
  4. Helm:2.16.1

Reference article

This paper focuses on the actual combat of k8s, so it needs a certain k8s foundation. Please refer to:

  1. Kubespray 2.11 installing kubernetes 1.15
  2. Deploying and experiencing helm (version 2.16.1)
  3. Installation and use of NFS in Ubuntu 16 environment

If you are ready for Qunhui, k8s and helm, let’s fight.

Set up NFS

  1. Website login Qunhui,Control Panel > shared folder
    在这里插入图片描述
  2. New shared folder:
    在这里插入图片描述
  3. Next is the encryption settings, here is not set encryption, directly clicknext step
    在这里插入图片描述
  4. Advanced settings page, please set on demand, here for simple and directnext step
    在这里插入图片描述
  5. Click apply to create a folder, and then set NFS, as shown in the following figure:
    在这里插入图片描述
  6. As shown in the figure below, note the NFS path in red box 1/volume1/nfs-tomcat(to be used later), and then click the red box 2:
    在这里插入图片描述
  7. In addition to NFS settings, you should also set permissions for this folder,Otherwise, an error will be reported during remote writing, as shown in the figure below, open the file station to see thenfs-tomcatThis is the local disk directory corresponding to the NFS directory. Right click on it and selectattribute
    在这里插入图片描述
  8. In the pop-up property page, add a permission configuration. Please set it according to your actual needs. Here, to save trouble, anyone can operate it
    在这里插入图片描述
    So far, the NFS setting on Qunhui is completed. Next, run an application in k8s to use the NFS storage;

Client for NFS installation

Users of NFS need to install clients. Here, k8s needs to use NFS. Therefore, to install client applications on k8s hosts is to execute commands for CentOSyum install nfs-utils -y

Create a persistent volume (PV)

PV is a common storage type in k8s. Here, create an NFS type PV:

  1. SSH login k8s;
  2. Create a namespace:kubectl create namespace tomcat-test
  3. New name istomcat-test-pv.yamlThe contents of the document are as follows, please notenfs.serverIs the IP address of Qunhui, nfs.path The value of is recorded when the shared file was created/volume1/nfs-tomcat
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 belowpv-tomcat-testThe PV state of isAvailable, indicating idle state, which can be used by k8s:
    在这里插入图片描述
  3. Now the PV is created successfully. Next, create Tomcat through helm to use the 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 chart is downloaded successfully, the Tomcat configuration package tomcat-6.2.4.tgz appears in the current directorytar -zxvf tomcat-6.2.4.tgz
  4. After decompression, the Tomcat folder appears. After entering, open the filetemplates/pvc.yaml, all contents remain unchanged, only the contents in the red box below are added at the end:
    在这里插入图片描述
  5. The content in the red box above is easy to understand: add a selector and use the PV you just created
  6. Go back to the Tomcat folder and execute the command to create the Tomcathelm install –name-template tomcat001 -f values.yaml . –namespace tomcat-test
  7. Check the PV status, it can be seen that it has been used (the other PV is still idle, indicating that it is in thepvc.yamlThe selector set in is valid:
    在这里插入图片描述
  8. Continue to check the pod and service. Everything is normal. At the same time, it is found that the service port of Tomcat is mapped to port 30512 of the host
    在这里插入图片描述
  9. Browser accessHost IP: 30512To open the Tomcat welcome page normally:
    在这里插入图片描述
  10. Go back to Qunhui’s webpage and open the file station. You can see that a lot of content has been written in the NFS Tomcat directory, which is the internal file of Tomcat
    在这里插入图片描述
    So far, k8s has successfully used the NFS service provided by Qunhui. In the future k8s learning, it has a stable NFS service, and thanks to the security of Qunhui’s file system, the data security has also been improved;

Welcome to the official account: programmer Xin Chen

Wechat search “programmer Xinchen”, I’m Xinchen, looking forward to enjoying the Java world with you
https://github.com/zq2599/blog_demos