前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >kubernetes用Glusterfs做持久化存储做PVC扩容

kubernetes用Glusterfs做持久化存储做PVC扩容

作者头像
极客运维圈
发布2020-03-23 16:47:12
发布2020-03-23 16:47:12
2.4K00
代码可运行
举报
文章被收录于专栏:乔边故事乔边故事
运行总次数:0
代码可运行

我们前面已经介绍过静态PV是没办法进行扩容的,而且我们在用NFS做持久化存储的时候了解到要用动态PV并做扩容操作需要Kubernetes底层支持的存储,这次我们就用Glusterfs做扩容测试。

需要准备好Glusterfs,搭建点此连接

(1)、创建namespace,以下测试都在这个namespace下

代码语言:javascript
代码运行次数:0
运行
复制
# kubectl create ns rookieops
namespace/rookieops created

(1)、创建Secret(glusterfs-secret.yaml)

代码语言:javascript
代码运行次数:0
运行
复制
apiVersion: v1
kind: Secret
metadata:
  name: glusterfs-secret
  namespace: rookieops
data:
  key: YWRtaW5AUEBzc1cwcmQ=
type: kubernetes.io/glusterfs

创建secret对象

代码语言:javascript
代码运行次数:0
运行
复制
# kubectl apply -f glusterfs-secret.yaml
secret/glusterfs-secret created
# kubectl get secret -n rookieops
NAME                  TYPE                                  DATA   AGE
default-token-s7d65   kubernetes.io/service-account-token   3      2m26s
glusterfs-secret      kubernetes.io/glusterfs               1      5s

(2)、创建StorageClass(glusterfs-storageclass.yaml)

代码语言:javascript
代码运行次数:0
运行
复制
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: glusterfs-storageclass
  namespace: rookieops
parameters:
  resturl: "http://10.1.10.128:48080"
  clusterid: "cca360f44db482f03297a151886eea19"
  restauthenabled: "true"             #若heketi开启认证此处也必须开启auth认证
  restuser: "admin"
  secretName: "glusterfs-secret"      #name/namespace与secret资源中定义一致
  secretNamespace: "rookieops"
  volumetype: "replicate:3"
provisioner: kubernetes.io/glusterfs
reclaimPolicy: Delete
allowVolumeExpansion: true

创建storageclass对象

代码语言:javascript
代码运行次数:0
运行
复制
# kubectl apply -f  glusterfs-storageclass.yaml
storageclass.storage.k8s.io/glusterfs-storageclass created
# kubectl get sc -n rookieops
NAME                     PROVISIONER               RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
glusterfs-storageclass   kubernetes.io/glusterfs   Delete          Immediate           false                  9s

(3)、创建PVC(glusterfs-pvc.yaml)

代码语言:javascript
代码运行次数:0
运行
复制
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-pvc
  namespace: rookieops
  annotations:
    volume.beta.kubernetes.io/storage-class: glusterfs-storageclass
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

创建PVC对象

代码语言:javascript
代码运行次数:0
运行
复制
# kubectl apply -f  glusterfs-pvc.yaml
persistentvolumeclaim/glusterfs-pvc created
# kubectl get pvc -n rookieops
NAME            STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS             AGE
glusterfs-pvc   Bound    pvc-cfae01a0-cb37-4fcc-8640-8ef604ae3874   1Gi        RWO            glusterfs-storageclass   46s

(4)、然后我们对其进行扩容,直接在PVC的YAML文件中修改其大小

代码语言:javascript
代码运行次数:0
运行
复制
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-pvc
  namespace: rookieops
  annotations:
    volume.beta.kubernetes.io/storage-class: glusterfs-storageclass
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

然后更新PVC对象

代码语言:javascript
代码运行次数:0
运行
复制
# kubectl apply -f  glusterfs-pvc.yaml
# kubectl get pvc -n rookieops
NAME            STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS             AGE
glusterfs-pvc   Bound    pvc-29c667db-b103-49f8-9b2f-87ca5d29f751   2Gi        RWO            glusterfs-storageclass   71s

我们describe以下PVC

代码语言:javascript
代码运行次数:0
运行
复制
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      2Gi
Access Modes:  RWO
VolumeMode:    Filesystem
Mounted By:    <none>
Events:
  Type    Reason                  Age   From                         Message
  ----    ------                  ----  ----                         -------
  Normal  ProvisioningSucceeded   48s   persistentvolume-controller  Successfully provisioned volume pvc-29c667db-b103-49f8-9b2f-87ca5d29f751 using kubernetes.io/glusterfs
  Normal  VolumeResizeSuccessful  3s    volume_expand                ExpandVolume succeeded for volume rookieops/glusterfs-pvc

可以看到event信息中有扩展成功。

既然可以扩容,那么可以缩容吗?我们将上面的YAML文件中的storage改小试试

代码语言:javascript
代码运行次数:0
运行
复制
# kubectl apply -f  glusterfs-pvc.yaml
The PersistentVolumeClaim "glusterfs-pvc" is invalid: spec.resources.requests.storage: Forbidden: field can not be less than previous value

然后报错,不允许缩容。

结论:如果动态PV要进行扩容需要满足以下条件:

  • 需要是kubernetes支持的存储,开发能力强的也可以自己开发使其支持第三方存储
  • 需要在sc中开启allowVolumeExpansion: true
  • 存储设备要有足够的存储能力
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-02-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 乔边故事 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档