当前位置:网站首页>Notes on the use of local persistent volumes by kubernetes

Notes on the use of local persistent volumes by kubernetes

2020-12-08 10:54:11 itread01

### Welcome to my GitHub [https://github.com/zq2599/blog_demos](https://github.com/zq2599/blog_demos) Content : All original articles classified summary and supporting original code , involve Java、Docker、Kubernetes、DevOPS etc. ; ### About Local Persistent Volumes In the article Local Persistent Volumes Abbreviated as Local PV; 1. Kubernetes Of Local PV since 1.7 Version alpha waive , stay 1.10 edition beta waive , The final official release (General Availability) Is in 1.14 edition ; 2. One Local PV Corresponds to a local disk space on the specified node ; 3. comparison NFS Remote storage like that ,Local PV Provides local IO Better performance ; ### and HostPath Volume The difference between Local PV Before it appeared , The way to use a local disk is HostPath Volume, Using local disk , What's the difference ? 1. The most important difference , Namely Local PV It's related to specific nodes , This means using Local PV Of pod, Restart many times will be Kubernetes scheduler Schedule to the same node , And if you use HostPath Volume, Every time you restart, it can be Kubernetes scheduler Schedule to a new node , Then use the same local path ; 2. When we want to use HostPath Volume When , Can be in PVC Declare , You can also write directly Pod The configuration of , however Local PV Only in PVC Declare , For PV Resources , It's usually managed by someone , This avoids Pod Conflicts and risks caused by unauthorized use of local disks by developers ; 3. Another thing to note ,HostPath Volume and Local PV They're all using local disks , Compared with the common distributed file system , A local disk failure can cause data loss , Do not use when storing important information HostPath Volume and Local PV; That's the basic concept , Next, the actual experience ; ### Actual combat environment information 1. The operating system :CentOS Linux release 7.8.2003 (Core) 2. kubernetes:1.15.3 3. helm:2.16.1 ### Experience Local PV A brief description of the steps of The goal of this actual combat is to quickly establish Local PV, And verify that Local PV Normally available , The paper consists of the following parts : 1. establish Local PV; 2. Through helm Download tomcat Of chart; 3. modify chart, Let tomcat Use the Local PV; 4. Deploy tomcat; 5. Check that the folder is properly written on the server ; ### Reference article If you want to know Kubernetes and helm More information about , Please refer to : 1. [《kubespray2.11 Install kubernetes1.15》](https://xinchen.blog.csdn.net/article/details/103106314); 2. [《 Deploy and experience Helm(2.16.1 edition )》](https://xinchen.blog.csdn.net/article/details/103667500); Ready , Start practicing ; ### establish PV 1. stay kubernetes The work node creates a folder for Local PV Use , I am :/root/temp/202005/24/local-pv/ 2. Write and read permissions to the above folder :chmod -R a+r,a+w /root/temp/202005/24/local-pv 3. Establish archives local-storage-pv.yaml, The content is as follows : ```yaml apiVersion: v1 kind: PersistentVolume metadata: name: example-pv spec: capacity: storage: 10Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: local-storage local: path: /root/temp/202005/24/local-pv nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - node1 ``` 4. About local-storage-pv.yaml There are several points to pay attention to : a. spec.storageClassName Equal to local-storage, Back PVC You should also specify storageClassName Equal to local-storage; b. spec.nodeAffinity Is a required argument , Used to establish Local PV The relationship with the node ,spec.nodeAffinity.required,nodeSelectorTerms.matchExpressions.values The value of contains node1, Indicates the Local PV You can use the host name node1 Node establishment of ; 5. Carry out orders kubectl apply -f local-storage-pv.yaml, You can create PV; 6. Execute kubectl describe pv example-pv Check whether the establishment is successful , As shown in the red box below , this PV Already available : ![ Insert picture description here ](https://img2020.cnblogs.com/other/485422/202012/485422-20201208074135716-846394936.png) ### Use PV Next through helm Deploy tomcat, And let tomcat Use the above Local PV, Please make sure helm It's loaded ; 1. increase helm Warehouse ( With tomcat Warehouse of ):helm repo add bitnami https://charts.bitnami.com/bitnami 2. Download tomcat Of chart:helm fetch bitnami/tomcat 3. chart After the download is successful , The current directory appears tomcat Configure the compressed package tomcat-6.2.4.tgz, Unloading :tar -zxvf tomcat-6.2.4.tgz 4. Decompress to get tomcat Folder , Open after entering values.yaml Archives , find persistence Node , Add the content in the red box below : ![ Insert picture description here ](https://img2020.cnblogs.com/other/485422/202012/485422-20201208074137005-1268924347.png) 5. stay tomcat Execute command under directory :helm install --name-template tomcat001 -f values.yaml . --namespace hello-storageclass 6. Look at tomcat Of pod and service The situation , Everything is all right , And the port is mapped to the host's 31835: ![ Insert picture description here ](https://img2020.cnblogs.com/other/485422/202012/485422-20201208074137752-239355716.png) 7. Browser access host IP:31835, Come on tomcat Welcome page : ![ Insert picture description here ](https://img2020.cnblogs.com/other/485422/202012/485422-20201208074138873-1832822747.png) 8. Go to the catalog /root/temp/202005/24/local-pv/ Check disk usage , Here's the picture , Visible assigned to tomcat Of PVC, And wrote tomcat The basic information of : ![ Insert picture description here ](https://img2020.cnblogs.com/other/485422/202012/485422-20201208074139832-771586843.png) 9. Examine again Local PV, Found that the state has changed : ![ Insert picture description here ](https://img2020.cnblogs.com/other/485422/202012/485422-20201208074141001-1061044729.png) At this point we can confirm that ,tomcat Using the Local PV, The data is stored in the specified folder of the host ; ### clear Local PV 1. In general , clear PV Do the following : a. Delete pod, perhaps deployment; b. Delete pvc; c. Delete Local PV; 2. Because of the use of helm, So through helm Combine the above steps 1 and 2 Execute it , Both orders helm delete tomcat001 3. And then local-storage-pv.yaml Execute in the directory kubectl delete -f local-storage-pv.yaml You can delete Local PV; thus ,Local PV The study and practice of the project is completed , If you are using this storage , I hope this article can give you some reference ; ### You're not alone , Xinchen's original works are accompanied all the way 1. [Java series ](https://xinchen.blog.csdn.net/article/details/105068742) 2. [Spring series ](https://xinchen.blog.csdn.net/article/details/105086498) 3. [Docker series ](https://xinchen.blog.csdn.net/article/details/105086732) 4. [kubernetes series ](https://xinchen.blog.csdn.net/article/details/105086794) 5. [ Database + Intermediary software series ](https://xinchen.blog.csdn.net/article/details/105086850) 6. [DevOps series ](https://xinchen.blog.csdn.net/article/details/105086920) ### Welcome to the public account : Programmer Xinchen > Wechat search 「 Programmer Xinchen 」, I'm Xinchen , Looking forward to traveling with you Java The world ... [https://github.com/zq2599/blog_demos](https://github.com/zq2599/blo

版权声明
本文为[itread01]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201208105334088d.html