k8s+glusterfs+mysql主从复制部署

该博客详细介绍了如何在Kubernetes(k8s)集群中结合GlusterFS进行磁盘分区和安装,为MySQL主从复制部署提供存储解决方案。首先进行了磁盘分区,接着在各节点安装了GlusterFS客户端,并打上特定标签。随后创建了Glusterfs管理服务容器集群,加载了必要的模块。接着,博主展示了如何创建Heketi服务,并通过容器内部执行命令进行集群管理和状态检查。最后,文章提到了准备设置MySQL主从复制集群的步骤,包括查看PV和PVC资源以及服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.磁盘分区(30G)
fdisk -l
fdisk /dev/sda    (n->p->w)

2.在各个node上安装glusterfs客户端

yum install -y glusterfs glusterfs-fuse

在kube-apiserver的启动参数中增加--allow-priviledge=true(默认为true)

3.给各个节点打上标签

kubectl label node k8s-slave1 storagenode=gluster

kubectl label node k8s-slave2 storagenode=gluster

kubectl label node k8s-slave3 storagenode=gluster

kubectl get nodes --show-labels

4.创建glusterfs管理服务容器集群

/etc/kubernetes/manifests/kube-apiserver.yaml

--authorization-mode=RBAC //k8s默认是RBAC模式

//glusterfs-daemonset.yaml

---
apiVersion: apps/v1
kind: DaemonSet

metadata:
  name: glusterfs
  labels:
    glusterfs: daemonset
  annotations:
    description: GlusterFS DaemonSet
    tags: glusterfs
spec:
  selector:
    matchLabels:
      glusterfs-node: pod
  template:
    metadata:
      name: glusterfs
      labels:
        glusterfs-node: pod
    spec:
      nodeSelector:
        storagenode: glusterfs
      hostNetwork: true
      containers:
      - image: gluster/gluster-centos:latest
        imagePullPolicy: IfNotPresent
        name: glusterfs
        resources:
          requests:
            memory: 100Mi
            cpu: 100m
        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-host-dev
          mountPath: "/mnt/host-dev"
        - name: glusterfs-misc
          mountPath: "/var/lib/misc/glusterfsd"
        - name: glusterfs-block-sys-class
          mountPath: "/sys/class"
        - name: glusterfs-block-sys-module
          mountPath: "/sys/module"
        - name: glusterfs-cgroup
          mountPath: "/sys/fs/cgroup"
          readOnly: true
        - name: glusterfs-ssl
          mountPath: "/etc/ssl"
          readOnly: true
        - name: kernel-modules
          mountPath: "/lib/modules"
          readOnly: true
        securityContext:
          capabilities: {}
          privileged: true
        readinessProbe:
          timeoutSeconds: 3
          initialDelaySeconds: 40
          exec:
            command:
            - "/bin/bash"
            - "-c"
            - "if command -v /usr/local/bin/status-probe.sh; then /usr/local/bin/status-probe.sh readiness; else systemctl status glusterd.service; fi"
          periodSeconds: 25
          successThreshold: 1
          failureThreshold: 50
        livenessProbe:
          timeoutSeconds: 3
          initialDelaySeconds: 40
          exec:
            command:
            - "/bin/bash"
            - "-c"
            - "if command -v /usr/local/bin/status-probe.sh; then /usr/local/bin/status-probe.sh liveness; else systemctl status glusterd.service; fi"
          periodSeconds: 25
          successThreshold: 1
          failureThreshold: 50
      volu
要使用 Kubernetes 部署 GlusterFS,需要进行以下步骤: 1. 安装 GlusterFSKubernetes 集群中的每个节点上安装 GlusterFS,可以使用以下命令: ```shell $ sudo apt-get install software-properties-common -y $ sudo add-apt-repository ppa:gluster/glusterfs-7 -y $ sudo apt-get update $ sudo apt-get install glusterfs-server -y ``` 2. 创建 GlusterFS 卷 可以使用 GlusterFS 的命令行工具 `gluster` 创建卷。首先需要创建一个 GlusterFS 集群,可以使用以下命令: ```shell $ sudo gluster peer probe <node1> $ sudo gluster peer probe <node2> ``` 其中,`<node1>` 和 `<node2>` 是 Kubernetes 集群中的两个节点。然后可以使用以下命令创建 GlusterFS 卷: ```shell $ sudo gluster volume create <volume-name> replica 2 <node1>:/data/glusterfs <node2>:/data/glusterfs force ``` 其中,`<volume-name>` 是卷的名称,`<node1>` 和 `<node2>` 是 GlusterFS 集群中的两个节点,`/data/glusterfs` 是 GlusterFS 的存储目录。 3. 创建 Kubernetes 存储类 可以使用以下 YAML 文件创建 Kubernetes 存储类: ```yaml kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: glusterfs-storage provisioner: kubernetes.io/glusterfs parameters: resturl: "http://<node1>:24007" restauthenabled: "false" restuser: "" secretNamespace: "default" secretName: "heketi-secret" ``` 其中,`<node1>` 是 GlusterFS 集群中的一个节点。 4. 创建 Kubernetes PV 和 PVC 可以使用以下 YAML 文件创建 Kubernetes PV 和 PVC: ```yaml kind: PersistentVolume apiVersion: v1 metadata: name: glusterfs-pv spec: storageClassName: glusterfs-storage capacity: storage: 1Gi accessModes: - ReadWriteMany glusterfs: endpoints: glusterfs-cluster path: <volume-name> readOnly: false --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: glusterfs-pvc spec: storageClassName: glusterfs-storage accessModes: - ReadWriteMany resources: requests: storage: 1Gi ``` 其中,`<volume-name>` 是 GlusterFS 卷的名称。 5. 使用 PVC 创建 Pod 可以使用以下 YAML 文件创建 Kubernetes Pod: ```yaml apiVersion: v1 kind: Pod metadata: name: glusterfs-pod spec: containers: - name: glusterfs-container image: nginx volumeMounts: - name: glusterfs-volume mountPath: /var/www/html volumes: - name: glusterfs-volume persistentVolumeClaim: claimName: glusterfs-pvc ``` 这个 Pod 会自动挂载 GlusterFS 存储卷到 `/var/www/html` 目录。 以上就是使用 Kubernetes 部署 GlusterFS 的步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值