博客
关于我
Kubernetes实战总结 - 动态存储管理StorageClass
阅读量:424 次
发布时间:2019-03-06

本文共 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]#

 

 

 

作者:

出处:

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

 

你可能感兴趣的文章
iOS UIAlertController
查看>>
iOS UISlider的使用
查看>>
iOS Xcode 打包之后,不能输出日志
查看>>
UIPickerView的使用(二)
查看>>
iOS 多线程GCD简介
查看>>
不想eject,还咋修改create-react-app的配置?
查看>>
实现延迟消息队列
查看>>
写了一下 micropython 的文件系统单元测试
查看>>
说说字库和字模的故事,然后在 MaixPy 里实现打印中文字体(任意字体)吧!
查看>>
linux kernel version magic 不一致导致的模块 加载 (insmod) 不上
查看>>
线性代数应该这样学9:上三角矩阵、对角矩阵
查看>>
【科学计算】插值理论
查看>>
centos7一步一步搭建docker jenkins 及自定义访问路径重点讲解
查看>>
Java 读取Excel百分数保留原格式(即不转换为小数)的方法
查看>>
深度学习一:深度前馈网络和反向传播
查看>>
在wxPython使ListCtrl占据整个窗口
查看>>
微软面试题
查看>>
Google新玩法(转载)
查看>>
C#中Dispose和Close的区别!
查看>>
绝密:Google 秘密测试新版首页, 将闪聊嵌入搜索框下方!!
查看>>