搭建nfs在k8s集群中实现数据持久化(yum安装)

背景:本背锅侠在开发测试环境搭建了一套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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维无止境

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值