搭建nfs在k8s集群中实现数据持久化(yum安装)
搭建nfs在k8s集群中实现数据持久化
背景:本背锅侠在开发测试环境搭建了一套K8S集群,单节点master,十来个node节点,其中一台node节点特意挂载了大磁盘用来作为nfs server,其他node节点作为client端就可以使用server端的存储空间,这样方便管理。
K8S集群搭建和往集群中添加worker节点就不多说了,可以看我以往的文章。
正题来了。在选中的这台nfs server上操作:
1、安装nfs服务:yum -y install nfs-utils rpcbind
2、启动nfs服务并设置开机自启:systemctl start nfs-server rpcbind && systemctl enable nfs-server rpcbind
3、创建nfs共享目录(本背锅侠将大容量磁盘都挂载到了/data下):mkdir -p /data/k8s
4、编辑配置文件:vi /etc/exports
/nfs *(rw,sync,insecure,no_subtree_check,no_root_squash)
5、然后重启服务:systemctl restart nfs-server
接下来在其他node节点安装nfs服务并做测试:
yum -y install nfs-utils rpcbind
systemctl start nfs rpcbind && systemctl enable nfs rpcbind
showmount -e nfs服务端的IP
大工告成,接下来贴一段yaml文件来展示使用nfs的语法:
kind: Deployment
apiVersion: apps/v1
metadata:
labels:
app: gitlab-ce
name: gitlab-ce
namespace: gitlab-ce
spec:
replicas: 1
selector:
matchLabels:
app: gitlab-ce
template:
metadata:
labels:
app: gitlab-ce
spec:
containers:
- name: gitlab-ce
image: gitlab/gitlab-ce:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: gitlab80
- containerPort: 22
name: gitlab22
volumeMounts:
# gitlab持久化
- name: gitlab-persistent-config
mountPath: /etc/gitlab
- name: gitlab-persistent-logs
mountPath: /var/log/gitlab
- name: gitlab-persistent-data
mountPath: /var/opt/gitlab
volumes:
- name: gitlab-persistent-config
nfs:
server: 10.127.0.17
path: /data/k8s/gitlab/config
- name: gitlab-persistent-logs
nfs:
server: 10.127.0.17
path: /data/k8s/gitlab/logs
- name: gitlab-persistent-data
nfs:
server: 10.127.0.17
path: /data/k8s/gitlab/data
更多推荐
所有评论(0)