k8s集群部署gluster及使用系列(三)

297 阅读2分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第3天,点击查看活动详情

部署gluster

gluster容器镜像制作

由于官方镜像gluster/gluster-centos最新提交是3年前的,版本较老旧,这里使用最新版本9.6构建容器镜像

  1. 编辑dockerfile
FROM centos:7
RUN set -x \
  && yum -y install centos-release-gluster \
  && yum -y install glusterfs glusterfs-server glusterfs-fuse \
  && yum -y install xfsprogs

EXPOSE 24007
ENV LOG_LEVEL=INFO
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
  1. 编辑容器entrypoint脚本
#!/bin/sh

ln -s /usr/lib/systemd/system/glusterd.service /etc/systemd/system/multi-user.target.wants/glusterd.service
exec /usr/sbin/init
systemctl enable --now glusterd
  1. 构建镜像
    docker build -t <reg_url>/gluster:9.6 .
  2. 上传至私有镜像仓库
    docker push <reg_url>/gluster:9.6

注意:gluster容器需运行在特权模式下docker run --privileged

k8s集群部署gluster daemonset

  1. 将需要部署gluster服务的主机(三台或以上,保证均有一个容量、性能相当的未格式化的磁盘或分区,如/dev/sda5)加入k8s集群
  2. 给上述节点打上特定标签和污点,保证gluster只部署在这些节点并且其他应用不会部署到这些节点。
  3. 编辑和应用gluster-ds.yaml
kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: glusterfs
  namespace: yunwei
  labels:
    glusterfs: daemonset
spec:
  selector:
    matchLabels:
      app: glusterfs
  template:
    metadata:
      name: glusterfs
      labels:
        app: glusterfs
        glusterfs: pod
        glusterfs-node: pod
    spec:
      nodeSelector:
        test.com/yunwei: glusterfs
      tolerations:
      - effect: NoSchedule
        key: test.com/yunwei
      hostNetwork: true
      containers:
      - image: <reg_url>/gluster:9.6
        name: glusterfs
        imagePullPolicy: Always
        volumeMounts:
        - name: glusterfs-heketi
          mountPath: "/var/lib/heketi"
        - name: glusterfs-run
          mountPath: "/run"
        - name: glusterfs-lvm
          mountPath: "/run/lvm"
        #- name: glusterfs-etc
        #  mountPath: "/etc/glusterfs"
        - name: glusterfs-logs
          mountPath: "/var/log/glusterfs"
        - name: glusterfs-config
          mountPath: "/var/lib/glusterd"
        - name: glusterfs-dev
          mountPath: "/dev"
        - name: glusterfs-misc
          mountPath: "/var/lib/misc/glusterfsd"
        - name: glusterfs-cgroup
          mountPath: "/sys/fs/cgroup"
          readOnly: true
        - name: glusterfs-ssl
          mountPath: "/etc/ssl"
          readOnly: true
        securityContext:
          capabilities: {}
          privileged: true
      volumes:
      - name: glusterfs-heketi
        hostPath:
          path: "/home/jpadmin/glusterfs-heketi"
      - name: glusterfs-run
        hostPath:
          path: "/run/gluster"
      - name: glusterfs-lvm
        hostPath:
          path: "/run/lvm"
      #- name: glusterfs-etc
      #  hostPath:
      #    path: "/etc/glusterfs"
      - name: glusterfs-logs
        hostPath:
          path: "/home/jpadmin/glusterfs-logs"
      - name: glusterfs-config
        hostPath:
          path: "/home/jpadmin/glusterfs"
      - name: glusterfs-dev
        hostPath:
          path: "/dev"
      - name: glusterfs-misc
        hostPath:
          path: "/home/jpadmin/glusterfs-misc"
      - name: glusterfs-cgroup
        hostPath:
          path: "/sys/fs/cgroup"
      - name: glusterfs-ssl
        hostPath:
          path: "/etc/ssl"

kubectl apply -f gluster-ds.yaml