在Kubernetes中部署GlusterFS+Heketi

簡介

在上一篇《獨立部署GlusterFS+Heketi實現Kubernetes共享存儲》中,咱們說明了如何手動部署GlusterFS+Heketi來提供Kubernetes的共享存儲。node

然而,由於Heketi沒法集羣部署,因此這種部署方式中,Heketi是一個單點。要儘量的消除這個單點,一種方式是直接將Heketi部署到Kubernetes集羣,複用Deployment的特性來確保heketi容器可用。linux

Gluster-Kubernetes

其實若是想直接將heketi和glusterfs直接部署到kubernetes中,已經有開源軟件幫咱們作了這些事情。這就是gluster-kuberntes項目。git

可是咱們這篇文檔並不打算展開來講Gluster-Kubernetes項目,若是對該項目有興趣,能夠自行查閱相關文檔。本篇文檔將經過手動在kubernetes集羣中部署一個Glusterfs+Heketi來展現其是如何在kubernetes中運行的。github

部署

環境準備

主機名 系統 ip地址 角色
ops-k8s-175 ubuntu16.04 192.168.75.175 k8s-node,glusterfs
ops-k8s-176 ubuntu16.04 192.168.75.176 k8s-node,glusterfs
ops-k8s-177 ubuntu16.04 192.168.75.177 k8s-node,glusterfs
ops-k8s-178 ubuntu16.04 192.168.175.178 k8s-node,glusterfs

下載相關文件

其實heketi官方在其源碼包及其heketi-client的二進制包中都包含了將glusterfs及heketi部署到kubernetes的相關示例文件。github上地址以下:https://github.com/heketi/heketi/tree/master/extras/kubernetes數據庫

咱們能夠直接將其所有下載到本地:json

wget https://raw.githubusercontent.com/heketi/heketi/master/extras/kubernetes/glusterfs-daemonset.json
wget https://raw.githubusercontent.com/heketi/heketi/master/extras/kubernetes/heketi-bootstrap.json
wget https://raw.githubusercontent.com/heketi/heketi/master/extras/kubernetes/heketi-deployment.json
wget https://raw.githubusercontent.com/heketi/heketi/master/extras/kubernetes/heketi-service-account.json
wget https://raw.githubusercontent.com/heketi/heketi/master/extras/kubernetes/heketi-start.sh
wget https://raw.githubusercontent.com/heketi/heketi/master/extras/kubernetes/heketi.json
wget https://raw.githubusercontent.com/heketi/heketi/master/extras/kubernetes/topology-sample.json

部署glusterfs

在上面下載的文件中,glusterfs-daemonset.json就是用於部署glusterfs的配置文件,將glusterfs做爲daemonset的方式運行。能夠經過將指定stoargenode=glusterfs標籤來選擇用於部署glusterfs的節點:bootstrap

kubectl label node 192.168.75.175 storagenode=glusterfs
kubectl label node 192.168.75.176 storagenode=glusterfs
kubectl label node 192.168.75.177 storagenode=glusterfs
kubectl label node 192.168.75.178 storagenode=glusterfs

修改glusterfs-daemonset.json使用的image爲gluster/gluster-centos:gluster4u0_centos7,而後執行該json文件:ubuntu

kubectl create -f glusterfs-daemonset.json

便可完成glusterfs部署centos

部署heketi server端

部署heketi以前,須要先爲heketi建立serviceaccount:

kubectl create -f heketi-service-account.json

而後爲該serviceaccount受權,爲其綁定相應的權限來控制gluster的pod,執行以下操做:

kubectl create clusterrolebinding heketi-gluster-admin --clusterrole=edit --serviceaccount=default:heketi-service-account

接着,建立一個Kubernetes secret來保存咱們Heketi實例的配置。必須將配置文件的執行程序設置爲 kubernetes才能讓Heketi server控制gluster pod。

heketi.json的配置修改以下:

......
#打開認證
  "use_auth": true,
......
#修改admin用戶的key
      "key": "adminkey"
......
#修改執行插件爲kubernetes
    "executor": "kubernetes",
......
#備份heketi數據庫
    "backup_db_to_kube_secret": true

執行以下操做,將heketi.json建立爲kubernetes的secret:

kubectl create secret generic heketi-config-secret --from-file=./heketi.json

接着部署heketi的運行容器,配置文件爲heketi-bootstrap.json,須要修改image爲heketi/heketi:7

kubectl create -f heketi-bootstrap.json

經過建立ingress的方式將heketi暴露出來:

# cat heketi.ingress.yaml 
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: traefik
  name: heketi
spec:
  rules:
  - host: heketi.breezey.io
    http:
      paths:
      - path: /
        backend:
          serviceName: deploy-heketi
          servicePort: 8080
          
          
# kubectl create -f hekti.ingress.yaml

至此,完成heketi server端部署

配置heketi client

須要說明的是,heketi的客戶端版本須要與server端對應,server端咱們使用的是7.0,因此客戶端也須要下載7.0版本:

wget https://github.com/heketi/heketi/releases/download/v7.0.0/heketi-client-v7.0.0.linux.amd64.tar.gz

修改topology-sample.json文件,以下:

{
    "clusters": [
        {
            "nodes": [
                {
                    "node": {
                        "hostnames": {
                            "manage": [
                                "192.168.75.175"
                            ],
                            "storage": [
                                "192.168.75.175"
                            ]
                        },
                        "zone": 1
                    },
                    "devices": [
                        "/dev/vda2"
                    ]
                },
                {
                    "node": {
                        "hostnames": {
                            "manage": [
                                "192.168.75.176"
                            ],
                            "storage": [
                                "192.168.75.176"
                            ]
                        },
                        "zone": 1
                    },
                    "devices": [
                        "/dev/vda2"
                    ]
                },
                {
                    "node": {
                        "hostnames": {
                            "manage": [
                                "192.168.75.177"
                            ],
                            "storage": [
                                "192.168.75.177"
                            ]
                        },
                        "zone": 1
                    },
                    "devices": [
                        "/dev/vda2"
                    ]
                },
                {
                    "node": {
                        "hostnames": {
                            "manage": [
                                "192.168.75.178"
                            ],
                            "storage": [
                                "192.168.75.178"
                            ]
                        },
                        "zone": 1
                    },
                    "devices": [
                        "/dev/vda2"
                    ]
                }               
            ]
        }
    ]
}

建立集羣:

heketi-cli  topology load --json topology-sample.json

至此,完成了glusterfs和heketi在kubernetes中的部署,具體的使用可參考《獨立部署GlusterFS+Heketi實現Kubernetes共享存儲》

相關文章
相關標籤/搜索