设为首页 收藏本站
查看: 1497|回复: 0

[经验分享] k8s1.5.4挂载volume之glusterfs

[复制链接]

尚未签到

发表于 2019-2-1 12:03:27 | 显示全部楼层 |阅读模式
k8s1.5.4挂载volume之glusterfs

  

  volume的例子集合
  https://github.com/kubernetes/kubernetes/tree/master/examples/volumes
  http://www.dockerinfo.net/2926.html
  http://dockone.io/article/2087
  https://www.kubernetes.org.cn/1146.html
  https://kubernetes.io/docs/user-guide/volumes/
  

  k8s集群安装部署
  http://jerrymin.blog.运维网.com/3002256/1898243
  k8s集群RC、SVC、POD部署
  http://jerrymin.blog.运维网.com/3002256/1900260
  k8s集群组件kubernetes-dashboard和kube-dns部署
  http://jerrymin.blog.运维网.com/3002256/1900508
  k8s集群监控组件heapster部署
  http://jerrymin.blog.运维网.com/3002256/1904460
  k8s集群反向代理负载均衡组件部署
  http://jerrymin.blog.运维网.com/3002256/1904463
  k8s集群挂载volume之nfs
  http://jerrymin.blog.运维网.com/3002256/1906778
  

  

  glusterfs参考文档
  https://github.com/kubernetes/kubernetes/tree/master/examples/volumes/glusterfs
  http://gluster.readthedocs.io/en/latest/Administrator%20Guide/
  http://blog.gluster.org/2016/03/persistent-volume-and-claim-in-openshift-and-kubernetes-using-glusterfs-volume-plugin/
  https://docs.openshift.org/latest/install_config/persistent_storage/persistent_storage_glusterfs.html
  

  The example assumes that you have already set up a Glusterfs server cluster and the Glusterfs client package is installed on all Kubernetes nodes.
  需要先在node节点安装部署gluster集群环境,可以参考http://www.linuxidc.com/Linux/2017-02/140517.htm
  

  1,glusterfs服务端和客户端环境部署:
  CentOS 安装 glusterfs 非常的简单
  在三个节点都安装glusterfs
  yum install centos-release-gluster
  yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
  配置 GlusterFS 集群:
  启动 glusterFS
  systemctl start glusterd.service
  systemctl enable glusterd.service
  

  配置
  [root@k8s-master glusterfs]# cd /usr/local/kubernetes/examples/volumes/glusterfs
  [root@k8s-master glusterfs]# ls
  glusterfs-endpoints.json  glusterfs-pod.json  glusterfs-service.json  README.md
  [root@k8s-master glusterfs]# gluster peer probe k8s-master
  peer probe: success. Probe on localhost not needed
  [root@k8s-master glusterfs]# gluster peer probe k8s-node1
  peer probe: success.
  [root@k8s-master glusterfs]# gluster peer probe k8s-node2
  peer probe: success.
  

  查看集群状态
  [root@k8s-master glusterfs]# gluster peer status
  Number of Peers: 2
  

  Hostname: k8s-node1
  Uuid: 4853baab-e8fb-41ad-9a93-bfb5f0d55692
  State: Peer in Cluster (Connected)
  

  Hostname: k8s-node2
  Uuid: 2c9dea85-2305-4989-a74a-970f7eb08093
  State: Peer in Cluster (Connected)
  

  创建数据存储目录
  [root@k8s-master glusterfs]# mkdir -p /data/gluster/data
  [root@k8s-node1 ~]# mkdir -p /data/gluster/data
  [root@k8s-node2 ~]# mkdir -p /data/gluster/data
  

  创建volume使用默认DHT也叫分布卷: 将文件已hash算法随机分布到 一台服务器节点中存储。
  [root@k8s-master glusterfs]# gluster volume create glusterfsdata replica 3 k8s-master:/data/gluster/data k8s-node1:/data/gluster/data k8s-node2:/data/gluster/data force
  volume create: glusterfsdata: success: please start the volume to access data
  

  查看volume信息
  [root@k8s-master glusterfs]# gluster volume info
  Volume Name: glusterfsdata
  Type: Replicate
  Volume ID: 100d1f33-fb0d-48c3-9a93-d08c2e2dabb3
  Status: Created
  Snapshot Count: 0
  Number of Bricks: 1 x 3 = 3
  Transport-type: tcp
  Bricks:
  Brick1: k8s-master:/data/gluster/data
  Brick2: k8s-node1:/data/gluster/data
  Brick3: k8s-node2:/data/gluster/data
  Options Reconfigured:
  transport.address-family: inet
  nfs.disable: on
  

  启动volume
  [root@k8s-master glusterfs]# gluster volume  start glusterfsdata
  volume start: glusterfsdata: success
  

  测试客户端
  [root@k8s-master glusterfs]# mount -t glusterfs k8s-master:glusterfsdata /mnt
  [root@k8s-master glusterfs]# df -h|grep gluster
  k8s-master:glusterfsdata  422G  934M  421G   1% /mnt
  [root@k8s-master mnt]# echo glusterfs > glusterfs
  [root@k8s-master mnt]# cat glusterfs
  glusterfs
  

  

  2,k8s集群挂载glusterfs
  注意endpoint改成glusterfs服务集群的一个节点的IP,配置文件是2个IP所以填2个节点IP
  [root@k8s-master glusterfs]# vim glusterfs-endpoints.json
  [root@k8s-master glusterfs]# kubectl create -f glusterfs-endpoints.json
  endpoints "glusterfs-cluster" created
  [root@k8s-master glusterfs]# kubectl get ep |grep glusterfs
  glusterfs-cluster   172.17.3.7:1,172.17.3.8:1                1m
  

  [root@k8s-master glusterfs]# kubectl create -f glusterfs-service.json
  service "glusterfs-cluster" created
  

  注意volumeMounts挂载name改成上面新建的glusterfs volume
  "volumes": [
  {
  "name": "glusterfsvol",
  "glusterfs": {
  "endpoints": "glusterfs-cluster",
  "path": "glusterfsdata",
  "readOnly": true
  }
  }
  ]
  [root@k8s-master glusterfs]# kubectl create -f glusterfs-pod.json
  pod "glusterfs" created
  

  [root@k8s-master glusterfs]# kubectl get pod -o wide |grep glus
  glusterfs            1/1       Running   0          4m        10.1.39.8    k8s-node1
  

  [root@k8s-node1 ~]# mount | grep gluster
  172.17.3.7:glusterfsdata on /var/lib/kubelet/pods/61cd4cec-0955-11e7-a8c3-c81f66d97bc3/volumes/kubernetes.io~glusterfs/glusterfsvol type fuse.glusterfs (ro,relatime,user_id=0,group_id=0,default_permissions,allow_other,max_read=131072)
  

  可见github上面例子不太直观,版本比较老,但是过程比较清楚。这里也可以参考nfs挂载把glusterfs挂载到nginx站点,那样测试更直观。下面是升级测试
  创建PV/PVC
  [root@k8s-master glusterfs]# cat glusterfs-pv.yaml
  apiVersion: v1
  kind: PersistentVolume
  metadata:
  name: gluster-default-volume
  spec:
  capacity:
  storage: 8Gi
  accessModes:
  - ReadWriteMany
  glusterfs:
  endpoints: "glusterfs-cluster"
  path: "glusterfsdata"
  readOnly: false
  [root@k8s-master glusterfs]# cat glusterfs-pvc.yaml
  kind: PersistentVolumeClaim
  apiVersion: v1
  metadata:
  name: glusterfs-claim
  spec:
  accessModes:
  - ReadWriteMany
  resources:
  requests:
  storage: 8Gi
  [root@k8s-master glusterfs]# kubectl create -f glusterfs-pv.yaml
  persistentvolume "gluster-default-volume" created
  [root@k8s-master glusterfs]# kubectl create -f glusterfs-pvc.yaml
  persistentvolumeclaim "glusterfs-claim" created
  [root@k8s-master glusterfs]# kubectl get pvc
  NAME              STATUS    VOLUME                   CAPACITY   ACCESSMODES   AGE
  glusterfs-claim   Bound     gluster-default-volume   8Gi        RWX           2m
  

  创建nginx站点挂载glusterfs-claim
  

  [root@k8s-master glusterfs]# kubectl create -f glusterfs-web-rc.yaml
  replicationcontroller "glusterfs-web" created
  [root@k8s-master glusterfs]# kubectl create -f glusterfs-web-service.yaml
  service "glusterfs-web" created
  

  配置文件如下
  [root@k8s-master glusterfs]# cat glusterfs-web-rc.yaml
  # This pod mounts the nfs volume claim into /usr/share/nginx/html and
  # serves a simple web page.
  

  apiVersion: v1
  kind: ReplicationController
  metadata:
  name: glusterfs-web
  spec:
  replicas: 2
  selector:
  role: glusterfs-web-frontend
  template:
  metadata:
  labels:
  role: glusterfs-web-frontend
  spec:
  containers:
  - name: glusterfsweb
  image: nginx
  imagePullPolicy: IfNotPresent
  ports:
  - name: glusterfsweb
  containerPort: 80
  volumeMounts:
  # name must match the volume name below
  - name: gluster-default-volume
  mountPath: "/usr/share/nginx/html"
  volumes:
  - name: gluster-default-volume
  persistentVolumeClaim:
  claimName: glusterfs-claim
  [root@k8s-master glusterfs]# cat glusterfs-web-service.yaml
  kind: Service
  apiVersion: v1
  metadata:
  name: glusterfs-web
  spec:
  ports:
  - port: 80
  selector:
  role: glusterfs-web-frontend
  

  验证
  [root@k8s-master glusterfs]# kubectl get pods -o wide |grep glusterfs-web
  glusterfs-web-280mz   1/1       Running   0          1m        10.1.39.12   k8s-node1
  glusterfs-web-f952d   1/1       Running   0          1m        10.1.15.10   k8s-node2
  [root@k8s-master glusterfs]# kubectl exec -ti glusterfs-web-280mz -- bash
  root@glusterfs-web-280mz:/# df -h |grep glusterfs
  172.17.3.7:glusterfsdata                                                                            422G  954M  421G   1% /usr/share/nginx/html
  root@glusterfs-web-280mz:/# cd /usr/share/nginx/html/
  root@glusterfs-web-280mz:/usr/share/nginx/html# ls
  glusterfs
  root@glusterfs-web-280mz:/usr/share/nginx/html# cat glusterfs
  glusterfs
  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-670434-1-1.html 上篇帖子: GlusterFS发布时间表 (Release Schedule) 下篇帖子: CentOS7下分布式系统GlusterFS安装配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表