kubernetes云平台管理实战: pod资源共享(三)

一、共享容器IP地址

1、查看容器进程

[root@k8s-node1 ~]# docker ps -a 
CONTAINER ID        IMAGE                                       COMMAND                  CREATED             STATUS                         PORTS               NAMES
27d25a2ee024        10.0.128.0:5000/nginx:latest                "nginx -g 'daemon off"   6 minutes ago       Up 6 minutes                                       k8s_nginx.d9a10343_nginx_default_eb1873c6-1c70-11e9-a431-000c292bd9e1_db2f2216
5a4f3b8afc83        10.0.128.0:5000/pod-infrastructure:latest   "/pod"                   6 minutes ago       Up 6 minutes                                       k8s_POD.be1401e9_nginx_default_eb1873c6-1c70-11e9-a431-000c292bd9e1_e0c2e5a9
3c681264cf57        busybox                                     "/bin/sh"                About an hour ago   Exited (0) 45 minutes ago                          sleepy_euclid
f63325fd3fff        busybox                                     "/bin/sh"                4 hours ago         Exited (1) About an hour ago                       tiny_darwin

2、查看容器网络

[root@k8s-node1 ~]# docker inspect 5a4f3b8afc83(pod)
  "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "fd91965070d661114647c421cccdd79c72fb34d4da0d05d07a0cec7f39e0a32e",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/fd91965070d6",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "d553e2a5b4f2b41597a366f66768bca11fe6684d8205325f5b357be155589b8c",
            "Gateway": "172.16.10.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.16.10.2",
            "IPPrefixLen": 24,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:10:0a:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "b5808699e84fb05d664674add787aa4a9e43d3ca94739c94df244f78d0f2146f",
                    "EndpointID": "d553e2a5b4f2b41597a366f66768bca11fe6684d8205325f5b357be155589b8c",
                    "Gateway": "172.16.10.1",
                    "IPAddress": "172.16.10.2",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:10:0a:02"
                }
            }
        }
    }
]
[root@k8s-node1 ~]# docker inspect 27d25a2ee024 

   },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": null,
            "SandboxKey": "",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": null
        }
    }
]

3、小结

k8s每启动一个容器,都需要先启动一个pod容器,启动的容器共用pod容器的ip地址

二、多pod体验

1、修改k8s_pod.yml文件

[root@k8s-master ~]# cat k8s_pod.yml
apiVersion: v1
kind: Pod
metadata:
  name: nginx2
  labels:
    app: web
spec:
  containers:
    - name: nginx2
      image: 10.0.128.0:5000/nginx:latest
      ports:
        - containerPort: 80

2、启动pod

[root@k8s-master ~]# kubectl create -f k8s_pod.yml
pod "nginx2" created

3、获取pod信息(简版)

[root@k8s-master ~]# kubectl get pod
NAME      READY     STATUS              RESTARTS   AGE
nginx     1/1       Running             0          1h
nginx2    0/1       ContainerCreating   0          18s

4、获取pod信息(详细)

[root@k8s-master ~]# kubectl describe pod nginx
Name:		nginx
Namespace:	default
Node:		k8s-node1/10.0.128.1
Start Time:	Sun, 20 Jan 2019 13:04:51 +0800
Labels:		app=web
Status:		Running
IP:		172.16.10.2
Controllers:	<none>
Containers:
  nginx:
    Container ID:		docker://27d25a2ee0248b103991a27b81e3f244382ebdb642694e2aeb5503c373fdb912
    Image:			10.0.128.0:5000/nginx:latest
    Image ID:			docker-pullable://10.0.128.0:5000/nginx@sha256:e2847e35d4e0e2d459a7696538cbfea42ea2d3b8a1ee8329ba7e68694950afd3
    Port:			80/TCP
    State:			Running
      Started:			Sun, 20 Jan 2019 13:48:30 +0800
    Ready:			True
    Restart Count:		0
    Volume Mounts:		<none>
    Environment Variables:	<none>
Conditions:
  Type		Status
  Initialized 	True 
  Ready 	True 
  PodScheduled 	True 
No volumes.
QoS Class:	BestEffort
Tolerations:	<none>
Events:
  FirstSeen	LastSeen	Count	From			SubObjectPath	Type		Reason		Message
  ---------	--------	-----	----			-------------	--------	------		-------
  1h		20m		13	{kubelet k8s-node1}			Warning		FailedSync	Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request.  details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)"

  1h	19m	182	{kubelet k8s-node1}		Warning	FailedSync	Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\""

  19m	19m	1	{kubelet k8s-node1}	spec.containers{nginx}	Normal	Pulling			pulling image "10.0.128.0:5000/nginx:latest"
  19m	18m	2	{kubelet k8s-node1}				Warning	MissingClusterDNS	kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.
  18m	18m	1	{kubelet k8s-node1}	spec.containers{nginx}	Normal	Pulled			Successfully pulled image "10.0.128.0:5000/nginx:latest"
  18m	18m	1	{kubelet k8s-node1}	spec.containers{nginx}	Normal	Created			Created container with docker id 27d25a2ee024; Security:[seccomp=unconfined]
  18m	18m	1	{kubelet k8s-node1}	spec.containers{nginx}	Normal	Started			Started container with docker id 27d25a2ee024
[root@k8s-master ~]# kubectl get pod -o wide
NAME      READY     STATUS    RESTARTS   AGE       IP            NODE
nginx     1/1       Running   0          1h        172.16.10.2   k8s-node1
nginx2    1/1       Running   0          52s       172.16.48.2   k8s-node2
posted @ 2019-01-21 16:37  活的潇洒80  阅读(1332)  评论(0编辑  收藏  举报