一、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