“ 对POD进行深度认识,让我们再次进入pod的世界。”

POD回顾
1、POD是最小调度单位2、POD本质上还是容器的隔离3、Pause容器
POD之Volume
[root@node1 ~]# cd namespace/[root@node1 namespace]# mkdir pod[root@node1 namespace]# cd pod[root@node1 pod]#[root@node1 pod]# vim pod-volume.yamlapiVersion: v1kind: Podmetadata:name: pod-volumespec:containers:- name: webimage: registry.cn-beijing.aliyuncs.com/yunweijia0909/springboot-web:v1ports:- containerPort: 8080volumeMounts:- name: shared-volumemountPath: shared-web- name: redisenv:- name: REDIS_PORTvalue: "6379"image: redisvolumeMounts:- name: shared-volumemountPath: shared-redisvolumes:- name: shared-volumehostPath:path: shared-volume-data[root@node1 pod]# kubectl apply -f pod-volume.yaml -n devpod/pod-volume created[root@node1 pod]#
[root@node1 pod]# kubectl get pod -n dev -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESpod-volume 2/2 Running 0 17s 10.200.104.36 node2 <none> <none>[root@node1 pod]#
[root@node2 ~]# crictl psCONTAINER IMAGE CREATED STATE NAME ATTEMPT POD ID5ef0dd5143665 bba24acba395b 24 seconds ago Running redis 0 a9c6a4f87ffde0123cd4068b28 8ad32427177e4 28 seconds ago Running web 0 a9c6a4f87ffde8eb0924940884 f2f70adc5d89a About an hour ago Running my-nginx 34 a696725bc8d76be92ec599aca8 67da37a9a360e About an hour ago Running coredns 33 0ea47c03f8a051b44a197f9c4e 7a71aca7b60fc About an hour ago Running calico-node 33 d4b02f3244df6c7cf66853091b 90f9d984ec9a3 About an hour ago Running node-cache 33 a461065aec716cfa1c7594c33b acac7d63e4060 About an hour ago Running nginx-ingress-controller 4 a3cdef0be2594[root@node2 ~]#
[root@node2 ~]# crictl exec -it 5ef0dd5143665 /bin/bashroot@pod-volume:/data# cdroot@pod-volume:/# lsbin boot data dev etc home lib lib64 media mnt opt proc root run sbin shared-redis srv sys tmp usr varroot@pod-volume:/# cd shared-redis/root@pod-volume:/shared-redis# lsroot@pod-volume:/shared-redis# echo "redis" > yunweijia.txtroot@pod-volume:/shared-redis# cat yunweijia.txtredisroot@pod-volume:/shared-redis# exitexit[root@node2 ~]#
[root@node2 ~]# crictl exec -it 0123cd4068b28 bin/bashroot@pod-volume:/# lsbin boot dev etc home lib lib64 media mnt opt proc root run sbin shared-web springboot-web-demo.jar srv sys tmp usr varroot@pod-volume:/# cd shared-web/root@pod-volume:/shared-web# lsyunweijia.txtroot@pod-volume:/shared-web# cat yunweijia.txtredisroot@pod-volume:/shared-web# exitexit[root@node2 ~]#
[root@node2 ~]# cat shared-volume-data/yunweijia.txtredis[root@node2 ~]#
POD的Hosts文件
[root@node2 ~]# crictl exec -it 5ef0dd5143665 cat etc/hosts# Kubernetes-managed hosts file.127.0.0.1 localhost::1 localhost ip6-localhost ip6-loopbackfe00::0 ip6-localnetfe00::0 ip6-mcastprefixfe00::1 ip6-allnodesfe00::2 ip6-allrouters10.200.104.36 pod-volume[root@node2 ~]#
[root@node2 ~]# crictl exec -it 0123cd4068b28 cat etc/hosts# Kubernetes-managed hosts file.127.0.0.1 localhost::1 localhost ip6-localhost ip6-loopbackfe00::0 ip6-localnetfe00::0 ip6-mcastprefixfe00::1 ip6-allnodesfe00::2 ip6-allrouters10.200.104.36 pod-volume[root@node2 ~]#
# 先删除pod[root@node1 pod]# kubectl delete -f pod-volume.yaml -n devpod "pod-volume" deleted[root@node1 pod]#
[root@node1 pod]# vim pod-volume.yamlapiVersion: v1kind: Podmetadata:name: pod-volumespec:hostAliases:- ip: "192.168.112.131"hostnames:- "ceshi.volume.com"containers:- name: webimage: registry.cn-beijing.aliyuncs.com/yunweijia0909/springboot-web:v1ports:- containerPort: 8080volumeMounts:- name: shared-volumemountPath: shared-web- name: redisenv:- name: REDIS_PORTvalue: "6379"image: redisvolumeMounts:- name: shared-volumemountPath: shared-redisvolumes:- name: shared-volumehostPath:path: shared-volume-data[root@node1 pod]#
[root@node1 pod]# kubectl apply -f pod-volume.yaml -n devpod/pod-volume created[root@node1 pod]# kubectl get pod -n dev -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESpod-volume 2/2 Running 0 3m 10.200.104.54 node2 <none> <none>[root@node1 pod]#
[root@node2 ~]# crictl exec -it de4805fe7b87c cat etc/hosts# Kubernetes-managed hosts file.127.0.0.1 localhost::1 localhost ip6-localhost ip6-loopbackfe00::0 ip6-localnetfe00::0 ip6-mcastprefixfe00::1 ip6-allnodesfe00::2 ip6-allrouters10.200.104.54 pod-volume# Entries added by HostAliases.192.168.112.131 ceshi.volume.com[root@node2 ~]#
[root@node2 ~]# crictl exec -it ffe81fd533bcd cat etc/hosts# Kubernetes-managed hosts file.127.0.0.1 localhost::1 localhost ip6-localhost ip6-loopbackfe00::0 ip6-localnetfe00::0 ip6-mcastprefixfe00::1 ip6-allnodesfe00::2 ip6-allrouters10.200.104.54 pod-volume# Entries added by HostAliases.192.168.112.131 ceshi.volume.com[root@node2 ~]#
POD和宿主机共享
[root@node1 pod]# kubectl delete -f pod-volume.yaml -n devpod "pod-volume" deleted[root@node1 pod]#
[root@node1 pod]# vim pod-volume.yamlapiVersion: v1kind: Podmetadata:name: pod-volumespec:hostNetwork: truehostPID: truehostAliases:- ip: "192.168.112.131"hostnames:- "ceshi.volume.com"containers:- name: webimage: registry.cn-beijing.aliyuncs.com/yunweijia0909/springboot-web:v1ports:- containerPort: 8080volumeMounts:- name: shared-volumemountPath: shared-web- name: redisenv:- name: REDIS_PORTvalue: "6379"image: redisvolumeMounts:- name: shared-volumemountPath: shared-redisvolumes:- name: shared-volumehostPath:path: shared-volume-data[root@node1 pod]#
[root@node1 pod]# kubectl apply -f pod-volume.yaml -n devpod/pod-volume created[root@node1 pod]# kubectl get pod -n dev -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESpod-volume 2/2 Running 0 17s 192.168.112.131 node2 <none> <none>[root@node1 pod]#
[root@node2 ~]# netstat -tunlp | grep 6379tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 71405/redis-servertcp6 0 0 :::6379 :::* LISTEN 71405/redis-server[root@node2 ~]# netstat -tunlp | grep 8080tcp 0 0 0.0.0.0:18080 0.0.0.0:* LISTEN 2337/nginx: mastertcp6 0 0 :::8080 :::* LISTEN 71290/javatcp6 0 0 :::18080 :::* LISTEN 2337/nginx: master[root@node2 ~]#
POD的生命周期
[root@node1 pod]# kubectl delete -f pod-volume.yaml -n devpod "pod-volume" deleted[root@node1 pod]#
[root@node1 pod]# vim pod-volume.yamlapiVersion: v1kind: Podmetadata:name: pod-volumespec:hostNetwork: truehostPID: truehostAliases:- ip: "192.168.112.131"hostnames:- "ceshi.volume.com"containers:- name: webimage: registry.cn-beijing.aliyuncs.com/yunweijia0909/springboot-web:v1ports:- containerPort: 8080volumeMounts:- name: shared-volumemountPath: /shared-weblifecycle:postStart:exec:command: ["/bin/sh", "-c", "echo web-service starting~~~ >> /shared-web/service.log"]preStop:exec:command: ["/bin/sh", "-c", "echo web-service stoping~~~ >> /shared-web/service.log"]- name: redisenv:- name: REDIS_PORTvalue: "6379"image: redisvolumeMounts:- name: shared-volumemountPath: /shared-redisvolumes:- name: shared-volumehostPath:path: /shared-volume-data[root@node1 pod]#
[root@node1 pod]# kubectl apply -f pod-volume.yaml -n devpod/pod-volume created[root@node1 pod]# kubectl get pod -n dev -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESpod-volume 2/2 Running 0 2m1s 192.168.112.131 node2 <none> <none>[root@node1 pod]#
[root@node2 ~]# cat /shared-volume-data/service.logweb-service starting~~~[root@node2 ~]#
[root@node1 pod]# kubectl delete -f pod-volume.yaml -n devpod "pod-volume" deleted[root@node1 pod]#
[root@node2 ~]# cat /shared-volume-data/service.logweb-service starting~~~web-service stoping~~~[root@node2 ~]#
往期推荐
文章转载自运维家,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




