首页 > 其他分享 >基于NFS实现pod数据持久化

基于NFS实现pod数据持久化

时间:2022-08-20 17:44:13浏览次数:75  
标签:easzlab 持久 deploy redis cluster NFS pod k8s root

一、nfs-server服务端:
挂载一块新磁盘
1.1、格式化并挂载
parted /dev/vdb mklable xfs

parted /dev/vdb primay 0% 100%

mkfs.xfs /dev/vdb1 

echo "/dev/vdb1 /nfs_share xfs defaults 0 0" >> /etc/fstab

mount -a 

1.2、安装nfs服务
apt install nfs-kernel-server -y
echo "/nfs_share 172.16.88.0/24(rw,sync,no_root_squash,no_subtree_check)" >> /etc/exports
exportfs -r

二、nfs客户端

2.1、安装客户端工具
apt-get install nfs-common -y

showmount 验证是否可以查看远程主机nfs

2.2、在k8s部署redis进行测试

 创建pv、pvc

root@easzlab-deploy:~/redis-cluster/redis-k8s# cat redis-pv.yaml 
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: redis-datadir-pv-1
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  nfs:
    path: /nfs_share/k8sdata/magedu/redis-datadir-1
    server: 172.16.88.169
root@easzlab-deploy:~/redis-cluster/redis-k8s#
root@easzlab-deploy:~/redis-cluster/redis-k8s# cat redis-pvc.yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: redis-datadir-pvc-1
  namespace: magedu
spec:
   volumeName: redis-datadir-pv-1
   accessModes:
      - ReadWriteOnce
   resources:
     requests:
       storage: 10Gi
root@easzlab-deploy:~/redis-cluster/redis-k8s#
root@easzlab-deploy:~/redis-cluster/redis-k8s# kubectl create ns magedu
namespace/magedu created
root@easzlab-deploy:~/redis-cluster/redis-k8s# kubectl apply -f redis-pvc.yaml 
persistentvolumeclaim/redis-datadir-pvc-1 created
root@easzlab-deploy:~/redis-cluster/redis-k8s# kubectl get pvc -A
NAMESPACE   NAME                  STATUS   VOLUME               CAPACITY   ACCESS MODES   STORAGECLASS   AGE
magedu      redis-datadir-pvc-1   Bound    redis-datadir-pv-1   10Gi       RWO                           69s
root@easzlab-deploy:~/redis-cluster/redis-k8s# kubectl get pv -A
NAME                 CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                        STORAGECLASS   REASON   AGE
redis-datadir-pv-1   10Gi       RWO            Retain           Bound    magedu/redis-datadir-pvc-1                           9m53s
root@easzlab-deploy:~/redis-cluster/redis-k8s#

2.3、编写deplayment,部署redis

root@easzlab-deploy:~/redis-cluster/redis-k8s# cat redis-k8s-deployment.yaml 
kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    app: devops-redis
  name: deploy-devops-redis
  namespace: magedu
spec:
  replicas: 1
  selector:
    matchLabels:
      app: devops-redis
  template:
    metadata:
      labels:
        app: devops-redis
    spec:
      containers:
        - name: redis-container
          image: harbor.magedu.net/magedu/redis:v4.0.14
          imagePullPolicy: Always
          volumeMounts:
          - mountPath: "/data/redis-data/"
            name: redis-datadir
      volumes:
        - name: redis-datadir
          persistentVolumeClaim:
            claimName: redis-datadir-pvc-1

---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: devops-redis
  name: srv-devops-redis
  namespace: magedu
spec:
  type: NodePort
  ports:
  - name: http
    port: 6379
    targetPort: 6379
    nodePort: 31379
  selector:
    app: devops-redis
  sessionAffinity: ClientIP
  sessionAffinityConfig:
    clientIP:
      timeoutSeconds: 10800
root@easzlab-deploy:~/redis-cluster/redis-k8s#
root@easzlab-deploy:~/redis-cluster/redis-k8s# kubectl apply -f redis-k8s-deployment.yaml 
deployment.apps/deploy-devops-redis unchanged
service/srv-devops-redis created
root@easzlab-deploy:~/redis-cluster/redis-k8s# 

 

标签:easzlab,持久,deploy,redis,cluster,NFS,pod,k8s,root
From: https://www.cnblogs.com/cyh00001/p/16592073.html

相关文章

  • Kubernetes学习笔记(十四):Static Pods
    kubelet依赖于kube-apiserver来获得关于在其node上加载哪些pod的指令,这是基于存储在etcd数据库中的kube-scheduler所做的决定。kubelet也可以独立运行,可以创建pod,可以指定......
  • 定义pod的hosts文件(HostAliases)
    通过HostAliases向Pod/etc/hosts文件添加条目当DNS配置以及其它选项不合理的时候,通过向Pod的/etc/hosts文件中添加条目,可以在Pod级别覆盖对主机名的解析。......
  • 移植busybox 以及从nfs启动系统
    1.前言开发环境Ubuntuserver18.04,因为找到的资料使用的nand是64M的,而我手上的板子是256M,所以资料里的镜像bin文件不能直接用,会有个ecc的问题,因为他在64M的nand上用......
  • ios开发之--Cocoapods更新指定的库
    最近接手了一个swift的老项目,问题还不少,把bug修复完成功编译后,还没来得及高兴,发现一运行都崩溃,经排查是三方库太旧的原因,但是有些老版本的库又不能全部更新,所以只能更新指......
  • 哈希类型,列表类型,集合类型,有序集合类型,慢查询,pipline与事务,发布订阅,Bitmap,HyperLogLog
    1API的使用1.1哈希类型###1---hget,hset,hdelhgetkeyfield#获取hashkey对应的field的value时间复杂度为o(1)hsetkeyfieldvalue#设置hashkey对应的field......
  • k8s中ingress,service,depoyment,pod如何关联
    k8s中ingress,service,depoyment,pod通过label标签名称来识别关联,它们的label name一定是一样的。1、查询发布的deploymet控制器[root@k8s-master1~]#kubectlgetdeplo......
  • centos快速搭建nfs共享
    一、nfs服务器端01.安装nfs服务yum-yinstallnfs-utils02.创建存储目录mkdir-p/data/2haohr_backup03.设置共享配置#vim/etc/exports/data/2haohr_backup......
  • podman基础命令
    podman基础命令podmancp在容器和本地文件系统之间复制文件/文件夹//将本地文件传输到容器中[root@localhost~]#podmanps-aC0ONTAINERIDIMAGECOMMANDCREATE......
  • 无根用户管理podman
    无根用户管理podman目录无根用户管理podman基础设置用户配置文件卷使用卷在允许没有root特权的用户运行Podman之前,管理员必须安装或构建Podman并完成以下配......
  • podman(无根用户管理podman)
    用户操作在允许没有root特权的用户运行Podman之前,管理员必须安装或构建Podman并完成以下配置cgroupV2Linux内核功能允许用户限制普通用户容器可以使用的资源,如果使用cgrou......