k8s emptyDir-临时数据卷
作者:互联网
emptyDir-临时数据卷
1. emptyDir-临时数据卷
-
emptyDir卷:是一个临时存储卷,与Pod生命周期绑定一起,如果Pod删除了卷也会被删除。
-
应用场景:Pod中容器之间数据共享
-
示例:
apiVersion: v1 kind: Pod metadata: name: my-pod spec: containers: - name: write image: centos command: ["bash","-c","for i in {1..100};do echo $i >> /data/hello;sleep 1;done"] volumeMounts: - name: data mountPath: /data - name: read image: centos command: ["bash","-c","tail -f /data/hello"] volumeMounts: - name: data mountPath: /data volumes: - name: data emptyDir: {}
示例:Pod内容器之前共享数据
2. 案例
2.1 编写emptydir配置文件
[root@k8s-master yaml]# mkdir -p emptyDir
[root@k8s-master yaml]# cd emptyDir/
[root@k8s-master emptyDir]# ll
总用量 0
[root@k8s-master emptyDir]# vim emptydir.yaml
[root@k8s-master emptyDir]# cat emptydir.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: write
image: centos
command: ["bash","-c","for i in {1..100};do echo $i >> /data/hello;sleep 1;done"]
volumeMounts:
- name: data
mountPath: /data
- name: read
image: centos
command: ["bash","-c","tail -f /data/hello"]
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
emptyDir: {}
2.2 启动配置文件
[root@k8s-master emptyDir]# kubectl apply -f emptydir.yaml
pod/my-pod created
2.3 验证服务
[root@k8s-master emptyDir]# kubectl get pod
NAME READY STATUS RESTARTS AGE
configmap-demo-pod 1/1 Running 0 45h
my-pod 2/2 Running 3 10m
secret-demo-pod 1/1 Running 0 38h
2.4 进入服务验证数据
[root@k8s-master emptyDir]# kubectl exec -it my-pod -- /bin/bash
Defaulting container name to write.
Use 'kubectl describe pod/my-pod -n default' to see all of the containers in this pod.
[root@my-pod /]# ls -a /data/
. .. hello
[root@my-pod /]# cat /data/hello
1
2
3
4
5
6
7
8
标签:name,临时,root,emptyDir,pod,k8s,data 来源: https://www.cnblogs.com/scajy/p/15661554.html