说明:
存储主要是用于持久化程序内部有效数据,主要包括日志、数据文件、配置中心的配置数据,采用的是阿里云的NAS存储方案,申请模式采用按量付费,如果没有使用的话是没有费用的;需要注意的时候利用阿里云NAS作为存储的话是不支持在线PVC扩容,因为目前官方没有提供针对NFS扩容的插件;
配置K8S支持NFS 相关资源对象
部署RBAC
文件rabc.yaml 内容如下
apiVersion: v1 kind: ServiceAccount metadata: name: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: default --- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: nfs-client-provisioner-runner rules: - apiGroups: [""] resources: ["persistentvolumes"] verbs: ["get", "list", "watch", "create", "delete"] - apiGroups: [""] resources: ["persistentvolumeclaims"] verbs: ["get", "list", "watch", "update"] - apiGroups: ["storage.k8s.io"] resources: ["storageclasses"] verbs: ["get", "list", "watch"] - apiGroups: [""] resources: ["events"] verbs: ["create", "update", "patch"] --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: run-nfs-client-provisioner subjects: - kind: ServiceAccount name: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: default roleRef: kind: ClusterRole name: nfs-client-provisioner-runner apiGroup: rbac.authorization.k8s.io --- kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: name: leader-locking-nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: default rules: - apiGroups: [""] resources: ["endpoints"] verbs: ["get", "list", "watch", "create", "update", "patch"] --- kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: leader-locking-nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: default subjects: - kind: ServiceAccount name: nfs-client-provisioner # replace with namespace where provisioner is deployed namespace: default roleRef: kind: Role name: leader-locking-nfs-client-provisioner apiGroup: rbac.authorization.k8s.io
部署rbac
# kubectl apply -f rbac.yaml
部署NFS Client Deployment
部署K8S nfs客户端
文件deployment.yaml内容如下
apiVersion: apps/v1 kind: Deployment metadata: name: nfs-client-provisioner labels: app: nfs-client-provisioner namespace: default spec: replicas: 1 strategy: type: Recreate selector: matchLabels: app: nfs-client-provisioner template: metadata: labels: app: nfs-client-provisioner spec: serviceAccountName: nfs-client-provisioner containers: - name: nfs-client-provisioner image: quay.io/external_storage/nfs-client-provisioner:latest volumeMounts: - name: nfs-client-root mountPath: /persistentvolumes env: - name: PROVISIONER_NAME value: fuseim.pri/ifs - name: NFS_SERVER value: xxxx-xxxx.cn-beijing.nas.aliyuncs.com - name: NFS_PATH value: / volumes: - name: nfs-client-root nfs: server: xxxx-xxx.cn-beijing.nas.aliyuncs.com #注意这是阿里云提供的nas地址 path: /
部署文件deployment
# kubectl apply -f deployment.yaml
查看资源对象POD
# kubectl get pod NAME READY STATUS RESTARTS AGE nfs-client-provisioner-776d84b5bf-6gqwj 1/1 Running 0 25m
部署NFS Class
文件Class.yam内容如下
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: managed-nfs-storage provisioner: fuseim.pri/ifs parameters: archiveOnDelete: "false" allowVolumeExpansion: true #是否允许扩容 reclaimPolicy: "Retain" #保留策略默认是Delete
部署Class
# kubectl apply -f class.yaml
storageclass.storage.k8s.io/managed-nfs-storage created
查看Class
# kubectl get sc
NAME PROVISIONER AGE
。。。。。。
managed-nfs-storage fuseim.pri/ifs 62s
验证K8s nfs
验证文件test-nfspvc.yaml 内容如下
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: test-claim annotations: volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" spec: accessModes: - ReadWriteMany resources: requests: storage: 2048Mi
部署test-nfs
# kubectl apply -f test-nfspvc.yaml
persistentvolumeclaim/test-claim created
查看PV 、PVC
# kubectl get pvc,pv NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE persistentvolumeclaim/test-claim Bound pvc-7866b19d-3a72-4e0b-9841-c053e10ec48a 2Gi RWX managed-nfs-storage 2m8s NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE persistentvolume/pvc-7866b19d-3a72-4e0b-9841-c053e10ec48a 2Gi RWX Retain Bound default/test-claim managed-nfs-storage 2m8s
NFS 相关资源对象部署完成