数据持久化需要数据卷。kubernetes生态提供海量的存储驱动和存储使用方式。
[root@master song]# cat pod-demo.yml apiVersion: v1kind: Podmetadata: name: pod-demo namespace: default labels: app: myapp tier: frontend 2sdlfj: dashazispec: containers: - name: centos image: busybox command: ["/bin/sh","-c","ping www.baidu.com"] volumeMounts: - name: song mountPath: /data - name: myapp-1 image: hub.c.163.com/library/nginx:1.13 volumeMounts: - name: song mountPath: /data nodeSelector: location: slave1 volumes: - name: song emptyDir: {} 查看状态
[root@master song]# kubectl describe pod pod-demo
Name: pod-demoNamespace: defaultPriority: 0PriorityClassName: <none>Node: k8s-node1/172.20.0.76Start Time: Sun, 03 Mar 2019 09:41:53 +0800Labels: 2sdlfj=dashazi app=myapp tier=frontendAnnotations: kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"2sdlfj":"dashazi","app":"myapp","tier":"frontend"},"name":"pod-dem...Status: RunningIP: 10.244.2.183Containers: centos: Container ID: docker://4bc862140523df128ab1c35375459f5a08cbab3bbeb787b35ae607016bb18071 Image: busybox Image ID: docker-pullable://busybox@sha256:061ca9704a714ee3e8b80523ec720c64f6209ad3f97c0ff7cb9ec7d19f15149f Port: <none> Host Port: <none> Command: /bin/sh -c ping www.baidu.com State: Running Started: Sun, 03 Mar 2019 09:42:01 +0800 Ready: True Restart Count: 0 Environment: <none> Mounts: /data from song (rw) /var/run/secrets/kubernetes.io/serviceaccount from default-token-tlx48 (ro) myapp-1: Container ID: docker://b32921dc906b58bfdf146e9a094748d7af80d21e24b58c17f6ffdc08fdee1752 Image: hub.c.163.com/library/nginx:1.13 Image ID: docker-pullable://hub.c.163.com/library/nginx@sha256:ff094de32a0d3b5efc29cec60daa709c5378cf4e53e4c9fd1d3433b87ac8ec8b Port: <none> Host Port: <none> State: Running Started: Sun, 03 Mar 2019 09:42:01 +0800 Ready: True Restart Count: 0 Environment: <none> Mounts: /data from song (rw) /var/run/secrets/kubernetes.io/serviceaccount from default-token-tlx48 (ro)Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: song: Type: EmptyDir (a temporary directory that shares a pod's lifetime) 说明该类型为临时文件,不会存盘。 Medium: default-token-tlx48: Type: Secret (a volume populated by a Secret) SecretName: default-token-tlx48 Optional: falseQoS Class: BestEffortNode-Selectors: location=slave1Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s node.kubernetes.io/unreachable:NoExecute for 300sEvents: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Pulling 7h9m kubelet, k8s-node1 pulling image "busybox" Normal Pulled 7h9m kubelet, k8s-node1 Successfully pulled image "busybox" Normal Created 7h9m kubelet, k8s-node1 Created container Normal Started 7h9m kubelet, k8s-node1 Started container Normal Pulled 7h9m kubelet, k8s-node1 Container image "hub.c.163.com/library/nginx:1.13" already present on machine Normal Created 7h9m kubelet, k8s-node1 Created container Normal Started 7h9m kubelet, k8s-node1 Started container Normal Scheduled 71s default-scheduler Successfully assigned default/pod-demo to k8s-node1[root@master song]# kubectl exec -i -t pod-demo -c centos -- /bin/sh/ # cd /data/data # cat /proc/mountsrootfs / rootfs rw 0 0overlay / overlay rw,relatime,lowerdir=/var/lib/docker/overlay2/l/XHB5NUDL4LLGOC3EZHZJ6C2U2R:/var/lib/docker/overlay2/l/Q2CWFPROIF2I4BB6RJY5CAM74J,upperdir=/var/lib/docker/overlay2/bae727cbe291547d5703c4d488afee8b1394e2abd8bb9a271ac73bfff2468365/diff,workdir=/var/lib/docker/overlay2/bae727cbe291547d5703c4d488afee8b1394e2abd8bb9a271ac73bfff2468365/work 0 0proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0tmpfs /dev tmpfs rw,nosuid,size=65536k,mode=755 0 0devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666 0 0sysfs /sys sysfs ro,nosuid,nodev,noexec,relatime 0 0tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,relatime,mode=755 0 0cgroup /sys/fs/cgroup/systemd cgroup ro,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0cgroup /sys/fs/cgroup/cpu,cpuacct cgroup ro,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0cgroup /sys/fs/cgroup/pids cgroup ro,nosuid,nodev,noexec,relatime,pids 0 0cgroup /sys/fs/cgroup/hugetlb cgroup ro,nosuid,nodev,noexec,relatime,hugetlb 0 0cgroup /sys/fs/cgroup/freezer cgroup ro,nosuid,nodev,noexec,relatime,freezer 0 0cgroup /sys/fs/cgroup/cpuset cgroup ro,nosuid,nodev,noexec,relatime,cpuset 0 0cgroup /sys/fs/cgroup/blkio cgroup ro,nosuid,nodev,noexec,relatime,blkio 0 0cgroup /sys/fs/cgroup/net_cls,net_prio cgroup ro,nosuid,nodev,noexec,relatime,net_prio,net_cls 0 0cgroup /sys/fs/cgroup/devices cgroup ro,nosuid,nodev,noexec,relatime,devices 0 0cgroup /sys/fs/cgroup/perf_event cgroup ro,nosuid,nodev,noexec,relatime,perf_event 0 0cgroup /sys/fs/cgroup/memory cgroup ro,nosuid,nodev,noexec,relatime,memory 0 0mqueue /dev/mqueue mqueue rw,nosuid,nodev,noexec,relatime 0 0/dev/mapper/centos_bogon-root /data ext4 rw,relatime,data=ordered 0 0/dev/mapper/centos_bogon-root /dev/termination-log ext4 rw,relatime,data=ordered 0 0/dev/mapper/centos_bogon-root /etc/resolv.conf ext4 rw,relatime,data=ordered 0 0/dev/mapper/centos_bogon-root /etc/hostname ext4 rw,relatime,data=ordered 0 0/dev/mapper/centos_bogon-root /etc/hosts ext4 rw,relatime,data=ordered 0 0shm /dev/shm tmpfs rw,nosuid,nodev,noexec,relatime,size=65536k 0 0tmpfs /var/run/secrets/kubernetes.io/serviceaccount tmpfs ro,relatime 0 0proc /proc/bus proc ro,relatime 0 0proc /proc/fs proc ro,relatime 0 0proc /proc/irq proc ro,relatime 0 0proc /proc/sys proc ro,relatime 0 0proc /proc/sysrq-trigger proc ro,relatime 0 0tmpfs /proc/acpi tmpfs ro,relatime 0 0tmpfs /proc/kcore tmpfs rw,nosuid,size=65536k,mode=755 0 0tmpfs /proc/keys tmpfs rw,nosuid,size=65536k,mode=755 0 0tmpfs /proc/timer_list tmpfs rw,nosuid,size=65536k,mode=755 0 0tmpfs /proc/timer_stats tmpfs rw,nosuid,size=65536k,mode=755 0 0tmpfs /proc/sched_debug tmpfs rw,nosuid,size=65536k,mode=755 0 0tmpfs /proc/scsi tmpfs ro,relatime 0 0tmpfs /sys/firmware tmpfs ro,relatime 0 0/data # df -hFilesystem Size Used Available Use% Mounted onoverlay 9.7G 4.6G 4.6G 50% /tmpfs 64.0M 0 64.0M 0% /devtmpfs 999.5M 0 999.5M 0% /sys/fs/cgroup/dev/mapper/centos_bogon-root 9.7G 4.6G 4.6G 50% /data/dev/mapper/centos_bogon-root 9.7G 4.6G 4.6G 50% /dev/termination-log/dev/mapper/centos_bogon-root 9.7G 4.6G 4.6G 50% /etc/resolv.conf/dev/mapper/centos_bogon-root 9.7G 4.6G 4.6G 50% /etc/hostname/dev/mapper/centos_bogon-root 9.7G 4.6G 4.6G 50% /etc/hostsshm 64.0M 0 64.0M 0% /dev/shmtmpfs 999.5M 12.0K 999.5M 0% /var/run/secrets/kubernetes.io/serviceaccounttmpfs 999.5M 0 999.5M 0% /proc/acpitmpfs 64.0M 0 64.0M 0% /proc/kcoretmpfs 64.0M 0 64.0M 0% /proc/keystmpfs 64.0M 0 64.0M 0% /proc/timer_listtmpfs 64.0M 0 64.0M 0% /proc/timer_statstmpfs 64.0M 0 64.0M 0% /proc/sched_debugtmpfs 999.5M 0 999.5M 0% /proc/scsitmpfs 999.5M 0 999.5M 0% /sys/firmware