Kubernetes实战总结 - 动态存储管理StorageClass
发布日期:2021-05-09 04:23:05 浏览次数:8 分类:博客文章

本文共 5534 字,大约阅读时间需要 18 分钟。

概述

StorageClass 为管理员提供了描述存储 "类" 的方法。 不同的类型可能会映射到不同的服务质量等级或备份策略,或是由集群管理员制定的任意策略。

每个 StorageClass 都包含 provisionerparameters 和 reclaimPolicy 字段, 这些字段会在 StorageClass 需要动态分配 PersistentVolume 时会使用到。

StorageClass 对象的命名很重要,用户使用这个命名来请求生成一个特定的类。 当创建 StorageClass 对象时,管理员设置 StorageClass 对象的命名和其他参数,一旦创建了对象就不能再对其更新。

更多详情参考:

 

Github:

 

以NFS服务为例

# 安装nfs服务并启动yum -y install nfs-common nfs-utils rpcbindsystemctl start nfs && systemctl enable nfssystemctl start rpcbind && systemctl enable rpcbind# 创建一个共享目录mkdir -p /data/nfsprovisionerchmod 777 /data/nfsprovisionerchown nfsnobody /data/nfsprovisioner cat >> /etc/exports <

 

部署nfs-client-provisioner

注意: 修改对应nfs地址和目录

apiVersion: storage.k8s.io/v1kind: StorageClassmetadata:  name: managed-nfs-storageprovisioner: fuseim.pri/ifs # or choose another name, must match deployment's env PROVISIONER_NAME'parameters:  archiveOnDelete: "false"---apiVersion: v1kind: ServiceAccountmetadata:  name: nfs-client-provisioner  # replace with namespace where provisioner is deployed  namespace: default---kind: ClusterRoleapiVersion: rbac.authorization.k8s.io/v1metadata:  name: nfs-client-provisioner-runnerrules:  - 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: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata:  name: run-nfs-client-provisionersubjects:  - kind: ServiceAccount    name: nfs-client-provisioner    # replace with namespace where provisioner is deployed    namespace: defaultroleRef:  kind: ClusterRole  name: nfs-client-provisioner-runner  apiGroup: rbac.authorization.k8s.io---kind: RoleapiVersion: rbac.authorization.k8s.io/v1metadata:  name: leader-locking-nfs-client-provisioner  # replace with namespace where provisioner is deployed  namespace: defaultrules:  - apiGroups: [""]    resources: ["endpoints"]    verbs: ["get", "list", "watch", "create", "update", "patch"]---kind: RoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata:  name: leader-locking-nfs-client-provisioner  # replace with namespace where provisioner is deployed  namespace: defaultsubjects:  - kind: ServiceAccount    name: nfs-client-provisioner    # replace with namespace where provisioner is deployed    namespace: defaultroleRef:  kind: Role  name: leader-locking-nfs-client-provisioner  apiGroup: rbac.authorization.k8s.io---apiVersion: apps/v1kind: Deploymentmetadata:  name: nfs-client-provisioner  labels:    app: nfs-client-provisioner  # replace with namespace where provisioner is deployed  namespace: defaultspec:  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          image: registry.cn-shanghai.aliyuncs.com/leozhanggg/storage/nfs-client-provisioner:latest          volumeMounts:            - name: nfs-client-root              mountPath: /persistentvolumes          env:            - name: PROVISIONER_NAME              value: fuseim.pri/ifs            - name: NFS_SERVER              value: 10.88.88.108            - name: NFS_PATH              value: /data/nfsprovisioner      volumes:        - name: nfs-client-root          nfs:            server: 10.88.88.108            path: /data/nfsprovisioner
[root@ymt108 ~]# kubectl apply -f nfs-client-provisioner.yamlstorageclass.storage.k8s.io/managed-nfs-storage createdserviceaccount/nfs-client-provisioner createdclusterrole.rbac.authorization.k8s.io/nfs-client-provisioner-runner createdclusterrolebinding.rbac.authorization.k8s.io/run-nfs-client-provisioner createdrole.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner createdrolebinding.rbac.authorization.k8s.io/leader-locking-nfs-client-provisioner createddeployment.apps/nfs-client-provisioner created[root@ymt108 ~]# kubectl get pod |grep nfs-client-provisionernfs-client-provisioner-6d7b4c474c-8xftt   1/1     Running   0          39m

 

部署测试Pod

kind: PersistentVolumeClaimapiVersion: v1metadata:  name: test-claim  annotations:    volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"spec:  accessModes:    - ReadWriteMany  resources:    requests:      storage: 1Mi---kind: PodapiVersion: v1metadata:  name: test-podspec:  containers:  - name: test-pod    image: busybox    command:      - "/bin/sh"    args:      - "-c"      - "touch /mnt/SUCCESS && exit 0 || exit 1"    volumeMounts:      - name: nfs-pvc        mountPath: "/mnt"  restartPolicy: "Never"  volumes:    - name: nfs-pvc      persistentVolumeClaim:        claimName: test-claim
[root@ymt108 ~]# kubectl apply -f test-pod.yamlpersistentvolumeclaim/test-claim createdpod/test-pod created[root@ymt108 ~]# cd /data/nfsprovisioner/[root@ymt108 nfsprovisioner]# lsdefault-test-claim-pvc-5763d9c1-2860-4aee-a408-c10ef94d252d[root@ymt108 nfsprovisioner]#[root@ymt108 nfsprovisioner]# kubectl delete -f /root/test-pod.yamlpersistentvolumeclaim "test-claim" deletedpod "test-pod" deleted[root@ymt108 nfsprovisioner]# ls[root@ymt108 nfsprovisioner]#

 

 

 

作者:

出处:

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

 

上一篇:【转载】kubelet 参数详解
下一篇:【解决】 使用Grafana查看k8s集群监控情况,提示插件未发现和没有数据

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2025年04月07日 22时36分35秒