kubectl-NFS
- 在生产环境中经常需要多个Pod中共享数据,而这些应用又在不同的机器的不同Pod中,NFS可以来解决这个问题。
- Kubernetes中通过简单的配置就可以挂载NFS到Pod中,而NFS中的数据是可以永久保存的,同时NFS支持并发写操作。
-
搭建NFS服务器
具体操作可见👉NFS服务器
-
创建PV/PVC资源
具体操作见👉PV/PVC
-
使用nfs-pvc
--- apiVersion: apps/v1 kind: Deployment metadata: name: webnginx-deployment annotations: kubernetes.io/change-cause: webnginx.v1 spec: replicas: 1 selector: matchLabels: app: web-nginx template: metadata: labels: app: web-nginx spec: volumes: - name: website #设置共享卷名称 persistentVolumeClaim: #卷类型为PVC claimName: pvc-nfs #PVC名称 containers: - name: nginx image: hub.godone.top/pub/nginx:v1 imagePullPolicy: IfNotPresent volumeMounts: #使用存储卷 - name: website #选择存储卷 mountPath: /usr/share/nginx/html #映射到容器内的路径 ports: - containerPort: 80