CKA test preparation lab | emptyDir

Book source: "CKA/CKAD Test Guide: From Docker to Kubernetes Complete Raiders"

Organize the teacher's course content and experimental notes while studying, and share them with everyone. Any infringement will be deleted. Thank you for your support!

Attach a summary post: CKA test preparation experiment |


The storage method of using emptyDir is similar to the command docker run -v /xx when creating a docker container, which means to randomly generate a directory in the physical machine (this directory is actually mounted on the memory of the physical machine), and then put this The directory is mounted to the /xx directory of the container. If the xx directory does not exist, it will be automatically created in the container, but when the pod is deleted, the directory corresponding to emptyDir will be deleted together, because this storage is temporary and uses memory as the medium, not permanent.

In order to distinguish it from pods created in other chapters, all experiments in this chapter operate in a new command space.

Step 1: Create a namespace nsvolume and switch to this namespace.

##########实操验证##########
[root@vms10 ~]# kubectl create ns nsvolume
namespace/nsvolume created
[root@vms10 ~]# 
[root@vms10 ~]# kubens nsvolume
Context "kubernetes-admin@kubernetes" modified.
Active namespace is "nsvolume".
[root@vms10 ~]# 

All the files involved in this chapter are placed in a directory volume.

Step 2: Create a directory volume and cd into it.

##########实操验证##########
[root@vms10 ~]# mkdir volume ; cd volume/
[root@vms10 volume]# 

Step 3: Create a pod yaml file emp.yaml, and modify it as follows.

##########实操验证##########
[root@vms10 volume]# cat emp.yaml 
apiVersion: v1
kind: Pod 
metadata:
  name: demo 
  labels:
    aa: aa 
spec:
  volumes: 
  - name: volume1 
    emptyDir: {}
  - name: volume2
    emptyDir: {}
  containers:
  - name: demo1
    image: busybox 
    imagePullPolicy: IfNotPresent 
    command: ['sh', '-c', 'sleep 5000']
    volumeMounts:
    - mountPath: /xx 
      name: volume1
  - name: demo2
    image: busybox
    imagePullPolicy: IfNotPresent 
    command: ['sh', '-c', 'sleep 5000']
    volumeMounts:
    - mountPath: /xx 
      name: volume1
[root@vms10 volume]# 

In this yaml file, volumes are created under the volumes field. Here, two volumes named volume1 and volume2 are created, both of type emptyDir. Two containers demo1 and demo2 are created in this pod. In each container, the volume is mounted through the volumeMounts option, where name specifies which volume to mount, and mountPath specifies the mount point of the volume in this container, where both containers mount volume1 to the /xx of the container directory.

Note: If the directory /xx in the container does not exist, it will be created automatically.

Step 4: Create a pod and check the running status of the pod.

##########实操验证##########
[root@vms10 volume]# kubectl apply -f emp.yaml 
pod/demo created
[root@vms10 volume]# kubectl get pods
NAME   READY   STATUS    RESTARTS   AGE
demo   2/2     Running   0          5s
[root@vms10 volume]# 

Step 5: View the description information of this pod.

##########实操验证##########
[root@vms10 volume]# kubectl describe pod demo | grep -A2 Volumes
Volumes:
  volume1:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
[root@vms10 volume]# 

You can see that this pod is now using the emptyDir type of storage.

Step 6: Check which host the pod is running on.

##########实操验证##########
[root@vms10 volume]# kubectl get pods -o wide --no-headers
demo   2/2   Running   0     74s   10.244.14.21   vms12.rhce.cc   <none>   <none>
[root@vms10 volume]# 

Step 7: Switch to the vms12 machine and find the corresponding container.

##########实操验证##########
[root@vms12 ~]# docker ps | grep demo
eb0b3c97308c   7cfbbec8963d                                        "sh -c 'sleep 5000'"     About a minute ago   Up About a minute             k8s_demo2_demo_nsvolume_f690d17c-478d-4f58-bd3e-6249b33d902a_0
c27ff5aafcdf   7cfbbec8963d                                        "sh -c 'sleep 5000'"     About a minute ago   Up About a minute             k8s_demo1_demo_nsvolume_f690d17c-478d-4f58-bd3e-6249b33d902a_0
358fa6a3bf58   registry.aliyuncs.com/google_containers/pause:3.2   "/pause"                 About a minute ago   Up About a minute             k8s_POD_demo_nsvolume_f690d17c-478d-4f58-bd3e-6249b33d902a_0
[root@vms12 ~]# 

You can see that the IDs of the two containers corresponding to the demo pod created on the master are d3150d1c569e and 5e9c9e41b8ea respectively.

Step 8: View their corresponding properties.

##########实操验证##########
[root@vms12 ~]# docker inspect eb0b3c97308c
[
    {
        "Id": "eb0b3c97308c3f6d5fc44359ddaa37b53b0d8c2fd958c2798a0554ddbdccd760",
        "Created": "2023-05-30T05:36:01.59596029Z",
        "Path": "sh",
        "Args": [
            "-c",
            "sleep 5000"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 66772,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2023-05-30T05:36:01.705496703Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:7cfbbec8963d8f13e6c70416d6592e1cc10f47a348131290a55d43c3acab3fb9",
        "ResolvConfPath": "/var/lib/docker/containers/358fa6a3bf58c602edf1da39ecf34881c419b660965f682f37c241acaf50ca4a/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/358fa6a3bf58c602edf1da39ecf34881c419b660965f682f37c241acaf50ca4a/hostname",
        "HostsPath": "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/etc-hosts",
        "LogPath": "/var/lib/docker/containers/eb0b3c97308c3f6d5fc44359ddaa37b53b0d8c2fd958c2798a0554ddbdccd760/eb0b3c97308c3f6d5fc44359ddaa37b53b0d8c2fd958c2798a0554ddbdccd760-json.log",
        "Name": "/k8s_demo2_demo_nsvolume_f690d17c-478d-4f58-bd3e-6249b33d902a_0",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/volumes/kubernetes.io~empty-dir/volume1:/xx",
                "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/volumes/kubernetes.io~projected/kube-api-access-v5wg9:/var/run/secrets/kubernetes.io/serviceaccount:ro",
                "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/etc-hosts:/etc/hosts",
                "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/containers/demo2/d28c536b:/dev/termination-log"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "container:358fa6a3bf58c602edf1da39ecf34881c419b660965f682f37c241acaf50ca4a",
            "PortBindings": null,
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                0,
                0
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "container:358fa6a3bf58c602edf1da39ecf34881c419b660965f682f37c241acaf50ca4a",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 1000,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": [
                "seccomp=unconfined"
            ],
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 2,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "/kubepods/besteffort/podf690d17c-478d-4f58-bd3e-6249b33d902a",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 100000,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/asound",
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/0f2e3d42b44b959c962e01990c93e92a333f2e101d9bfc5305b43f559e96e239-init/diff:/var/lib/docker/overlay2/e151f4c9750ff81b23bc4ee275c22f1664d4fc7974265b9ac8a8b440f0bc5e31/diff",
                "MergedDir": "/var/lib/docker/overlay2/0f2e3d42b44b959c962e01990c93e92a333f2e101d9bfc5305b43f559e96e239/merged",
                "UpperDir": "/var/lib/docker/overlay2/0f2e3d42b44b959c962e01990c93e92a333f2e101d9bfc5305b43f559e96e239/diff",
                "WorkDir": "/var/lib/docker/overlay2/0f2e3d42b44b959c962e01990c93e92a333f2e101d9bfc5305b43f559e96e239/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/volumes/kubernetes.io~empty-dir/volume1",
                "Destination": "/xx",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/volumes/kubernetes.io~projected/kube-api-access-v5wg9",
                "Destination": "/var/run/secrets/kubernetes.io/serviceaccount",
                "Mode": "ro",
                "RW": false,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/etc-hosts",
                "Destination": "/etc/hosts",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/containers/demo2/d28c536b",
                "Destination": "/dev/termination-log",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "demo",
            "Domainname": "",
            "User": "0",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "KUBERNETES_SERVICE_PORT_HTTPS=443",
                "KUBERNETES_PORT=tcp://10.96.0.1:443",
                "KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443",
                "KUBERNETES_PORT_443_TCP_PROTO=tcp",
                "KUBERNETES_PORT_443_TCP_PORT=443",
                "KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1",
                "KUBERNETES_SERVICE_HOST=10.96.0.1",
                "KUBERNETES_SERVICE_PORT=443",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": null,
            "Healthcheck": {
                "Test": [
                    "NONE"
                ]
            },
            "Image": "sha256:7cfbbec8963d8f13e6c70416d6592e1cc10f47a348131290a55d43c3acab3fb9",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "sh",
                "-c",
                "sleep 5000"
            ],
            "OnBuild": null,
            "Labels": {
                "annotation.io.kubernetes.container.hash": "56690cd4",
                "annotation.io.kubernetes.container.restartCount": "0",
                "annotation.io.kubernetes.container.terminationMessagePath": "/dev/termination-log",
                "annotation.io.kubernetes.container.terminationMessagePolicy": "File",
                "annotation.io.kubernetes.pod.terminationGracePeriod": "30",
                "io.kubernetes.container.logpath": "/var/log/pods/nsvolume_demo_f690d17c-478d-4f58-bd3e-6249b33d902a/demo2/0.log",
                "io.kubernetes.container.name": "demo2",
                "io.kubernetes.docker.type": "container",
                "io.kubernetes.pod.name": "demo",
                "io.kubernetes.pod.namespace": "nsvolume",
                "io.kubernetes.pod.uid": "f690d17c-478d-4f58-bd3e-6249b33d902a",
                "io.kubernetes.sandbox.id": "358fa6a3bf58c602edf1da39ecf34881c419b660965f682f37c241acaf50ca4a"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {}
        }
    }
]
[root@vms12 ~]# docker inspect c27ff5aafcdf
[
    {
        "Id": "c27ff5aafcdfe8200f000738cbc34a817a3ab964dc25774757e5d24c28e24c6c",
        "Created": "2023-05-30T05:36:01.483534386Z",
        "Path": "sh",
        "Args": [
            "-c",
            "sleep 5000"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 66732,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2023-05-30T05:36:01.586033581Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:7cfbbec8963d8f13e6c70416d6592e1cc10f47a348131290a55d43c3acab3fb9",
        "ResolvConfPath": "/var/lib/docker/containers/358fa6a3bf58c602edf1da39ecf34881c419b660965f682f37c241acaf50ca4a/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/358fa6a3bf58c602edf1da39ecf34881c419b660965f682f37c241acaf50ca4a/hostname",
        "HostsPath": "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/etc-hosts",
        "LogPath": "/var/lib/docker/containers/c27ff5aafcdfe8200f000738cbc34a817a3ab964dc25774757e5d24c28e24c6c/c27ff5aafcdfe8200f000738cbc34a817a3ab964dc25774757e5d24c28e24c6c-json.log",
        "Name": "/k8s_demo1_demo_nsvolume_f690d17c-478d-4f58-bd3e-6249b33d902a_0",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/volumes/kubernetes.io~empty-dir/volume1:/xx",
                "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/volumes/kubernetes.io~projected/kube-api-access-v5wg9:/var/run/secrets/kubernetes.io/serviceaccount:ro",
                "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/etc-hosts:/etc/hosts",
                "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/containers/demo1/6766f47e:/dev/termination-log"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "container:358fa6a3bf58c602edf1da39ecf34881c419b660965f682f37c241acaf50ca4a",
            "PortBindings": null,
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                0,
                0
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "container:358fa6a3bf58c602edf1da39ecf34881c419b660965f682f37c241acaf50ca4a",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 1000,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": [
                "seccomp=unconfined"
            ],
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 2,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "/kubepods/besteffort/podf690d17c-478d-4f58-bd3e-6249b33d902a",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 100000,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/asound",
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/7cb2130d3bb712dc53ce9e4262c86772bdaa710ffc965125b482a33d62b4be20-init/diff:/var/lib/docker/overlay2/e151f4c9750ff81b23bc4ee275c22f1664d4fc7974265b9ac8a8b440f0bc5e31/diff",
                "MergedDir": "/var/lib/docker/overlay2/7cb2130d3bb712dc53ce9e4262c86772bdaa710ffc965125b482a33d62b4be20/merged",
                "UpperDir": "/var/lib/docker/overlay2/7cb2130d3bb712dc53ce9e4262c86772bdaa710ffc965125b482a33d62b4be20/diff",
                "WorkDir": "/var/lib/docker/overlay2/7cb2130d3bb712dc53ce9e4262c86772bdaa710ffc965125b482a33d62b4be20/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/volumes/kubernetes.io~empty-dir/volume1",
                "Destination": "/xx",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/volumes/kubernetes.io~projected/kube-api-access-v5wg9",
                "Destination": "/var/run/secrets/kubernetes.io/serviceaccount",
                "Mode": "ro",
                "RW": false,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/etc-hosts",
                "Destination": "/etc/hosts",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/containers/demo1/6766f47e",
                "Destination": "/dev/termination-log",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "demo",
            "Domainname": "",
            "User": "0",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "KUBERNETES_PORT_443_TCP_PORT=443",
                "KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1",
                "KUBERNETES_SERVICE_HOST=10.96.0.1",
                "KUBERNETES_SERVICE_PORT=443",
                "KUBERNETES_SERVICE_PORT_HTTPS=443",
                "KUBERNETES_PORT=tcp://10.96.0.1:443",
                "KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443",
                "KUBERNETES_PORT_443_TCP_PROTO=tcp",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": null,
            "Healthcheck": {
                "Test": [
                    "NONE"
                ]
            },
            "Image": "sha256:7cfbbec8963d8f13e6c70416d6592e1cc10f47a348131290a55d43c3acab3fb9",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "sh",
                "-c",
                "sleep 5000"
            ],
            "OnBuild": null,
            "Labels": {
                "annotation.io.kubernetes.container.hash": "60b2be1e",
                "annotation.io.kubernetes.container.restartCount": "0",
                "annotation.io.kubernetes.container.terminationMessagePath": "/dev/termination-log",
                "annotation.io.kubernetes.container.terminationMessagePolicy": "File",
                "annotation.io.kubernetes.pod.terminationGracePeriod": "30",
                "io.kubernetes.container.logpath": "/var/log/pods/nsvolume_demo_f690d17c-478d-4f58-bd3e-6249b33d902a/demo1/0.log",
                "io.kubernetes.container.name": "demo1",
                "io.kubernetes.docker.type": "container",
                "io.kubernetes.pod.name": "demo",
                "io.kubernetes.pod.namespace": "nsvolume",
                "io.kubernetes.pod.uid": "f690d17c-478d-4f58-bd3e-6249b33d902a",
                "io.kubernetes.sandbox.id": "358fa6a3bf58c602edf1da39ecf34881c419b660965f682f37c241acaf50ca4a"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {}
        }
    }
]
[root@vms12 ~]# 

You can see that there are /xx in both containers, and they both correspond to the same physical directory /var/lib/kubelet/pods/7549132-ae81-11e9-8865-000c294d4f7c/volumes/kubernetes.io~empty-dir/volume1 inside.

Step 9: Copy a random file on the master to the /xx directory of container demo1 in this pod.

##########实操验证##########
[root@vms10 volume]# kubectl cp /etc/hosts demo:/xx -c demo1
[root@vms10 volume]# 

Step 10: View the /xx directory of container demo2 in the demo pod.

##########实操验证##########
[root@vms10 volume]# kubectl exec demo -c demo2 -- ls /xx
hosts
[root@vms10 volume]# 

It can be seen that there is also data here, because the same volume mounted by both demo1 and demo2 realizes data sharing.

Step 11: Switch to vms12.

##########实操验证##########
[root@vms12 ~]# ls /var/lib/kubelet/pods/f690d17c-478d-4f58-bd3e-6249b33d902a/volumes/kubernetes.io~empty-dir/volume1
hosts
[root@vms12 ~]# 

You can see that there is a hosts file.

Step 12: Delete this pod.

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/131449003