k8s持久化存储之NFS

    0

首先在集群之外安装服务端

nfs-server

bash
apt update apt upgrade apt install nfs-kernel-server mkdir -p /srv/nfs/share #创建共享目录 chmod 777 /srv/nfs/share #分配权限 echo "/srv/nfs/share 192.168.100.0/24(rw,no_root_squash,no_all_squash,sync,no_subtree_check)" >> /etc/exports exportfs -rv //使配置生效 #验证挂载 showmount -e localhost #Export list for localhost: #/srv/nfs/share 192.168.100.0/22

nfs-client

所有节点安装nfs客户端!!⚠️

bash
apt update apt upgrade apt-get install -y nfs-common showmount -e 192.168.100.193 #Export list for 192.168.100.0: #/srv/nfs/share 192.168.100.0/22

K8S

直接使用

yaml
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80 volumeMounts: - name: data mountPath: /usr/share/nginx/html volumes: - name: data nfs: path: /data/nfs server: 192.168.100.201

helm

安装

bash
helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/ helm install nfs-client nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \ --set nfs.server=192.168.100.164 \ --set nfs.path=/srv/nfs/share \ --set storageClass.defaultClass=true kubectl get sc

PVC

以bark-server为例

yaml
kind: Service apiVersion: v1 metadata: name: bark-server spec: selector: app: bark-server type: NodePort ports: - name: http port: 8080 targetPort: 8080 nodePort: 30002 --- apiVersion: apps/v1 kind: Deployment metadata: name: bark-server spec: replicas: 1 selector: matchLabels: app: bark-server template: metadata: labels: app: bark-server spec: containers: - name: bark-server image: finab/bark-server resources: limits: memory: "128Mi" cpu: "500m" ports: - containerPort: 8080 volumeMounts: - mountPath: /data name: bark-server volumes: - name: bark-server persistentVolumeClaim: claimName: bark-server #--- #apiVersion: v1 #kind: PersistentVolume #metadata: # name: bark-server #spec: # capacity: # storage: 200G # accessModes: # - ReadWriteMany # storageClassName: nfs-client # nfs: # server: 192.168.100.193 # path: /home/test --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: bark-server spec: accessModes: ["ReadWriteOnce"] storageClassName: nfs-client resources: requests: storage: 2Gi

csi-driver-nfs

附录

评论区

共有评论 0

暂无评论