環境信息
三台機器,操作系統CentOS 7.4:
hanyu-210 10.20.0.210
hanyu-211 10.20.0.211
hanyu-212 10.20.0.212
前提條件:
已搭建K8S集群(1個master 2個node節點)
1、搭建glusterFS集群(除非特別說明,否則三個節點都執行)
執行
[root@hanyu-210 k8s_glusterfs]# yum install centos-release-gluster [root@hanyu-210 k8s_glusterfs]# yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
配置 GlusterFS 集群
[root@hanyu-210 k8s_glusterfs]# systemctl start glusterd.service [root@hanyu-210 k8s_glusterfs]# systemctl enable glusterd.service
hanyu-210節點執行
[root@hanyu-210 k8s_glusterfs]# gluster peer probe hanyu-210 [root@hanyu-210 k8s_glusterfs]# gluster peer probe hanyu-211 [root@hanyu-210 k8s_glusterfs]# gluster peer probe hanyu-212
創建數據目錄
[root@hanyu-210 k8s_glusterfs]# mkdir -p /opt/gfs_data
創建復制卷
[root@hanyu-210 k8s_glusterfs]# gluster volume create k8s-volume replica 3 hanyu-210:/opt/gfs_data hanyu-211:/opt/gfs_data hanyu-212:/opt/gfs_data force
啟動卷
[root@hanyu-210 k8s_glusterfs]# gluster volume start k8s-volume
查詢卷狀態
[root@hanyu-210 k8s_glusterfs]# gluster volume status Status of volume: k8s-volume Gluster process TCP Port RDMA Port Online Pid ------------------------------------------------------------------------------ Brick hanyu-210:/opt/gfs_data 49152 0 Y 29445 Brick hanyu-212:/opt/gfs_data 49152 0 Y 32098 Self-heal Daemon on localhost N/A N/A Y 29466 Self-heal Daemon on hanyu-212 N/A N/A Y 32119 Task Status of Volume k8s-volume ------------------------------------------------------------------------------ There are no active volume tasks
[root@hanyu-210 k8s_glusterfs]# gluster volume info Volume Name: k8s-volume Type: Replicate Volume ID: 7d7ecba3-7bc9-4e09-89ed-493b3a6a2454 Status: Started Snapshot Count: 0 Number of Bricks: 1 x 3 = 3 Transport-type: tcp Bricks: Brick1: hanyu-210:/opt/gfs_data Brick2: hanyu-211:/opt/gfs_data Brick3: hanyu-212:/opt/gfs_data Options Reconfigured: transport.address-family: inet nfs.disable: on performance.client-io-threads: off
驗證glusterFS集群可用
選擇其中一台主機執行
yum install -y glusterfs glusterfs-fuse
mkdir -p /root/test
mount -t glusterfs hanyu-210:k8s-volume /root/test
df -h
umount /root/test
2、使用glusterfs(以下均在k8s master節點執行)
創建glusterfs的endpoints:kubectl apply -f glusterfs-cluster.yaml
[root@hanyu-210 k8s_glusterfs]# cat glusterfs-cluster.yaml
apiVersion: v1 kind: Endpoints metadata: name: glusterfs-cluster namespace: default subsets: - addresses: - ip: 10.20.0.210 - ip: 10.20.0.211 - ip: 10.20.0.212 ports: - port: 49152 protocol: TCP
創建應用直接使用glusterfs作為存儲卷:kubectl apply -f nginx_deployment_test.yaml
[root@hanyu-210 k8s_glusterfs]# cat nginx_deployment_test.yaml apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment-test spec: replicas: 3 selector: matchLabels: name: nginx template: metadata: labels: name: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 volumeMounts: - name: storage001 mountPath: "/usr/share/nginx/html" volumes: - name: storage001 glusterfs: endpoints: glusterfs-cluster path: k8s-volume readOnly: false


創建pv使用glusterfs:kubectl apply -f glusterfs-pv.yaml
[root@hanyu-210 k8s_glusterfs]# cat glusterfs-pv.yaml apiVersion: v1 kind: PersistentVolume metadata: name: glusterfs-pv spec: capacity: storage: 10Gi accessModes: - ReadWriteMany glusterfs: endpoints: glusterfs-cluster path: k8s-volume readOnly: false
創建pvc聲明:kubectl apply -f glusterfs-pvc.yaml
[root@hanyu-210 k8s_glusterfs]# cat glusterfs-pvc.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: glusterfs-pvc spec: accessModes: - ReadWriteMany resources: requests: storage: 2Gi
創建應用使用pvc:kubectl apply -f nginx_deployment.yaml
[root@hanyu-210 k8s_glusterfs]# cat nginx_deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 selector: matchLabels: name: nginx template: metadata: labels: name: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 volumeMounts: - name: storage001 mountPath: "/usr/share/nginx/html" volumes: - name: storage001 persistentVolumeClaim: claimName: glusterfs-pvc


作者:sjyu_eadd
鏈接:https://www.jianshu.com/p/4ebf960b2075
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。