参考: https://kubernetes.io/docs/concepts/storage/volumes/
1.emptyDir
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: gcr.io/google_containers/test-webserver
name: test-container
volumeMounts:
- mountPath: /cache
name: cache-volume
volumes:
- name: cache-volume
emptyDir: {}
2.hostPath
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: gcr.io/google_containers/test-webserver
name: test-container
volumeMounts:
- mountPath: /test-pd
name: test-volume
volumes:
- name: test-volume
hostPath:
# directory location on host
path: /data
3.pod持久存储
- 方式1: pod直接挂载nfs-server
volumes:
- name: nfs
nfs:
server: 192.168.1.1
path:"/"
静态提供:管理员手动创建多个PV,供PVC使用。
动态提供:动态创建PVC特定的PV,并绑定。
- 方式2: 手动创建pv
pv.yaml
apiVersion: v1
kind: PersistentVolume