Kubernetes部署glusterfs(未能部署在wordpress)

Kubernetes部署glusterfs(未能部署在wordpress)

k8s安装glusterfs

1. 安装与配置glusterfs
节点如下
172.16.1.110  master
172.16.1.111  node-1
172.16.1.112  node-2

# 全部节点都是
[root@master-1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6101
10.0.0.110 master-1
10.0.0.111 node-1
10.0.0.112 node-2

1.1 每个节点安装glusterfs全家桶
yum install -y centos-release-gluster 
yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
# 启动服务,并添加到开机启动
systemctl start glusterd.service
systemctl enable glusterd.service

1.2 主节点加入其他节点
[root@master-1 ~]# gluster peer probe node-1
[root@master-1 ~]# gluster peer probe node-2

master 也要 "Peer in Cluster" 状态,你可以尝试手动添加 master 到 GlusterFS 集群。
在 node-1 主机上执行以下命令:
[root@node-1 ~]# gluster peer probe master-1
[root@node-2 ~]# gluster peer probe master-1

# 查看
[root@master-1 ~]# gluster peer status
Number of Peers: 2

Hostname: node-1
Uuid: 408b4bd8-5405-48aa-8e99-18841113b2e9
State: Peer in Cluster (Connected)

Hostname: node-2
Uuid: 1d40328d-6f76-4121-befc-b45b3db8e96e
State: Peer in Cluster (Connected)

[root@node-1 ~]# gluster peer status
Number of Peers: 2

Hostname: master-1
Uuid: e3851007-312f-4da6-bcd2-f1014259cc8a
State: Peer in Cluster (Connected)

Hostname: node-2
Uuid: 1d40328d-6f76-4121-befc-b45b3db8e96e
State: Peer in Cluster (Connected)

[root@node-2 ~]# gluster peer status
Number of Peers: 2

Hostname: master-1
Uuid: e3851007-312f-4da6-bcd2-f1014259cc8a
State: Peer in Cluster (Connected)

Hostname: node-1
Uuid: 408b4bd8-5405-48aa-8e99-18841113b2e9
State: Peer in Cluster (Connected)

1.3 每个节点创建gfs文件夹
mkdir /root/gfs

1.4 主节点使用默认模式创建卷并启动
[root@master-1 ~]# gluster volume create k8s_data master-1:/root/gfs node-1:/root/gfs node-2:/root/gfs  force
[root@master-1 ~]# gluster volume start k8s_data
volume start: k8s_data: success

可以试验一下是否起作用
主节点挂载,并创建test_txt文件

mkdir -p /root/test
mount -t glusterfs master-1:k8s_data /root/test
touch /root/test/test_txt

从节点挂载,并查看
mkdir -p /root/test
mount -t glusterfs master-1:k8s_data /root/test
[root@node-1 ~]# ll /root/test/
total 0
-rw-r--r-- 1 root root 0 Sep 27 17:14 test_txt
验证完毕后主从取消挂载

umount /root/test

2. 配置k8s使用glusterfs
2.1 创建glusterfs-cluster.yaml
必须使用ip而非hostname

apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: 172.16.1.110
  ports:
  - port: 49152
- addresses:
  - ip: 172.16.1.111
  ports:
  - port: 49152
- addresses:
  - ip: 172.16.1.112
  ports:
  - port: 49152
---
apiVersion: v1
kind: Service
metadata:
  name: glusterfs-cluster
spec:
  ports:
  - port: 49152

加载配置
kubectl apply -f glusterfs-cluster.yaml

2.2 创建glusterfs-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  glusterfs:
    endpoints: glusterfs-cluster
    path: k8s_data
    readOnly: false

加载配置
kubectl apply -f glusterfs-pv.yaml

2.3 创建glusterfs-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 10Gi

加载配置
kubectl apply -f glusterfs-pvc.yaml

## 下面是资源清单合集(想不到吧)
cat glusterfs.yaml

apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: 172.16.1.110
  ports:
  - port: 49152
- addresses:
  - ip: 172.16.1.111
  ports:
  - port: 49152
- addresses:
  - ip: 172.16.1.112
  ports:
  - port: 49152
---
apiVersion: v1
kind: Service
metadata:
  name: glusterfs-cluster
spec:
  ports:
  - port: 49152

---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
  - ReadWriteMany
  glusterfs:
    endpoints: glusterfs-cluster
    path: k8s_data
    readOnly: false

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 10Gi

[root@master-1 yaml]# kubectl apply -f glusterfs.yaml 
endpoints/glusterfs-cluster created
service/glusterfs-cluster created
persistentvolume/glusterfs-pv created
persistentvolumeclaim/glusterfs-pvc created

下面没有实验谨慎食用 谨慎食用 谨慎食用 (主要借鉴k8s的部分)

在 Kubernetes 中使用 GlusterFS 通常涉及以下几个步骤,主要是创建 Persistent Volume(PV)和 Persistent Volume Claim(PVC)。这里以一个简单的使用实例为例:

步骤 1: 部署 GlusterFS 集群

首先,你需要在你的节点上部署 GlusterFS 集群。你可以使用 GlusterFS 的 Helm Chart 来简化这个过程。确保 Helm 已经安装在你的集群上。

helm repo add glusterfs https://download.gluster.org/pub/gluster/glusterfs/kubernetes/helm/
helm install glusterfs glusterfs/glusterfs

步骤 2: 创建 GlusterFS 卷

创建 GlusterFS 卷并记录其 IP 地址。你可以在 GlusterFS Helm Chart 中找到相应的服务名称。

kubectl get svc -n glusterfs

步骤 3: 创建 Persistent Volume (PV)

创建一个 Persistent Volume 描述 GlusterFS 卷的属性。在 glusterfs-pv.yaml 文件中添加以下内容:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-pv
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  glusterfs:
    endpoints: glusterfs-cluster
    path: '/myvolume'  # Replace with the actual path on GlusterFS
    readOnly: false
  persistentVolumeReclaimPolicy: Retain

然后应用该配置:

kubectl apply -f glusterfs-pv.yaml

步骤 4: 创建 Persistent Volume Claim (PVC)

在你的应用中创建一个 Persistent Volume Claim。在 glusterfs-pvc.yaml 文件中添加以下内容:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 1Gi  # Adjust the size as needed

然后应用该配置:

kubectl apply -f glusterfs-pvc.yaml

步骤 5: 在 Pod 中使用 GlusterFS 卷

在你的 Pod 配置中引用上述创建的 PVC,例如:

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mycontainer
    image: nginx
    volumeMounts:
    - mountPath: "/usr/share/nginx/html"
      name: glusterfs-storage
  volumes:
  - name: glusterfs-storage
    persistentVolumeClaim:
      claimName: glusterfs-pvc

这个 Pod 将能够访问 GlusterFS 卷的内容。

这只是一个简单的 GlusterFS 在 Kubernetes 中的使用实例。根据你的实际需求,可能需要更详细的配置和调整。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇