原POD中使用动态PV时,增加一个静态PV目录
方法:
创建PV、PVC后,在动态项目yaml中加上静态volumes部分即可
apiVersion: v1
kind: Service
metadata:
name: nginx1
labels:
app: nginx1
spec:
type: LoadBalancer
ports:
- port: 8888
targetPort: 80
nodePort: 30681
name: nginx1
selector:
app: nginx1
clusterIP: 10.10.214.147
clusterIPs:
- 10.10.214.147
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web1
spec:
selector:
matchLabels:
app: nginx1
serviceName: "nginx1"
replicas: 1
template:
metadata:
labels:
app: nginx1
spec:
imagePullSecrets:
- name: huoban-harbor
terminationGracePeriodSeconds: 10
containers:
- name: nginx1
image: nginx
ports:
- containerPort: 80
name: web1
volumeMounts:
- name: www1
mountPath: /data
- name: nginx-data-var-www
mountPath: /var/www
volumes:
- name: nginx-data-var-www
persistentVolumeClaim:
claimName: nginx-nfs-pvc-var-www
volumeClaimTemplates:
- metadata:
name: www1
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "managed-nfs-storage-guokao"
resources:
requests:
storage: 1Gi
增加部分为:
- name: nginx-data-var-www POD中增加的目录
mountPath: /var/www
volumes:
- name: nginx-data-var-www 静态PVC名
persistentVolumeClaim:
claimName: nginx-nfs-pvc-var-www
注:
PV 与PVC 一一对应
PVC可以同时被多个POD使用
-------------------end