[root@hdss7-200 volume]# vim /data/k8s-yaml/base_resource/volume/emptydir.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-emptydir
namespace: app
labels:
tier: volume
role: empty-dir
spec:
containers:
- name: main-container
image: harbor.od.com/public/busybox:v1.31.1
volumeMounts:
- name: web-root
mountPath: /tmp
command:
- httpd
args:
- -f
- -h
- "/tmp/"
- name: sidecar-container
image: harbor.od.com/public/centos:7
volumeMounts:
- name: web-root
mountPath: /tmp
command:
- /bin/bash
args:
- -c
- "while :;do date +'%F %T' > /tmp/index.html;sleep 1;done"
volumes:
- name: web-root
emptyDir: {}
[root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/base_resource/volume/emptydir.yaml
[root@hdss7-21 ~]# kubectl get pod pod-emptydir -n app -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod-emptydir 2/2 Running 0 71s 172.7.22.11 hdss7-22.host.com <none> <none>
[root@hdss7-21 ~]# kubectl describe pod pod-emptydir -n app
Name: pod-emptydir
Namespace: app
...
Containers:
main-container:
...
Mounts:
/tmp from web-root (rw)
...
sidecar-container:
...
Mounts:
/tmp from web-root (rw)
...
Volumes:
web-root:
Type: EmptyDir (a temporary directory that shares a pod's lifetime)
Medium:
SizeLimit: <unset>
[root@hdss7-21 ~]# while :;do curl -s 172.7.22.11;sleep 1;done
2020-01-26 12:31:09
2020-01-26 12:31:10
2020-01-26 12:31:11
2020-01-26 12:31:12