k8s——持久化存储之nfs
准备所有k8s节点需要安装nfs服务一台nfs服务器提供存储根据需求创建数据挂载目录例如我的:创建PV// vi pv-nfs.yamlapiVersion: v1kind: PersistentVolumemetadata:name:web-pvlabels:app: web-pvspec:capacity:storage: 1...
·
准备
- 所有k8s节点需要安装nfs服务
- 一台nfs服务器提供存储
- 根据需求创建数据挂载目录
例如我的:
创建PV
// vi pv-nfs.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: web-pv
labels:
app: web-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /k8s-data/web
server: 192.168.50.190
kubectl apply -f pv-nfs.yaml
- 查看pv
kubectl get pv
创建PVC
// vi pvc-nfs.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: web-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
selector:
matchLabels:
app: web-pv
kubectl apply -f pvc-nfs.yaml
- 查看PVC
kubectl get pvc
使用PVC挂载
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
selector:
matchLabels:
app: web
replicas: 2
template:
metadata:
labels:
app: web
spec:
terminationGracePeriodSeconds: 3
containers:
- name: web
image: nginx
imagePullPolicy: Never
ports:
- containerPort: 80
name: web
volumeMounts:
- mountPath: /usr/share/nginx/html
name: index
volumes:
- name: index
persistentVolumeClaim:
claimName: web-pvc
- 创建service
apiVersion: v1
kind: Service
metadata:
name: web-svc
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
nodePort: 30991
selector:
app: web
把主页文件放到之前准本的nfs目录下,访问ip+30991即可
更多推荐
已为社区贡献10条内容
所有评论(0)