服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

dirtysea 发表于 2021-8-5 11:10:37

k8s学习笔记之StorageClass+NFS

<h3 id="autoid-0-0-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">一、什么是StorageClass</span></h3><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">Kubernetes提供了一套可以自动创建PV的机制,即:Dynamic Provisioning.而这个机制的核心在于:StorageClass这个API对象.

StorageClass对象会定义下面两部分内容:
</span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">,PV的属性.比如,存储类型,Volume的大小等.
</span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">,创建这种PV需要用到的存储插件
有了这两个信息之后,Kubernetes就能够根据用户提交的PVC,找到一个对应的StorageClass,之后Kubernetes就会调用该StorageClass声明的存储插件,进而创建出需要的PV.
但是其实使用起来是一件很简单的事情,你只需要根据自己的需求,编写YAML文件即可,然后使用kubectl create命令执行即可</span></span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><h3 id="autoid-0-1-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">二、为什么需要StorageClass</span></h3><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;">在一个大规模的Kubernetes集群里,可能有成千上万个PVC,这就意味着运维人员必须实现创建出这个多个PV,此外,随着项目的需要,会有新的PVC不断被提交,那么运维人员就需要不断的添加新的,满足要求的PV,否则新的Pod就会因为PVC绑定不到PV而导致创建失败.而且通过 PVC 请求到一定的存储空间也很有可能不足以满足应用对于存储设备的各种需求
而且不同的应用程序对于存储性能的要求可能也不尽相同,比如读写速度、并发性能等,为了解决这一问题,Kubernetes 又为我们引入了一个新的资源对象:StorageClass,通过 StorageClass 的定义,管理员可以将存储资源定义为某种类型的资源,比如快速存储、慢速存储等,用户根据 StorageClass 的描述就可以非常直观的知道各种存储资源的具体特性了,这样就可以根据应用的特性去申请合适的存储资源了。</span></pre></div><h3 id="autoid-0-2-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">三、StorageClass运行原理及部署流程</span></h3><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">要使用 StorageClass,我们就得安装对应的自动配置程序,比如我们这里存储后端使用的是 nfs,那么我们就需要使用到一个 nfs-client 的自动配置程序,我们也叫它 Provisioner,这个程序使用我们已经配置好的 nfs 服务器,来自动创建持久卷,也就是自动帮我们创建 PV。</span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span>.自动创建的 PV 以${<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span>}-${pvcName}-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">${pvName}这样的命名格式创建在 NFS 服务器上的共享数据目录中
</span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2</span>.而当这个 PV 被回收后会以archieved-${<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span>}-${pvcName}-${pvName}这样的命名格式存在 NFS 服务器上。</span></pre></div><h6 id="autoid-0-3-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">1.原理及部署流程说明</span></h6><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>详细的运作流程可以参考下图:</strong></span></p><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;"><img src="https://img2018.cnblogs.com/i-beta/911490/202001/911490-20200115135841991-1378803950.png" alt="" class="medium-zoom-image" style="border: 0px; max-width: 100%; cursor: zoom-in; height: auto; transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1) 0s !important;"></span></p><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">&nbsp;</span></p><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>&nbsp;搭建StorageClass+NFS,大致有以下几个步骤:</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">.创建一个可用的NFS Serve
</span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">.创建Service Account.这是用来管控NFS provisioner在k8s集群中运行的权限
</span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">3</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">.创建StorageClass.负责建立PVC并调用NFS provisioner进行预定的工作,并让PV与PVC建立管理
</span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">4</span>.创建NFS provisioner.有两个功能,一个是在NFS共享目录下创建挂载点(volume),另一个则是建了PV并将PV与NFS的挂载点建立关联</span></pre></div><h3 id="autoid-0-3-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">四、创建StorageClass</span></h3><h6 id="autoid-0-4-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">1.创建NFS共享服务</span></h6><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>该步骤比较简单不在赘述,大家可以自行百度搭建</strong></span></p><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>当前环境NFS server及共享目录信息</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;">IP: <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">172.16</span>.<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">155.227</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
Export PATH: </span>/data/volumes/</span></pre></div><h6 id="autoid-0-4-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">2.使用以下文档配置account及相关权限</span></h6><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>rbac.yaml:&nbsp; &nbsp; &nbsp; #唯一需要修改的地方只有namespace,根据实际情况定义</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">apiVersion: v1
kind: ServiceAccount
metadata:
name: nfs</span>-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
# replace with </span><span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span> <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">where</span> provisioner <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">is</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> deployed
</span><span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span>: <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default      <strong><span style="line-height: 1.5; color: rgb(255, 0, 0);">#根据实际环境设定namespace,下面类同</span></strong></span>
---<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io</span>/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">v1
metadata:
name: nfs</span>-client-provisioner-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">runner
rules:
</span>- apiGroups: [<span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">""</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
    resources: [</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">persistentvolumes</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
    verbs: [</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">get</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">list</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">watch</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">create</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">delete</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
</span>- apiGroups: [<span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">""</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
    resources: [</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">persistentvolumeclaims</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
    verbs: [</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">get</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">list</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">watch</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">update</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
</span>- apiGroups: [<span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">storage.k8s.io</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
    resources: [</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">storageclasses</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
    verbs: [</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">get</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">list</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">watch</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
</span>- apiGroups: [<span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">""</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
    resources: [</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">events</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
    verbs: [</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">create</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">update</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">patch</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
</span>---<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io</span>/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">v1
metadata:
name: run</span>-nfs-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
subjects:
</span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> kind: ServiceAccount
    name: nfs</span>-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
    # replace with </span><span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span> <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">where</span> provisioner <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">is</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> deployed
    </span><span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span>: <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
roleRef:
kind: ClusterRole
name: nfs</span>-client-provisioner-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">runner
apiGroup: rbac.authorization.k8s.io
</span>---<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
kind: Role
apiVersion: rbac.authorization.k8s.io</span>/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">v1
metadata:
name: leader</span>-locking-nfs-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
    # replace with </span><span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span> <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">where</span> provisioner <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">is</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> deployed
</span><span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span>: <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
rules:
</span>- apiGroups: [<span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">""</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
    resources: [</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">endpoints</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
    verbs: [</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">get</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">list</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">watch</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">create</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">update</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>, <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">patch</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">]
</span>---<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io</span>/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">v1
metadata:
name: leader</span>-locking-nfs-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
subjects:
</span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> kind: ServiceAccount
    name: nfs</span>-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
    # replace with </span><span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span> <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">where</span> provisioner <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">is</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> deployed
    </span><span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span>: <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
roleRef:
kind: Role
name: leader</span>-locking-nfs-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
apiGroup: rbac.authorization.k8s.io</span></span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><h6 id="autoid-0-4-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">&nbsp;3.创建NFS资源的StorageClass</span></h6><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>nfs-StorageClass.yaml&nbsp;&nbsp;</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;">apiVersion: storage.k8s.io/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">v1
kind: StorageClass
metadata:
name: managed</span>-nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">storage
provisioner: qgg</span>-nfs-storage <span style="line-height: 1.5; color: rgb(255, 0, 0); font-family: &quot;Courier New&quot; !important;"><strong>#这里的名称要和provisioner配置文件中的环境变量PROVISIONER_NAME保持一致<br></strong></span></span>parameters:<br>archiveOnDelete: "false"</pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><h6 id="autoid-0-4-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">&nbsp;4.创建NFS provisioner</span></h6><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>nfs-provisioner.yaml</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;">apiVersion: apps/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">v1
kind: Deployment
metadata:
name: nfs</span>-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
labels:
    app: nfs</span>-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
# replace with </span><span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span> <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">where</span> provisioner <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">is</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> deployed
</span><span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span>: <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default<span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#与RBAC文件中的namespace保持一致</strong></span></span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
spec:
replicas: </span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
selector:
    matchLabels:
      app: nfs</span>-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
strategy:
    type: Recreate
selector:
    matchLabels:
      app: nfs</span>-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
template:
    metadata:
      labels:
      app: nfs</span>-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
    spec:
      serviceAccountName: nfs</span>-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
      containers:
      </span>- name: nfs-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner
          image: quay.io</span>/external_storage/nfs-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">provisioner:latest
          volumeMounts:
            </span>- name: nfs-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">root
            mountPath: </span>/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">persistentvolumes
          env:
            </span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> name: PROVISIONER_NAME<strong>
            value: qgg</strong></span><strong>-nfs-</strong><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"><strong>storage </strong> <span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#provisioner名称,请确保该名称与 nfs-StorageClass.yaml文件中的provisioner名称保持一致
            </strong></span></span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> name: NFS_SERVER
            value: </span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">172.16</span>.<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">155.227   <span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#NFS Server IP地址</strong></span></span>
            -<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> name: NFS_PATH
            value: </span>/data/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">volumes    <span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#NFS挂载卷</strong></span>
      volumes:
      </span>- name: nfs-client-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">root
          nfs:
            server: </span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">172.16</span>.<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">155.227<span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#NFS Server IP地址</strong></span></span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
            path: </span>/data/volumes   <span style="line-height: 1.5; color: rgb(255, 0, 0); font-family: &quot;Courier New&quot; !important;"><strong>#NFS 挂载卷</strong></span></span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><h3 id="autoid-0-4-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">五、创建测试pod,检查是否部署成功</span></h3><h6 id="autoid-0-5-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">1.Pod+PVC</span></h6><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">创建PVC</span></p><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>test-claim.yaml</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test</span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">claim
annotations:
    volume.beta.kubernetes.io</span>/storage-<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">class</span>: <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">managed-nfs-storage</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"   <span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#与nfs-StorageClass.yaml metadata.name保持一致</strong></span></span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
spec:
accessModes:
    </span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> ReadWriteMany
resources:
    requests:
      storage: 1Mi</span></span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>确保PVC状态为Bound</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"># kubectl <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">get</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> pvc
NAME         STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS          AGE
test</span>-claim   Bound    pvc-aae2b7fa-377b-11ea-87ad-525400512eca   1Mi      RWX            managed-nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">storage   2m48s
# kubectl <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">get</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                STORAGECLASS          REASON   AGE
pvc</span>-aae2b7fa-377b-11ea-87ad-525400512eca   1Mi      RWX            Delete         Bound    <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>/test-claim   managed-nfs-storage            4m13s</span></pre></div><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;"><strong><span style="line-height: 1.5; color: rgb(51, 102, 255);">创建测试pod,查看是否可以正常挂载</span></strong></span></p><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>test-pod.yaml</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">kind: Pod
apiVersion: v1
metadata:
name: test</span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">pod
spec:
containers:
</span>- name: test-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">pod
    image: busybox:</span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1.24</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
    command:
      </span>- <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">/bin/sh</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
    args:
      </span>- <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">-c</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span>
      - <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">touch /mnt/SUCCESS &amp;&amp; exit 0 || exit 1</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"   <span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#创建一个SUCCESS文件后退出</strong></span></span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
    volumeMounts:
      </span>- name: nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">pvc
      mountPath: </span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">/mnt</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
restartPolicy: </span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">Never</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
volumes:
    </span>- name: nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">pvc
      persistentVolumeClaim:
      claimName: test</span>-claim<span style="line-height: 1.5; color: rgb(255, 0, 0); font-family: &quot;Courier New&quot; !important;"><strong>#与PVC名称保持一致</strong></span></span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>检查结果:</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"># ll /data/volumes/<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>-test-claim-pvc-aae2b7fa-377b-11ea-87ad-525400512eca/   <span style="line-height: 1.5; color: rgb(255, 0, 0); font-family: &quot;Courier New&quot; !important;"><strong>#文件规则是按照${namespace}-${pvcName}-${pvName}创建的</strong></span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
总用量 </span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">0</span>
-rw-r--r-- <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span> root root <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">0</span> <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2020</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">01</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">15</span> <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">17</span>:<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">51</span> SUCCESS<span style="line-height: 1.5; color: rgb(255, 0, 0); font-family: &quot;Courier New&quot; !important;"><strong>#下面有一个 SUCCESS 的文件,证明我们上面的验证是成功</strong></span></span></pre></div><h6 id="autoid-0-5-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">2.StateFulDet+volumeClaimTemplates自动创建PV</span></h6><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>创建无头服务及statefulset</strong></span></p><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>nginx-statefulset.yaml</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;">---<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
apiVersion: v1
kind: Service
metadata:
name: nginx</span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">headless
labels:
    app: nginx
spec:
ports:
</span>- port: <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">80</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
    name: web
clusterIP: None   <span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#注意此处的值,None表示无头服务</strong></span>
selector:
    app: nginx
</span>---<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
apiVersion: apps</span>/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">v1beta1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: </span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">nginx</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
replicas: </span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2<span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#两个副本</strong></span></span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
template:
    metadata:
      labels:
      app: nginx
    spec:
      containers:
      </span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> name: nginx
      image: ikubernetes</span>/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">myapp:v1
      ports:
      </span>- containerPort: <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">80</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
          name: web
      volumeMounts:
      </span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> name: www
          mountPath: </span>/usr/share/nginx/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">html
volumeClaimTemplates:
</span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> metadata:
      name: www
      annotations:
      volume.beta.kubernetes.io</span>/storage-<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">class</span>: <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">managed-nfs-storage</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"   <strong><span style="line-height: 1.5; color: rgb(255, 0, 0);">#managed-nfs-storage为我们创建的storage-class名称</span></strong></span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
    spec:
      accessModes: [ </span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">ReadWriteOnce</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> ]
      resources:
      requests:
          storage: 1Gi</span></span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>检查结果:</strong></span></p><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>集群节点上</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"> #kubectl delete -f nginx-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">statefulset.yaml
# kubectl <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">get</span> pods -l app=<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">nginx<strong><span style="line-height: 1.5; color: rgb(255, 0, 0);">#检查pod状态</span></strong>
NAME    READY   STATUS    RESTARTS   AGE
web</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">0</span>   <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span>/<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span>   Running   <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">0</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">          115m
web</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span>   <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span>/<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span>   Running   <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">0</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">          114m
# kubectl <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">get</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> pvc <span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#查看PVC</strong></span>
NAME         STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS          AGE
test</span>-claim   Bound    pvc-aae2b7fa-377b-11ea-87ad-525400512eca   1Mi      RWX            managed-nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">storage   19h
www</span>-web-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">0</span>    Bound    pvc-4d7e342a-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">3810</span>-11ea-87ad-525400512eca   1Gi      RWO            managed-nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">storage   115m
www</span>-web-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span>    Bound    pvc-5431c8ba-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">3810</span>-11ea-87ad-525400512eca   1Gi      RWO            managed-nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">storage   115m
# kubectl <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">get</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> pv <span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#查看PV</strong></span>
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                STORAGECLASS          REASON   AGE
pvc</span>-4d7e342a-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">3810</span>-11ea-87ad-525400512eca   1Gi      RWO            Delete         Bound    <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>/www-web-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">0</span>    managed-nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">storage            115m
pvc</span>-5431c8ba-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">3810</span>-11ea-87ad-525400512eca   1Gi      RWO            Delete         Bound    <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>/www-web-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span>    managed-nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">storage            115m
pvc</span>-aae2b7fa-377b-11ea-87ad-525400512eca   1Mi      RWX            Delete         Bound    <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>/test-claim   managed-nfs-storage            19h</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>NFS Server上:</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"># cd /data/volumes/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
# ll<span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#注意目录的命名格式</strong></span>
总用量 </span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">0</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
drwxrwxrwx </span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2</span> root root <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">21</span> <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2020</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">01</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">15</span> <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">17</span>:<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">51</span> <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>-test-claim-pvc-aae2b7fa-377b-11ea-87ad-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">525400512eca
drwxrwxrwx </span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2</span> root root<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">6</span> <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2020</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">01</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">16</span> <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">11</span>:<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">28</span> <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>-www-web-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">0</span>-pvc-4d7e342a-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">3810</span>-11ea-87ad-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">525400512eca
drwxrwxrwx </span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2</span> root root<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">6</span> <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2020</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">01</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">16</span> <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">11</span>:<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">28</span> <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>-www-web-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span>-pvc-5431c8ba-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">3810</span>-11ea-87ad-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">525400512eca
# echo <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">web-00</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span> &gt; <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>-www-web-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">0</span>-pvc-4d7e342a-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">3810</span>-11ea-87ad-525400512eca/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">index.html #分别创建不同的index文件
# echo <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">web-01</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">"</span> &gt; <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>-www-web-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span>-pvc-5431c8ba-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">3810</span>-11ea-87ad-525400512eca/index.html</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>集群任意节点上:</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"># kubectl exec -it pod-cm-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span> -- /bin/<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">sh<span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#进入集群中任意pod中,解析nginx-headless 服务</strong></span></span>/ # nslookup nginx-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">headless
nslookup: can</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">'</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">t resolve </span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">'</span>(<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">null</span>)<span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">'</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">: Name does not resolve</span>
<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
Name:      nginx</span>-head<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">less
Address </span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">1</span>: <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">172.17</span>.<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">136.7</span> <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">172</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">17</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">136</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">7</span>.nginx-headless.<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">.svc.cluster.local<span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#可以看到有两个地址</strong></span>
Address </span><span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">2</span>: <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">172.17</span>.<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">248.5</span> <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">172</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">17</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">248</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">5</span>.nginx-headless.<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">.svc.cluster.local
# curl <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">172.17</span>.<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">248.5 <span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#分别访问一下查看结果</strong></span></span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
web</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">00</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
# curl <span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">172.17</span>.<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">136.7</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
web</span>-<span style="line-height: 1.5; color: rgb(128, 0, 128); font-family: &quot;Courier New&quot; !important;">01</span></span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;"><strong>#对于statefulset我们可以通过添加/删除pod副本的数量,观察PV/PVC的状态及变化.</strong></span></p><h3 id="autoid-0-5-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);">六、关于StorageClass回收策略对数据的影响</h3><h6 id="autoid-0-6-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);">1.第一种配置</h6><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;">   archiveOnDelete: <span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">false</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5;">
   reclaimPolicy: Delete   #默认没有配置,默认值为Delete</span></pre></div><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><strong><span style="line-height: 1.5; color: rgb(51, 102, 255);">测试结果:</span></strong></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.5; color: rgb(128, 0, 128);">1</span><span style="line-height: 1.5;">.pod删除重建后数据依然存在,旧pod名称及数据依然保留给新pod使用
</span><span style="line-height: 1.5; color: rgb(128, 0, 128);">2</span><span style="line-height: 1.5;">.sc删除重建后数据依然存在,旧pod名称及数据依然保留给新pod使用
</span><span style="line-height: 1.5; color: rgb(128, 0, 128);">3</span>.删除PVC后,PV被删除且NFS Server对应数据被删除</pre></div><h6 id="autoid-0-6-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);">2.第二种配置</h6><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;">   archiveOnDelete: <span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">false</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5;">
   reclaimPolicy: Retain</span></pre></div><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255);"><strong>测试结果:</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.5; color: rgb(128, 0, 128);">1</span><span style="line-height: 1.5;">.pod删除重建后数据依然存在,旧pod名称及数据依然保留给新pod使用
</span><span style="line-height: 1.5; color: rgb(128, 0, 128);">2</span><span style="line-height: 1.5;">.sc删除重建后数据依然存在,旧pod名称及数据依然保留给新pod使用
</span><span style="line-height: 1.5; color: rgb(128, 0, 128);">3</span><span style="line-height: 1.5;">.删除PVC后,PV不会别删除,且状态由Bound变为Released,NFS Server对应数据被保留
</span><span style="line-height: 1.5; color: rgb(128, 0, 128);">4</span>.重建sc后,新建PVC会绑定新的pv,旧数据可以通过拷贝到新的PV中</pre></div><h6 id="autoid-0-6-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);">3.第三种配置</h6><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;">   archiveOnDelete: <span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">ture</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5;">
   reclaimPolicy: Retain</span></pre></div><div style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; background-color: rgb(254, 254, 242);"><strong><span style="line-height: 1.5; color: rgb(51, 102, 255);">结果:</span></strong></div><div style="color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; background-color: rgb(254, 254, 242);"><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.5; color: rgb(128, 0, 128);">1</span><span style="line-height: 1.5;">.pod删除重建后数据依然存在,旧pod名称及数据依然保留给新pod使用
</span><span style="line-height: 1.5; color: rgb(128, 0, 128);">2</span><span style="line-height: 1.5;">.sc删除重建后数据依然存在,旧pod名称及数据依然保留给新pod使用
</span><span style="line-height: 1.5; color: rgb(128, 0, 128);">3</span><span style="line-height: 1.5;">.删除PVC后,PV不会别删除,且状态由Bound变为Released,NFS Server对应数据被保留
</span><span style="line-height: 1.5; color: rgb(128, 0, 128);">4</span>.重建sc后,新建PVC会绑定新的pv,旧数据可以通过拷贝到新的PV中</pre></div><h6 id="autoid-0-6-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px;">4.第四种配置</h6><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;">archiveOnDelete: <span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">ture</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5;">
reclaimPolicy: Delete</span></pre></div><p style="margin: 10px auto; line-height: 1.5;"><span style="line-height: 1.5; color: rgb(51, 102, 255);"><strong>结果:</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="line-height: 1.5; color: rgb(128, 0, 128);">1</span><span style="line-height: 1.5;">.pod删除重建后数据依然存在,旧pod名称及数据依然保留给新pod使用
</span><span style="line-height: 1.5; color: rgb(128, 0, 128);">2</span><span style="line-height: 1.5;">.sc删除重建后数据依然存在,旧pod名称及数据依然保留给新pod使用
</span><span style="line-height: 1.5; color: rgb(128, 0, 128);">3</span><span style="line-height: 1.5;">.删除PVC后,PV不会别删除,且状态由Bound变为Released,NFS Server对应数据被保留
</span><span style="line-height: 1.5; color: rgb(128, 0, 128);">4</span>.重建sc后,新建PVC会绑定新的pv,旧数据可以通过拷贝到新的PV中</pre></div><p style="margin: 10px auto; line-height: 1.5;"><span style="line-height: 1.5; color: rgb(51, 102, 255);"><strong>总结:除以第一种配置外,其他三种配置在PV/PVC被删除后数据依然保留</strong></span></p></div><h3 id="autoid-0-6-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 16px; line-height: 1.5; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">七、常见问题</span></h3><h6 id="autoid-0-7-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">1.如何设置默认的StorageClass</span></h6><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; color: rgb(51, 102, 255); font-family: &quot;courier new&quot;, courier;"><strong>我们可以用 kubectl patch 命令来更新:</strong></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"># kubectl <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">get</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> sc<strong><span style="line-height: 1.5; color: rgb(255, 0, 0);">#查看当前sc</span></strong>
NAME                  PROVISIONER       AGE
managed</span>-nfs-storage   qgg-nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">storage   20h
# kubectl patch storageclass managed-nfs-storage -p <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">'</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">'#设置managed-nfs-storage为默认后端存储</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
storageclass.storage.k8s.io</span>/managed-nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">storage patched
# kubectl <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">get</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> sc<span style="line-height: 1.5; color: rgb(255, 0, 0);"><strong>#再次查看,注意是否有default标识</strong></span>
NAME                            PROVISIONER       AGE
managed</span>-nfs-storage (<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>)   qgg-nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">storage   20h
# kubectl patch storageclass managed-nfs-storage -p <span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">'</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}</span><span style="line-height: 1.5; color: rgb(128, 0, 0); font-family: &quot;Courier New&quot; !important;">' #取消默认存储后端</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">
storageclass.storage.k8s.io</span>/managed-nfs-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">storage patched
# kubectl <span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">get</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> sc
NAME                  PROVISIONER       AGE
managed</span>-nfs-storage   qgg-nfs-storage   20h</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><h6 id="autoid-0-7-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">YAML文件</span></h6><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;">apiVersion: storage.k8s.io/<span style="line-height: 1.5;">v1
kind: StorageClass
metadata:
name: managed</span>-nfs-<span style="line-height: 1.5;">storage
annotations:
    </span><span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">storageclass.kubernetes.io/is-default-class</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span>: <span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">true</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">"   #添加此注释</span><span style="line-height: 1.5;">
provisioner: qgg</span>-nfs-storage #or choose another name, must match deployment<span style="line-height: 1.5; color: rgb(128, 0, 0);">'</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">s env PROVISIONER_NAME</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">'</span><span style="line-height: 1.5;">
parameters:
archiveOnDelete: </span><span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">false</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><h6 id="autoid-0-7-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">&nbsp;2.如何使用默认的StorageClass</span></h6><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">&nbsp;<span style="line-height: 1.5; color: rgb(51, 102, 255);"><strong>如果集群有一个默认的StorageClass能够满足我们的需求,那么剩下所有需要做的就是创建PersistentVolumeClaim(PVC),剩下的都有默认的动态配置搞定,包括无需去指定storageClassName:</strong></span></span></p><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;"><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvc
</span><span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">namespace</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">: testns
spec:
accessModes:
</span>-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;"> ReadWriteOnce
resources:
   requests:
   storage: 10Gi</span></span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><h6 id="autoid-0-7-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">3.修改默回收策略(默认为Delete)</span></h6><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;">apiVersion: storage.k8s.io/<span style="line-height: 1.5;">v1
kind: StorageClass
metadata:
name: managed</span>-nfs-<span style="line-height: 1.5;">storage
annotations:</span><span style="line-height: 1.5;">
provisioner: qgg</span>-nfs-storage #or choose another name, must match deployment<span style="line-height: 1.5; color: rgb(128, 0, 0);">'</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">s env PROVISIONER_NAME</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">'</span><span style="line-height: 1.5;">
parameters:
archiveOnDelete: </span><span style="line-height: 1.5; color: rgb(128, 0, 0);">"</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">ture</span><span style="line-height: 1.5; color: rgb(128, 0, 0);">" #暂时不清楚该值对回收策略产生什么影响</span><span style="line-height: 1.5;">
reclaimPolicy: Retain   #只有NFS 和hostPth支持两种回收策略</span></pre><div class="cnblogs_code_toolbar" style="margin-top: 5px;"><span class="cnblogs_code_copy" style="padding-right: 5px; line-height: 1.5;"><a title="复制代码" style="color: rgb(7, 93, 179); text-decoration-line: underline; border: none !important;"><img src="https://common.cnblogs.com/images/copycode.gif" alt="复制代码" style="max-width: 100%; height: auto;"></a></span></div></div><h6 id="autoid-0-7-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">4.能过删除/关闭默认的StorageClass</span></h6><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;"><span style="font-family: &quot;courier new&quot;, courier; line-height: 1.5;">不能删除默认的StorageClass,因为它是作为集群的add-<span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">on安装的,如果它被删除,会被重新安装。
当然,可以停掉默认的StorageClass行为,通过删除annotation:storageclass.beta.kubernetes.io</span>/<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">is</span>-<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">default</span>-<span style="line-height: 1.5; color: rgb(0, 0, 255); font-family: &quot;Courier New&quot; !important;">class,或者设置为false</span><span style="line-height: 1.5; font-family: &quot;Courier New&quot; !important;">。
如果没有StorageClass对象标记默认的annotation,那么PersistentVolumeClaim对象(在不指定StorageClass情况下)将不自动触发动态配置。相反,它们将回到绑定可用的</span>*PersistentVolume(PV)*的状态。</span></pre></div><h6 id="autoid-0-7-0" style="margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier;">5.当删除PersistentVolumeClaim(PVC)会发生什么</span></h6><div class="cnblogs_code" style="margin-top: 5px; margin-bottom: 5px; padding: 5px; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); overflow: auto; color: rgb(0, 0, 0); font-family: &quot;Courier New&quot; !important; font-size: 12px !important;"><pre style="overflow: auto; font-family: &quot;Courier New&quot; !important;">如果一个卷是动态配置的卷,则默认的回收策略为“删除”。这意味着,在默认的情况下,当PVC被删除时,基础的PV和对应的存储也会被删除。如果需要保留存储在卷上的数据,则必须在PV被设置之后将回收策略从delete更改为retain。</pre></div><p style="margin: 10px auto; line-height: 1.5; color: rgb(0, 0, 0); font-size: 13px; font-family: Verdana, Arial, Helvetica, sans-serif; background-color: rgb(254, 254, 242);"><span style="line-height: 1.5; font-family: &quot;courier new&quot;, courier; font-size: 16px;">参考文档:<a href="https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client" target="_blank" style="color: rgb(7, 93, 179);">https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client</a></span></p>
页: [1]
查看完整版本: k8s学习笔记之StorageClass+NFS