Kubernetes存储之Heketi管理GlusterFS
GlusterFS是一个可扩展,分布式文件系统,集成来自多台服务器上的磁盘存储资源到单一全局命名空间,以提供共享文件存储
特点:
可以扩展到几PB容量
支持处理数千个客户端
兼容POSIX接口
使用通用硬件,普通服务器即可构建
能够使用支持扩展属性的文件系统,例如ext4,XFS
支持工业标准的协议,例如NFS,SMB
提供很多高级功能,例如副本,配额,跨地域复制,快照以及bitrot检测
支持根据不同工作负载进行调优
glusterfs卷的模式
glusterfs中的volume的模式有很多中,包括以下几种:
分布卷(默认模式):即DHT, 也叫 分布卷: 将文件以hash算法随机分布到 一台服务器节点中存储。
复制模式:即AFR, 创建volume 时带 replica x 数量: 将文件复制到 replica x 个节点中。
条带模式:即Striped, 创建volume 时带 stripe x 数量: 将文件切割成数据块,分别存储到 stripe x 个节点中 ( 类似raid 0 )。
分布式条带模式:最少需要4台服务器才能创建。 创建volume 时 stripe 2 server = 4 个节点: 是DHT 与 Striped 的组合型。
分布式复制模式:最少需要4台服务器才能创建。 创建volume 时 replica 2 server = 4 个节点:是DHT 与 AFR 的组合型。
条带复制卷模式:最少需要4台服务器才能创建。 创建volume 时 stripe 2 replica 2 server = 4 个节点: 是 Striped 与 AFR 的组合型。
三种模式混合: 至少需要8台 服务器才能创建。 stripe 2 replica 2 , 每4个节点 组成一个 组。
heketi介绍
heketi是一个提供RESTful API管理gfs卷的框架,能够在kubernetes、openshift、openstack等云平台上实现动态的存储资源供应,支持gfs多集群管理,便于管理员对gfs进行操作,在kubernetes集群中,pod将存储的请求发送至heketi,然后heketi控制gfs集群创建对应的存储卷。
heketi动态在集群内选择bricks构建指定的volumes,以确保副本会分散到集群不同的故障域内。
heketi还支持任意数量的glusterfs集群,以保证接入的云服务器不局限于单个glusterfs集群。
####生产环境建议glusterFS为外部:
主机名 | IP | 角色 |
---|---|---|
master | 192.168.200.100 | K8S-master |
node | 192.168.200.101 | K8S-node01 |
node | 192.168.200.102 | K8S-node02 |
heketi | 192.168.200.103 | Heketi |
GlusterFS-node | 192.168.200.104 | GlusterFS01 |
GlusterFS-node | 192.168.200.105 | GlusterFS02 |
GlusterFS-node | 192.168.200.106 | GlusterFS03 |
####这里为方便测试演示,采用三台
环境准备:
主机名 | IP | 角色 |
---|---|---|
master01 | 192.168.200.182 | k8s-master,glusterfs01,heketi |
node01 | 192.168.200.183 | k8s-node,glusterfs02 |
node02 | 192.168.200.184 | k8s-node,glusterfs03 |
1.使用kubeadm快速搭建kubernetes集群(glusterfs在kubernetes集群中需要以特权运行,需要在kube-apiserver中添加–allow-privileged=true参数以开启此功能,默认此版本的kubeadm已开启。)
略
2.安装GlusterFs,搭建GlusterFs集群(GlusterFS只需要安装并启动即可,不必组建受信存储池(trusted storage pools))
略
3.部署Heketi
1.安装heketi
#添加gluster yum源
#heketi-client:heketi客户端/命令行工具
[root@master01 ~]# yum -y install centos-release-gluster
[root@master01 ~]# yum -y install heketi heketi-client
2.配置heketi.json
[root@master01 heketi]# cat heketi.json.bak
{
"_port_comment": "Heketi Server Port Number",
"port": "8080",
"_use_auth": "Enable JWT authorization. Please enable for deployment",
"use_auth": false,
"_jwt": "Private keys for access",
"jwt": {
"_admin": "Admin has access to all APIs",
"admin": {
"key": "My Secret"
},
"_user": "User only has access to /volumes endpoint",
"user": {
"key": "My Secret"
}
},
"_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": "mock",
"_sshexec_comment": "SSH username and private key file information",
"sshexec": {
"keyfile": "path/to/private_key",
"user": "sshuser",
"port": "Optional: ssh port. Default is 22",
"fstab": "Optional: Specify fstab file on node. Default is /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" : "debug"
}
}
#修改
[root@master01 heketi]# cat heketi.json
{
"_port_comment": "Heketi Server Port Number",
"port": "8080", #默认端口号
"_use_auth": "Enable JWT authorization. Please enable for deployment",
"use_auth": true, #默认flase,不需要认证
"_jwt": "Private keys for access",
"jwt": {
"_admin": "Admin has access to all APIs",
"admin": {
"key": "admin" #修改
},
"_user": "User only has access to /volumes endpoint",
"user": {
"key": "admin" #修改
}
},
"_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."
],
#三种模式:
# mock:测试环境下创建的volume无法挂载;
# kubernetes:在GlusterFS由kubernetes创建时采用
"executor": "ssh", #生产环境使用ssh或Kubernetes,这里采用ssh模式
"_sshexec_comment": "SSH username and private key file information",
"sshexec": {
"keyfile": "/etc/heketi/heketi_key", #密钥路径
"user": "root", #用户为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"
],
# 默认设置为debug,不设置时的默认值即是warning;
# 日志信息输出在/var/log/message
"loglevel" : "warning"
}
}
3.设置heketi免密访问glusterFS
# 选择ssh执行器,heketi服务器需要免密登陆GlusterFS集群的各节点;
# -t:秘钥类型;
# -q:安静模式;
# -f:指定生成秘钥的目录与名字,注意与heketi.json的ssh执行器中"keyfile"值一致;
# -N:秘钥密码,””即为空
[root@master01 ~]# ssh-keygen -t rsa -q -f /etc/heketi/heketi_key -N ""
# heketi服务由heketi用户启动,heketi用户需要有新生成key的读赋权,否则服务无法启动
[root@master01 ~]# chown heketi:heketi /etc/heketi/heketi_key
# 分发公钥;
# -i:指定公钥
[root@master01 ~]# ssh-copy-id -i /etc/heketi/heketi_key.pub root@192.168.200.182
[root@master01 ~]# ssh-copy-id -i /etc/heketi/heketi_key.pub root@192.168.200.183
[root@master01 ~]# ssh-copy-id -i /etc/heketi/heketi_key.pub root@192.168.200.184
4.启动heketi
[root@master01 ~]# systemctl enable heketi && systemctl start heketi && systemctl status heketi
#验证
[root@master01 ~]# curl 192.168.200.182:8080/hello
Hello from Heketi[root@master01 ~]#
4.设置GlusterFS集群
1.通过topology.json文件定义组建GlusterFS集群;
# topology指定了层级关系:clusters-->nodes-->node/devices-->hostnames/zone;
# node/hostnames字段的manage填写主机ip,指管理通道,在heketi服务器