k8s glusterfs mysql_k8s使用glusterfs实现动态持久化存储
简介
本文章介绍如何使用glusterfs为k8s提供动态申请pv的功能。glusterfs提供底层存储功能,heketi为glusterfs提供restful风格的api,方便管理glusterfs。支持k8s的pv的3种访问模式ReadWriteOnce,ReadOnlyMany ,ReadWriteMany
访问模式只是能力描述,并不是强制执行的,对于没有按pvc声明的方式使用pv,存储提供者应该负责访问时的运行错误。例如如果设置pvc的访问模式为ReadOnlyMany ,pod挂载后依然可写,如果需要真正的不可写,申请pvc是需要指定 readOnly: true 参数
安装
实验用的Vagrantfile# -*- mode: ruby -*-# vi: set ft=ruby :ENV["LC_ALL"] = "en_US.UTF-8"Vagrant.configure("2") do |config|
(1..3).each do |i|
config.vm.define "lab#{i}" do |node|
node.vm.box = "centos-7.4-docker-17"
node.ssh.insert_key = false
node.vm.hostname = "lab#{i}"
node.vm.network "private_network", ip: "11.11.11.11#{i}"
node.vm.provision "shell", inline: "echo hello from node #{i}"
node.vm.provider "virtualbox" do |v|
v.cpus = 2
v.customize ["modifyvm", :id, "--name", "lab#{i}", "--memory", "3096"]
file_to_disk = "lab#{i}_vdb.vdi"
unless File.exist?(file_to_disk) # 50GB
v.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024] end
v.customize ['storageattach', :id, '--storagectl', 'IDE', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk] end
end
endend
环境配置说明# 安装 glusterfs 每节点需要提前加载 dm_thin_pool 模块modprobe dm_thin_pool# 配置开启自加载cat >/etc/modules-load.d/glusterfs.conf<
dm_thin_poolEOF# 安装 glusterfs-fuseyum install -y glusterfs-fuse
安装glusterfs与heketi# 安装 heketi client# https://github.com/heketi/heketi/releases# 去github下载相关的版本wget https://github.com/heketi/heketi/releases/download/v7.0.0/heketi-client-v7.0.0.linux.amd64.tar.gztar xf heketi-client-v7.0.0.linux.amd64.tar.gz
cp heketi-client/bin/heketi-cli /usr/local/bin# 查看版本heketi-cli -v# 如下部署步骤都在如下目录执行cd heketi-client/share/heketi/kubernetes# 在k8s中部署 glusterfskubectl create -f glusterfs-daemonset.json# 查看 node 节点kubectl get nodes# 给提供存储 node 节点打 labelkubectl label node lab1 lab2 lab3 storagenode=glusterfs# 查看 glusterfs 状态kubectl get pods -o wide# 部署 heketi server # 配置 heketi server 的权限kubectl create -f heketi-service-account.json
kubectl create clusterrolebinding heketi-gluster-admin --clusterrole=edit --serviceaccount=default:heketi-service-account# 创建 cofig secretkubectl create secret generic heketi-config-secret --from-file=./heketi.json# 初始化部署kubectl create -f heketi-bootstrap.json# 查看 heketi bootstrap 状态kubectl get pods -o wide
kubectl get svc# 配置端口转发 heketi serverHEKETI_BOOTSTRAP_POD=$(kubectl get pods | grep deploy-heketi | awk '{print $1}')
kubectl port-forward $HEKETI_BOOTSTRAP_POD 58080:8080# 测试访问# 另起一终端curl http://localhost:58080/hello# 配置 glusterfs# hostnames/manage 字段里必须和 kubectl get node 一致# hostnames/storage 指定存储网络 ip 本次实验使用与k8s集群同一个ipcat >topology.json<
{ "clusters": [
{ "nodes": [
{ "node": { "hostnames": { "manage": [ "lab1"
], "storage": [ "11.11.11.111"
]
}, "zone": 1
}, "devices": [
{ "name": "/dev/sdb", "destroydata": false
}
]
},
{ "node": { "hostnames": { "manage": [ "lab2"
], "storage": [ "11.11.11.112"
]
}, "zone": 1
}, "devices": [
{ "name": "/dev/sdb", "destroydata": false
}
]
},
{ "node": { "hostnames": { "manage": [ "lab3"
], "storage": [ "11.11.11.113"
]
}, "zone": 1
}, "devices": [
{ "name": "/dev/sdb", "destroydata": false
}
]
}
]
}
]
}
EOF
export HEKETI_CLI_SERVER=http://localhost:58080heketi-cli topology load --json=topology.json# 使用 Heketi 创建一个用于存储 Heketi 数据库的 volumeheketi-cli setup-openshift-heketi-storage
kubectl create -f heketi-storage.json# 查看状态# 等所有job完成 即状态为 Completed# 才能进行如下的步骤kubectl get pods
kubectl get job# 删除部署时产生的相关资源kubectl delete all,service,jobs,deployment,secret --selector="deploy-heketi"# 部署 heketi serverkubectl create -f heketi-deployment.json# 查看 heketi server 状态kubectl get pods -o wide
kubectl get svc# 查看 heketi 状态信息# 配置端口转发 heketi serverHEKETI_BOOTSTRAP_POD=$(kubectl get pods | grep heketi | awk '{print $1}')
kubectl port-forward $HEKETI_BOOTSTRAP_POD 58080:8080export HEKETI_CLI_SERVER=http://localhost:58080heketi-cli cluster listheketi-cli volume list
测试# 创建 StorageClass# 由于没有开启认证# restuser restuserkey 可以随意写HEKETI_SERVER=$(kubectl get svc | grep heketi | head -1 | awk '{print $3}')echo $HEKETI_SERVERcat >storageclass-glusterfs.yaml<
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: gluster-heketi
provisioner: kubernetes.io/glusterfs
parameters:
resturl: "http://$HEKETI_SERVER:8080"
restauthenabled: "false"
restuser: "will"
restuserkey: "will"
gidMin: "40000"
gidMax: "50000"
volumetype: "replicate:3"EOF
kubectl create -f storageclass-glusterfs.yaml# 查看kubectl get sc# 创建pvc测试cat >gluster-pvc-test.yaml<
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gluster1
annotations:
volume.beta.kubernetes.io/storage-class: gluster-heketi
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
EOF
kubectl apply -f gluster-pvc-test.yaml
# 查看kubectl get pvc
kubectl get pv
# 创建 nginx pod 挂载测试cat >nginx-pod.yaml<
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod1
labels:
name: nginx-pod1
spec:
containers:
- name: nginx-pod1
image: nginx:alpine
ports:
- name: web
containerPort: 80
volumeMounts:
- name: gluster-vol1
mountPath: /usr/share/nginx/html
volumes:
- name: gluster-vol1
persistentVolumeClaim:
claimName: gluster1
EOF
kubectl apply -f nginx-pod.yaml
# 查看kubectl get pods -o wide
# 修改文件内容kubectl exec -ti nginx-pod1 -- /bin/sh -c 'echo Hello World from GlusterFS!!! > /usr/share/nginx/html/index.html'
# 访问测试POD_ID=$(kubectl get pods -o wide | grep nginx-pod1 | awk '{print $(NF-1)}')
curl http://$POD_ID
# node 节点查看文件内容GLUSTERFS_POD=$(kubectl get pod | grep glusterfs | head -1 | awk '{print $1}')
kubectl exec -ti $GLUSTERFS_POD /bin/sh
mount | grep heketi
cat /var/lib/heketi/mounts/vg_56033aa8a9131e84faa61a6f4774d8c3/brick_1ac5f3a0730457c
作者:CountingStars_
链接:https://www.jianshu.com/p/29e13149ac50
k8s glusterfs mysql_k8s使用glusterfs实现动态持久化存储相关推荐
- AKS使用Azure File实现动态持久化存储
本文作者|搪瓷小娃娃 本文来源|搪瓷小娃娃博客园 如我们所知,Kubernetes通过 Volume 为集群中的容器提供存储,通过Persistent Volume 和 Persistent Volu ...
- k8s使用glusterfs实现动态持久化存储
简介 本文章介绍如何使用glusterfs为k8s提供动态申请pv的功能.glusterfs提供底层存储功能,heketi为glusterfs提供restful风格的api,方便管理glusterfs ...
- K8S持久化存储:NFS+StorageClass实现动态供给
K8S持久化存储:NFS+StorageClass实现动态供给 一.简介:K8S中的持久化存储 二.部署nfs-provisioner 三.创建StorageClass 四.实验 实验1:部署depl ...
- 部署k8s(15):持久化存储方案
一.ConfigMap 1.概念 ConfigMap的功能在k8s1.2版本中引入的,许多应用程序会从配置文件,命令行参数或环境变量中读取配置信息.ConfigMap API会给我们提供了向容器中注入 ...
- K8s 或 K3s 集群中持久化存储方案选型
存储架构 1 三个概念: pv , pvc ,storageclass pv - 持久化卷, 支持本地存储和网络存储, 例如hostpath,ceph rbd, nfs等,只支持两个属性, capac ...
- k8s之持久化存储PV、PVC
目录 前言 一.k8s 容器磁盘 1.1 Volume(存储卷) 1.2 emptyDir 存储卷 1.3 hostPath存储卷 二.PV和PVC 1.PV 概念 2.PVC概念 3.PV 与 P ...
- 一文读懂 K8s 持久化存储流程
作者 | 孙志恒(惠志) 阿里巴巴开发工程师 **导读:**众所周知,K8s 的持久化存储(Persistent Storage)保证了应用数据独立于应用生命周期而存在,但其内部实现却少有人提及.K ...
- 【k8s的持久化存储】PV、PVC、StorageClass讲解
一.PV和PVC的引入 Volume 提供了非常好的数据持久化方案,不过在可管理性上还有不足. Pod 通常是由应用的开发人员维护,而 Volume 则通常是由存储系统的管理员维护.开发人员要获得上面 ...
- 02.Kubernetes 和 KubeSphere 集群安装配置持久化存储(nfs)并通过StatefulSet动态为pod生成pv挂载
Kubernetes 和 KubeSphere 集群安装配置持久化存储(nfs)并通过StatefulSet动态为pod生成pv挂载 简介 1. 安装配置前置环境 1.1 安装nfs文件系统 1.1. ...
最新文章
- Navicat 2003-can't connect to MYSQL server on 'localhost'(10061)
- 虚拟机磁盘类型_虚拟机存储类型分为哪些种类
- 读服务器文件,读取服务器文件
- 使用SharePoint 2007 Web Service上传文件到文档库
- 基于便签纸的无限延生学习方法
- python模拟网页点击_python怎么模拟点击网页按钮
- 攻防:如何防止动态hook绕过jni签名校验
- Leetcode 950. Reveal Cards In Increasing Order
- 使用双栈实现一个队列
- 弹出新窗体 winform 1615018696
- 【JAVA】在jar文件中引用图片等外部资源的问题
- python压缩算法_Python实现压缩和解压缩ZIP文件的方法分析
- nodejs后台系列--第五篇-购买云服务器,安装宝塔面板
- C/C++基础学习代码(1)
- python画图软件是哪个_python画图软件是哪个
- golang操作elasticsearch(oliver/elastic使用文档)
- Android 12/12L 全面升级、微信和“吃鸡”都在用 Flutter,2021 Google 开发者大会你看了吗?
- 在PC下载微信视频号里面的视频
- android ormlite框架,Android ORMLite 框架的入门用法
- 自适应均衡matlab仿真,对比RLS,LMS以及NLMS的均衡前后星座图效果,调制采用4QAM,16QAM,64QAM
热门文章
- 如何枚举String类型的枚举?
- JSLint说“缺少基数参数”
- 为什么要使用Ruby的attr_accessor,attr_reader和attr_writer?
- Win10电脑定时关机无效怎么办
- 如何在Win11上本地显示CPU、GPU和RAM使用情况?
- MDC记录activiti流程ID
- char*和CString转换
- hive 直接访问mysql_hive 直接插入mysql
- 什么是基本包装类型?
- Vue 报错Error: No PostCSS Config found解决办法