我測試了1.20.2版本配置glusterfs結果使用不了。記錄時間2021-2-19
一、環境介紹
2台服務器都為存儲服務器,都有一塊20G的數據盤
注意:數據盤不要格式化操作
[root@master ~]# fdisk -l /dev/vdb Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes [root@master ~]# kubectl get node NAME STATUS ROLES AGE VERSION master Ready master 5m28s v1.19.8 node1 Ready <none> 4m52s v1.19.8 [root@master ~]# cat /etc/hosts ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 172.16.208.210 master 172.16.208.211 node1
二、2台服務器都安裝glusterfs和heketi
注意:GlusterFS只需要安裝並啟動即可,不必組建受信存儲池
#所有存儲服務器下載安裝glusterfs yum install centos-release-gluster -y yum install glusterfs-server -y #啟動 systemctl start glusterd #安裝heketi yum install -y heketi heketi-client
三、配置heketi.json(2台服務器都修改)
[root@master ~]# cat /etc/heketi/heketi.json { "_port_comment": "Heketi Server Port Number", "port": "8080", "_use_auth": "Enable JWT authorization. Please enable for deployment", "use_auth": true, "_jwt": "Private keys for access", "jwt": { "_admin": "Admin has access to all APIs", "admin": { "key": "admin@key" }, "_user": "User only has access to /volumes endpoint", "user": { "key": "user@key" } }, "_glusterfs_comment": "GlusterFS Configuration", "glusterfs": { "_executor_comment": [ "Execute plugin. Possible choices: mock, ssh", "mock: This setting is used for testing and development.", " It will not send commands to any node.", "ssh: This setting will notify Heketi to ssh to the nodes.", " It will need the values in sshexec to be configured.", "kubernetes: Communicate with GlusterFS containers over", " Kubernetes exec api." ], "executor": "ssh", "_sshexec_comment": "SSH username and private key file information", "sshexec": { "keyfile": "/etc/heketi/heketi_key", "user": "root", "port": "22", "fstab": "/etc/fstab" }, "_kubeexec_comment": "Kubernetes configuration", "kubeexec": { "host" :"https://kubernetes.host:8443", "cert" : "/path/to/crt.file", "insecure": false, "user": "kubernetes username", "password": "password for kubernetes user", "namespace": "OpenShift project or Kubernetes namespace", "fstab": "Optional: Specify fstab file on node. Default is /etc/fstab" }, "_db_comment": "Database file name", "db": "/var/lib/heketi/heketi.db", "_loglevel_comment": [ "Set log level. Choices are:", " none, critical, error, warning, info, debug", "Default is warning" ], "loglevel" : "warning" } }
三、設置heketi免密訪問GlusterFS與公鑰分發
#設置heketi免密訪問GlusterFS [root@master heketi]# ssh-keygen -t rsa -q -f /etc/heketi/heketi_key -N "" [root@master heketi]# chown heketi:heketi /etc/heketi/heketi_key #分發公鑰 [root@master heketi]# ssh-copy-id -i /etc/heketi/heketi_key.pub root@master [root@master heketi]# ssh-copy-id -i /etc/heketi/heketi_key.pub root@node1 #將秘鑰充master服務器復制到node1服務器上 [root@master heketi]# rsync -avz /etc/heketi/heketi_key root@node1:/etc/heketi/
四、啟動heketi
systemctl enable heketi
systemctl restart heketi
systemctl status heketi
驗證
[root@master ~]# curl http://localhost:8080/hello Hello from Heketi
五、設置GlusterFS集群
1、創建topology.json文件
[root@master ~]# cat /etc/heketi/topology.json { "clusters": [ { "nodes": [ { "node": { "hostnames": { "manage": [ "172.16.208.210" ], "storage": [ "172.16.208.210" ] }, "zone": 1 }, "devices": [ "/dev/vdb" ] }, { "node": { "hostnames": { "manage": [ "172.16.208.211" ], "storage": [ "172.16.208.211" ] }, "zone": 2 }, "devices": [ "/dev/vdb" ] } ] } ] }
2、通過topology.json組建GlusterFS集群
[root@master ~]# heketi-cli --server http://localhost:8080 --user admin --secret admin@key topology load --json=/etc/heketi/topology.json Creating cluster ... ID: 2865ef5ac77aae777bbfaf3f27e456ef Allowing file volumes on cluster. Allowing block volumes on cluster. Creating node 172.16.208.210 ... ID: 474894862effef22952e7c0d4542605b Adding device /dev/vdb ... OK Creating node 172.16.208.211 ... ID: 156c6b793ef761f68b317d0cfe8e7ec1 Adding device /dev/vdb ... OK
3、查看命令(后面添加的,就不貼粘貼內容了)
[root@master ~]# heketi-cli --server http://localhost:8080 --user admin --secret admin@key topology info
六、配置StorageClass
1、定義並導入secret
[root@master ~]# cat gluster-heketi-secret.yaml apiVersion: v1 kind: Secret metadata: name: heketi-secret namespace: default data: # base64 encoded password. E.g.: echo -n "mypassword" | base64 key: YWRtaW5Aa2V5 type: kubernetes.io/glusterfs [root@master ~]# kubectl apply -f gluster-heketi-secret.yaml secret/heketi-secret created
2、定義StorageClass並導入
注意:allowVolumeExpansion可以根據情況是否設置為true(默認為false),allowVolumeExpansion為flase時不能動態擴容(例如不能直接修改pvc大小,當allowVolumeExpansion為true時可以修改)
文檔:https://kubernetes.io/zh/docs/concepts/storage/storage-classes/
[root@master ~]# cat gluster-heketi-storageclass.yaml apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: gluster-heketi-storageclass provisioner: kubernetes.io/glusterfs reclaimPolicy: Delete parameters: resturl: "http://172.16.208.210:8080" restauthenabled: "true" restuser: "admin" secretNamespace: "default" secretName: "heketi-secret" volumetype: "replicate:2" [root@master ~]# kubectl apply -f gluster-heketi-storageclass.yaml storageclass.storage.k8s.io/gluster-heketi-storageclass created
3、查看
[root@master ~]# kubectl get secret heketi-secret NAME TYPE DATA AGE heketi-secret kubernetes.io/glusterfs 1 20m [root@master ~]# kubectl get sc NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE gluster-heketi-storageclass kubernetes.io/glusterfs Delete Immediate false 19m
七、測試
1、創建的測試pvc
[root@master ~]# cat test-pvc.yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: test-claim annotations: volume.beta.kubernetes.io/storage-class: "gluster-heketi-storageclass" spec: accessModes: - ReadWriteMany resources: requests: storage: 1Gi
2、導入並查看是否自動創建了pv
[root@master ~]# kubectl apply -f test-pvc.yaml persistentvolumeclaim/test-claim unchanged [root@master ~]# kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE test-claim Bound pvc-34c1b3e5-76ec-4c5e-98b6-f8d5bca6c2eb 1Gi RWX gluster-heketi-storageclass 21m [root@master ~]# kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-34c1b3e5-76ec-4c5e-98b6-f8d5bca6c2eb 1Gi RWX Delete Bound default/test-claim gluster-heketi-storageclass 21m