如何在Kubernetes里使用Glusterfs存储
1166 字
6 分钟
如何在Kubernetes里使用Glusterfs存储
部署 Glusterfs 参考: [[glusterfs]]
Kubernetes 通过 StorageClass 访问 heketi,heketi 负责管理 Glusterfs 集群
1 heketi
1.1 安装
1.1.1 配置 yum 源并安装
cat /etc/yum.repos.d/glusterfs.repo[glusterfs]name=glusterfsbaseurl=https://buildlogs.centos.org/centos/7/storage/x86_64/gluster-9/enabled=1gpgcheck=0yum install -y heketi heketi-client1.1.2 配置文件
这个一般只需要修改用户名与 key
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" # admin key }, "_user": "User only has access to /volumes endpoint", "user": { "key": "user" } },
"_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": "ops", # 远程用户名 "port": "22", # 远程端口 "sudo": true, # 是否sudo "fstab": "/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" : "info" # 日志级别 }}1.1.3 添加免密登录
cd /etc/heketi/ssh-keygen -t rsa -q -f /etc/heketi/heketi_key -N ""ssh-copy-id -i /etc/heketi/heketi_key.pub -p 9999 ops@10.1.1.1ssh-copy-id -i /etc/heketi/heketi_key.pub -p 9999 ops@10.1.1.2ssh-copy-id -i /etc/heketi/heketi_key.pub -p 9999 ops@10.1.1.31.1.4 启动
systemctl enable heketisystemctl start heketi1.1.5 查看与测试
systemctl status heketicurl 10.1.1.1:8080/helloHello from Heketi1.2 添加 Glusterfs 集群
1.2.1 添加 heketi 专用磁盘
不需要格式化
dd if=/dev/zero of=gfs-data.img bs=1M count=10240losetup -d /dev/loop10losetup /dev/loop10 gfs-data.img查看刚才创建的虚拟磁盘
lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTloop10 7:10 0 10G 0 loop1.2.2 配置 Glusterfs 集群
- 磁盘一定要与上面查询到的一样
- 可以使用主机名,我为了方便直接使用 ip 地址了
cat /etc/heketi/topology.json
{ "clusters": [ { "nodes": [ { "node": { "hostnames": { "manage": [ "10.1.1.1" ], "storage": [ "10.1.1.1" ] }, "zone": 1 }, "devices": [ "/dev/loop10" ] }, { "node": { "hostnames": { "manage": [ "10.1.1.2" ], "storage": [ "10.1.1.2" ] }, "zone": 1 }, "devices": [ "/dev/loop10" ] }, { "node": { "hostnames": { "manage": [ "10.1.1.3" ], "storage": [ "10.1.1.3" ] }, "zone": 1 }, "devices": [ "/dev/loop10" ] }, { "node": { "hostnames": { "manage": [ "10.1.1.4" ], "storage": [ "10.1.1.4" ] }, "zone": 1 }, "devices": [ "/dev/loop10" ] } ] } ] }1.2.3 连接集群
heketi-cli --user admin --secret admin topology load --json=/etc/heketi/topology.json Found node 10.1.1.1 on cluster bd307c566431464e6d91578ff88724f8 Adding device /dev/loop10 ... OK Found node 10.1.1.2 on cluster bd307c566431464e6d91578ff88724f8 Adding device /dev/loop10 ... OK Found node 10.1.1.3 on cluster bd307c566431464e6d91578ff88724f8 Adding device /dev/loop10 ... OK Found node 10.1.1.4 on cluster bd307c566431464e6d91578ff88724f8 Adding device /dev/loop10 ... OK1.2.4 创建测试存储卷
heketi-cli --user admin --secret admin volume create --size=5
Name: vol_399d09a026f7e9faa4c112fa01c01f97Size: 3Volume Id: 399d09a026f7e9faa4c112fa01c01f97Cluster Id: bd307c566431464e6d91578ff88724f8Mount: 10.1.1.1:vol_399d09a026f7e9faa4c112fa01c01f97Mount Options: backup-volfile-servers=10.1.1.2,10.1.1.3,10.1.1.4Block: falseFree Size: 0Reserved Size: 0Block Hosting Restriction: (none)Block Volumes: []Durability Type: replicateDistribute Count: 1Replica Count: 31.2.5 查看
1.2.5.1 glusterfs
gluster volume info
Volume Name: vol_399d09a026f7e9faa4c112fa01c01f97Type: ReplicateVolume ID: 26c8ae49-00e4-4f1b-9388-e2e3ec5eabf9Status: StartedSnapshot Count: 0Number of Bricks: 1 x 3 = 3Transport-type: tcpBricks:Brick1: 10.1.1.3:/var/lib/heketi/mounts/vg_61f345a18c1093cac5abfc6a373a8716/brick_0826c144799419a265dae9759214bfa2/brickBrick2: 10.1.1.1:/var/lib/heketi/mounts/vg_e5b0b51220b519ed7bfb553ac1073a1f/brick_163d78579056f4e38ca6e8a0f8467f03/brickBrick3: 10.1.1.4:/var/lib/heketi/mounts/vg_034008384665cab8fb2fdb1477893424/brick_7266a0b5b52f60e8c363a2e17f3a6915/brickOptions Reconfigured:user.heketi.id: 399d09a026f7e9faa4c112fa01c01f97cluster.granular-entry-heal: onstorage.fips-mode-rchecksum: ontransport.address-family: inetnfs.disable: onperformance.client-io-threads: off能看到说明以前正常,如果看不到看看日志,应该是免密没有做好
1.2.6 删除
heketi-cli --user admin --secret admin volume delete ${Volume Id}2 Kubernetes
2.1 安装 glusterfs 客户端
所有节点最好都执行
yum install glusterfs-fuse -y
2.2 StorageClass
2.2.1 查看 heketi 的 Cluster Id
heketi-cli --user admin --secret admin topology infoCluster Id: b122b2fa65f1e02648d0bc434deefc5e
File: true Block: true
Volumes: ...........................2.2.2 StorageClass 配置文件
cat gfs.yamlapiVersion: storage.k8s.io/v1kind: StorageClassmetadata: name: gluster-heketi-storageclassprovisioner: kubernetes.io/glusterfsparameters: resturl: "http://10.1.1.1:8080" # heketi服务端地址 clusterid: "b122b2fa65f1e02648d0bc434deefc5e" # 刚才查到的Cluster Id restauthenabled: "true" restuser: "admin" secretNamespace: "gfs" secretName: "heketi-secret" gidMin: "40000" gidMax: "50000" volumetype: "replicate:2"---apiVersion: v1kind: Secretmetadata: name: heketi-secretdata: key: YWRtaW4= # heketi.json里配置的admin key base64加密type: kubernetes.io/glusterfs添加
kubectl apply -f gfs.yaml -n gfs2.3 pvc
cat pvc.yamlkind: PersistentVolumeClaimapiVersion: v1metadata: name: gfs-pvcspec: storageClassName: gluster-heketi-storageclass accessModes: - ReadWriteMany resources: requests: storage: 1G
kubectl apply -f pvc.yaml -n gfs2.3.1 查看
kubectl get pvc -n gfsNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEgfs-pvc Bound pvc-e3e5cfb6-25b1-429c-8e85-2bf93a5ae61f 1Gi RWX gluster-heketi-storageclass 4d17h2.4 pod
cat pod.yamlkind: PodapiVersion: v1metadata: name: gfs-pod namespace: gfsspec: containers: - name: gfs-pod image: nginx volumeMounts: - name: pvc mountPath: "/mnt" volumes: - name: pvc persistentVolumeClaim: claimName: gfs-pvc2.5 查看
2.5.1 pod
kubectl get pod -n gfsNAME READY STATUS RESTARTS AGEgfs-pod 1/1 Running 0 4d17h2.5.2 Glusterfs
gluster volume info
Volume Name: vol_3373ccb6e612ae94f39d56a8b55c5068Type: ReplicateVolume ID: 751b7641-443f-4207-875a-4d42f13abfefStatus: StartedSnapshot Count: 0Number of Bricks: 1 x 2 = 2............3 静态绑定
3.1 glusterfs 创建 volume
gluster volume create kube_vol 10.1.1.1:/data/gfs2_data 10.1.1.2:/data/gfs2_data 10.1.1.3:/data/gfs2_data
3.1.1 启动 volume
gluster volume start kube_vol
3.2 配置 kubernetes 访问 glusterfs 集群
cat endpoints.yaml
apiVersion: v1kind: Endpointsmetadata: name: glusterfs-clustersubsets:- addresses: - ip: 10.1.1.1 ports: - port: 20- addresses: - ip: 10.1.1.2 ports: - port: 20- addresses: - ip: 10.1.1.3 ports: - port: 20- addresses: - ip: 10.1.1.4 ports: - port: 20---apiVersion: v1kind: Servicemetadata: name: glusterfs-clusterspec: ports: - port: 203.3 创建 pv
apiVersion: v1kind: PersistentVolumemetadata: name: gfs-pvspec: accessModes: - ReadWriteOnce capacity: storage: 1Gi glusterfs: endpoints: glusterfs-cluster path: kube_vol readOnly: true3.4 创建 pvc 绑定 pv
apiVersion: v1kind: PersistentVolumeClaimmetadata: name: gfs-pvc2spec: volumeName: gfs-pv accessModes: ["ReadWriteOnce"] resources: requests: storage: 1Gi3.5 查看
kubectl get pvc gfs-pvc2 -n gfsNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEgfs-pvc2 Bound gfs-pv 1Gi RWO 19m4 问题
4.1 mount: unknown filesystem type ‘glusterfs’
安装 glusterfs 客户端
yum install glusterfs-fuse -y
4.2 添加集群初始化失败
硬盘不需要格式化
4.3 pod 挂载不上 pvc
查看 glusterfs 集群 volume 是否正常,可能没启动,gluster volume status
文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!
如何在Kubernetes里使用Glusterfs存储
https://ccops.cc/posts/2c594405/ 相关文章 智能推荐
1
如何在Kubernetes里使用本地存储
🐳云原生 如何在Kubernetes里使用节点磁盘存储数据
2
如何在Kubernetes里使用SMB存储
🐳云原生 如何在Kubernetes里使用smb作为存储后端
3
如何在Kubernetes里使用NFS存储
🐳云原生 如何在Kubernetes里使用NFS作为存储后端
4
如何在Kubernetes里使用Minio存储
🐳云原生 如何在Kubernetes里使用Minio作为存储后端
5
如何在Kubernetes里使用cephrdb作为存储
🐳云原生 如何在Kubernetes里使用cephrbd作为存储后端
随机文章 随机推荐