1. 11.1 Kubernetes Volume
在Docker的相关章节,我们讲解了Docker Volume,可以挂载一个目录到Docker容器中,在Kubernetes中也有Volume的组建,Volume不是单独存在的,你不能单独创建一个Volume的资源对象,需要 在Pod中进行定义,Volume的生命周期和Pod一样,但是比Pod里面的容易要长。
1.1. emptyDir卷
[root@linux-node1 ~]# cat nginx-volume-empty.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.13.12
ports:
- containerPort: 80
volumeMounts:
- mountPath: /cache
name: cache-volume
volumes:
- name: cache-volume
emptyDir: {}
1.2. HostPath卷
[root@linux-node1 ~]# cat nginx-volume-hostpath.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.13.12
ports:
- containerPort: 80
volumeMounts:
- mountPath: /cache
name: log-volume
volumes:
- name: log-volume
hostPath:
path: /opt
type: Directory