k8s存储卷与数据持久化(3)
时间:2020-09-23 15:52 来源:未知 作者:liangzh 点击:次
[root@zfb-jyhpt-bgcsjyh1 k8s]# cat vol-emptydir.yaml
apiVersion: v1
kind: Pod
metadata:
name: vol-emptydir-pod
spec:
volumes:
- name: html
emptyDir: {}
containers:
- name: nginx
image: nginx
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
- name: pagegen
image: alpine
volumeMounts:
- name: html
mountPath: /html
command: ["/bin/sh","-c"]
args:
- while true; do
echo $(hostname) $(date)>/html/index.html;
sleep 10;
done
[root@zfb-jyhpt-bgcsjyh1 k8s]# kubectl get pod vol-emptydir-pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
vol-emptydir-pod 2/2 Running 0 2m51s 10.244.4.6 172.19.33.2 <none> <none>
查看nginx
[root@zfb-jyhpt-bgcsjyh1 k8s]# kubectl logs -f vol-emptydir-pod nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
访问测试:
[root@zfb-jyhpt-bgcsjyh1 k8s]# curl 10.244.4.7
vol-emptydir-pod Wed Sep 23 15:06:12 UTC 2020
vol-emptydir-pod Wed Sep 23 15:06:22 UTC 2020
vol-emptydir-pod Wed Sep 23 15:06:32 UTC 2020
进入pagegen容器可以看到/html下的index.html文件正在追加内容:
[root@zfb-jyhpt-bgsygc1 ~]# docker exec -it ce783e87b94a /bin/sh
/ # lsbin dev etc home html lib media mnt opt proc root run sbin srv sys tmp usr var
/ # ls html/index.html
/ # df -hFilesystem Size Used Available Use% Mounted on
overlay 50.0G 6.2G 43.8G 12% /tmpfs 64.0M 0 64.0M 0% /dev
tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup/dev/mapper/centos-root
50.0G 6.2G 43.8G 12% /html
# tail -f /html/index.html
vol-emptydir-pod Wed Sep 23 15:12:22 UTC 2020
vol-emptydir-pod Wed Sep 23 15:12:32 UTC 2020
vol-emptydir-pod Wed Sep 23 15:12:42 UTC 2020
vol-emptydir-pod Wed Sep 23 15:12:52 UTC 2020
vol-emptydir-pod Wed Sep 23 15:13:02 UTC 2020
vol-emptydir-pod Wed Sep 23 15:13:12 UTC 2020
vol-emptydir-pod Wed Sep 23 15:13:22 UTC 2020
作为边车( sidecar )的 容器 paggen ,其每隔 10s钟将一行信息追加到存储卷上的
index.html 文件中,因此,通过主容器 nginx 的应用访问到的内容也会处于不停的变动中
外,emptyDir 储卷也可以基于 RAM 创建 tmpfs 件系统的存储卷,常用于为容器的应 (责任编辑:liangzh) |