Volumes: 将磁盘存储连接到容器
- 0 资源类型 Node, Pod, Container, ReplicationController, ReplicaSet, DaemonSet, Job, CronJob, Services, Endpoints,Ingress, PersistentVolume, PersistentVolumeClaim,StorageClass
- 1 Volumes的生命周期像pod的一样,只是Volumes中的文件可能在pod和Volumes被移除之后保留下来。Volumes是pod的组成部分。
- 2 Volumes的类型:emptyDir, hostPath, gitRepo, nfs, gcePersistDisk, awsElasticBlockStore, azureDisk, cinder, cephfs, iscsi, flocker, glusterfs, quobyte, rbd, flexVolume, vsphereVolume, photoPersistentDisk, scaleIO, configMap, secret, downwardAPI, persistentVolumeClaim
- 3 端口转发 kubectl port-forward fortune 8080:80 注意监听的是localhost:8080,不是0.0.0.0:8080
- 4 hostPath 访问node的文件
- 5 persistentVolume ReclaimPolicy策略类型:Retain,Delete,Recycle。
- 6 动态配置 StorageClass
Review
- 声明volumns,然后在每个container到模板中挂在卷。
apiVersion: v1
kind: Pod
metadata:
name: fortune
spec:
containers:
- image: myorange/fortune
name: html-generator
volumeMounts:
- name: html
mountPath: /var/htdocs
- image: nginx:alpine
name: web-server
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
readOnly: true
ports:
- containerPort: 80
protocol: TCP
volumes:
- name: html
emptyDir: {}
- 如上yaml文件。因为emptyDir存在于内存中,所以易失。
- 将git仓库中的文件添加到卷。
volumes:
- name: html
gitRepo:
repository: https://github.com/luksa/kubia-website-example.git
revision: master
directory: .
- 创建一个hostpath类型的持久化卷PV
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongodb-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
- ReadOnlyMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /tmp/mongodb
- 挂在外部存储就是挂在NFS等类型的PV,需要指明服务地址和导出的path。
volumes:
- name: mongodb-data
nfs:
server: 1.2.3.4
path: /some/path
- 解耦pod和存储设施。需要学会创建PV和PVC。然后在pod中挂在pvc,而不是直接挂pv了。
volumes:
- name: mongodb-data
persistentVolumeClaim:
claimName: mongodb-pvc