k8s持久化存储之NFS

    0

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

nfs-server

centos

bash
yum -y install nfs-utils rpcbind mkdir -p /data/nfs #创建共享目录 chmod 0755 /data/nfs。#分配权限 echo "/data/nfs 192.168.100.0/22(rw,no_root_squash,no_all_squash,sync)" >> /etc/exports exportfs -rv //使配置生效 systemctl enable rpcbind systemctl enable nfs-server
bash
#验证挂载 showmount -e localhost #Export list for localhost: #/data/nfs 192.168.100.0/22

debian

bash
sudo apt update sudo apt upgrade sudo apt install nfs-kernel-server

nfs-client

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

bash
yum -y install nfs-utils showmount -e 192.168.100.193 #Export list for 192.168.100.0: #/data/nfs 192.168.100.0/22

debian

bash
sudo apt update sudo apt upgrade sudo apt-get install -y nfs-common

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 -n kube-system nfs-client nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \ --set nfs.server=192.168.100.201 \ --set nfs.path=/data/nfs \ --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
评论区
共有评论 0
暂无评论