k8s+gluster+heketi分布式存储

2019-12-11  本文已影响0人  于飞_d529

部署gluster

部署环境

vmware15
ubuntu16.04    192.168.245.133  k8s-master gluster heketi
ubuntu16.04    192.168.245.134  k8s-node   gluster 
ubuntu16.04    192.168.245.135  k8s-node   gluster 

添加硬盘

    root@ubuntu:/usr/local/heketi/heketi# fdisk -l
    Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 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@ubuntu:/usr/local/heketi/heketi# fdisk /dev/sdb

    Welcome to fdisk (util-linux 2.27.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.


    Command (m for help):#依次输入g->w保存退出
    root@ubuntu:/usr/local/heketi/heketi# fdisk -l
    Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 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
    Disklabel type: gpt
    Disk identifier: D2003869-2A4C-47F4-B600-74E60998A0A1
    root@ubuntu:/usr/local/heketi/heketi# fdisk /dev/sdb

    Welcome to fdisk (util-linux 2.27.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.


    Command (m for help): #依次输入n->一直按回车->w保存退出
    root@ubuntu:/usr/local/heketi/heketi# fdisk -l
    Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 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
    Disklabel type: gpt
    Disk identifier: D2003869-2A4C-47F4-B600-74E60998A0A1

    Device     Start      End  Sectors Size Type
    /dev/sdb1   2048 10485726 10483679   5G Linux filesystem

gluster部署

    apt-get install glusterfs-server glusterfs-common glusterfs-client fuse
    systemctl start glusterfs-server
    systemctl enable glusterfs-server
    gluster peer probe 192.168.245.134
    gluster peer probe 192.168.245.135
    root@ubuntu:/usr/local/heketi/heketi# gluster peer probe 192.168.245.133
    peer probe: success. Probe on localhost not needed

heketi部署

    wget https://github.com/heketi/heketi/releases/download/v5.0.1/heketi-client-v5.0.1.linux.amd64.tar.gz
    wget https://github.com/heketi/heketi/releases/download/v5.0.1/heketi-v5.0.1.linux.amd64.tar.gz
    tar -zxvf heketi-client-v5.0.1.linux.amd64.tar.gz
    tar -zxvf heketi-v5.0.1.linux.amd64.tar.gz
    "_port_comment": "Heketi Server Port Number",
    "port": "18080",#修改端口

    "_use_auth": "Enable JWT authorization. Please enable for deployment",
    "use_auth": true,#修改auth

    "_jwt": "Private keys for access",
    "jwt": {
        "_admin": "Admin has access to all APIs",
        "admin": {
          "key": "adminkey" #修改admin登录密码
        },
        "_user": "User only has access to /volumes endpoint",
        "user": {
          "key": "My Secret"
        }
    },
    ---
    "executor": "ssh",# 修改登录方式

    "_sshexec_comment": "SSH username and private key file information",
    "sshexec": {
      "keyfile": "/root/.ssh/id_rsa", #秘钥地址
      "user": "root",# 登录用户
      "port": "22",# 端口
      "fstab": "/etc/fstab"#  /etc/fstab文件负责配置Linux开机时自动挂载的分区
    },

向heketi中添加cluster、device

    {
        "clusters": [
            {
                "nodes": [
                    {
                        "node": {
                            "hostnames": {
                                "manage": [
                                    "192.168.245.133"
                                ],
                                "storage": [
                                    "192.168.245.133"
                                ]
                            },
                            "zone": 1
                        },
                        "devices": [
                            "/dev/sdb1"
                        ]
                    },
                    {
                        "node": {
                            "hostnames": {
                                "manage": [
                                    "192.168.245.134"
                                ],
                                "storage": [
                                    "192.168.245.134"
                                ]
                            },
                            "zone": 1
                        },
                        "devices": [
                            "/dev/sdb1"
                        ]
                    },
                    {
                        "node": {
                            "hostnames": {
                                "manage": [
                                    "192.168.245.135"
                                ],
                                "storage": [
                                    "192.168.245.135"
                                ]
                            },
                            "zone": 1
                        },
                        "devices": [
                            "/dev/sdb1"
                        ]
                    }             
                ]
            }
        ]
    }
    root@ubuntu:/usr/local/heketi/heketi# ./heketi-cli --server "http://192.168.245.133:18080" --user "admin" --secret "adminkey" topology load --json topology-sample.json
    Creating node 192.168.245.133 ... ID: 1204399251b630ccd34cd25c7c93a597
        Adding device /dev/sdb1
    Creating node 192.168.245.134 ... ID: a77370a6e9d5ee52de9cb71a27475d4a
        Adding device /dev/sdb1 ... OK
    Creating node 192.168.245.135 ... ID: 4668bb56bee757caaf6032638b9b8269
        Adding device /dev/sdb1
    root@ubuntu:/usr/local/heketi/heketi# ./heketi-cli --server "http://192.168.245.133:18080" --user "admin" --secret "adminkey" cluster list
    Clusters:
    Id:baf191bf97b91c6a8b8fad77e99c4ffc
    root@ubuntu:/usr/local/heketi/heketi# ./heketi-cli --server "http://192.168.245.133:18080" --user "admin" --secret "adminkey" node list
    Id:1204399251b630ccd34cd25c7c93a597 Cluster:baf191bf97b91c6a8b8fad77e99c4ffc
    Id:4668bb56bee757caaf6032638b9b8269 Cluster:baf191bf97b91c6a8b8fad77e99c4ffc
    Id:a77370a6e9d5ee52de9cb71a27475d4a Cluster:baf191bf97b91c6a8b8fad77e99c4ffc

k8s使用gluster

    apiVersion: storage.k8s.io/v1beta1 
    kind: StorageClass
    metadata:
      name: glusterfs
    provisioner: kubernetes.io/glusterfs #表示存储分配器,需要根据后端存储的不同而变更
    parameters:
      resturl: "http://192.168.245.133:18080" #heketi API服务提供的url
      restauthenabled: "true" #可选参数,默认值为”false”,heketi服务开启认证时必须设置为”true”
      restuser: "admin" #可选参数,开启认证时设置相应用户名;
      restuserkey: "adminkey" #可选参数,开启认证时设置相应密码;
      volumetype: "replicate:2" #可选参数,设置卷类型及其参数,如果未分配卷类型,则有分配器决定卷类型;如”volumetype: replicate:3”表示3副本的replicate卷,”volumetype: disperse:4:2”表示disperse卷,其中‘4’是数据,’2’是冗余校验,”volumetype: none”表示distribute卷
    kubectl apply -f storageclass-glusterfs.yaml
    root@ubuntu:/usr/local/heketi/heketi# kubectl get storageclass
    NAME        PROVISIONER               AGE
    glusterfs   kubernetes.io/glusterfs   70m
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: glusterfs-test
      namespace: default
      annotations:
        volume.beta.kubernetes.io/storage-class: "glusterfs"
    spec:
      accessModes:
      - ReadWriteMany
      resources:
        requests:
          storage: 1Gi
    root@ubuntu:/usr/local/heketi/heketi# kubectl create -f glusterfs-pvc.yaml 
    persistentvolumeclaim/glusterfs-test created

状态为Bound说明创建成功

    root@ubuntu:/usr/local/heketi/heketi# kubectl get pvc
    NAME             STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
    glusterfs-test   Bound    pvc-f705938e-1bf9-11ea-b5d9-000c29509b70   1Gi        RWX            glusterfs      12s

这里pv为动态创建的

    root@ubuntu:/usr/local/heketi/heketi# kubectl get pv
    NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                    STORAGECLASS   REASON   AGE
    pvc-f705938e-1bf9-11ea-b5d9-000c29509b70   1Gi        RWX            Delete           Bound    default/glusterfs-test   glusterfs               81s

问题

上一篇 下一篇

猜你喜欢

热点阅读