快乐的老鼠 发表于 2018-9-16 07:48:59

深入kubernetes之Pod——一pod多容器

  # vi test2_redis_nginx_pod.yaml
  name: perofu4
  labels:
  name: perofu4
  spec:
  replicas: 1
  selector:
  name: perofu4
  template:
  metadata:
  labels:
  name: perofu4
  spec:
  containers:
  - name: redis
  image: www.perofu.com:7070/centos6.4_redis
  command:
  - '/bin/bash'
  - '-c'
  - '/etc/rc.local'
  - name: nginx
  image: www.perofu.com:7070/registry
  #/usr/bin/kubectl create -ftest2_redis_nginx_pod.yaml
  replicationcontrollers/perofu4
  #
  # /usr/bin/kubectl get pod
  NAME             READY   STATUS    RESTARTS   AGE
  perofu-wduar   1/2       Running   1          14s
  # /usr/bin/kubectl get pod
  NAME             READY   STATUS    RESTARTS   AGE
  perofu-wduar   2/2       Running   2          2m
  #
  # /usr/bin/kubectl get pod
  NAME             READY   STATUS    RESTARTS   AGE
  perofu-wduar   2/2       Running   2          2m
  #
  # /usr/bin/kubectl describe pod perofu-wduar
  Name:                           perofu-wduar
  Namespace:                      default
  Image(s):                     www.perofu.com:7070/centos6.4_redis,www.perofu.com:7070/registry
  Node:                           192.168.16.240/192.168.16.240
  Labels:                         name=perofu4
  Status:                         Running
  Reason:
  Message:
  IP:                           172.22.2.9
  Replication Controllers:      perofu4 (1/1 replicas created)
  Containers:
  redis:
  Image:            www.perofu.com:7070/centos6.4_redis
  State:            Running
  Started:          Tue, 16 Feb 2016 16:54:32 +0800
  Ready:            True
  Restart Count:      0
  nginx:
  Image:            www.perofu.com:7070/registry
  State:            Running
  Started:          Tue, 16 Feb 2016 16:54:50 +0800
  Ready:            True
  Restart Count:      2
  Conditions:
  Type          Status
  Ready         True
  #验证
  # docker ps
  CONTAINER ID      IMAGE                                  COMMAND                CREATED             STATUS            PORTS               NAMES
  5c6581d919a5      www.perofu.com:7070/registry:latest    "docker-registry"      2 minutes ago       Up 2 minutes                            k8s_nginx.65e9d290_perofu-wduar_default_eaa53352-cc1f-11e5-938c-000c29eae008_03b774d2
  08315bce234b      centos6.4_redis:latest               "/bin/bash -c /etc/r   2 minutes ago       Up 2 minutes                            k8s_redis.510ddc4c_perofu-wduar_default_eaa53352-cc1f-11e5-938c-000c29eae008_3e6b7907
  15bd3a44a717      gcr.io/google_containers/pause:0.8.0   "/pause"               2 minutes ago       Up 2 minutes                            k8s_POD.e4cc795_perofu-wduar_default_eaa53352-cc1f-11e5-938c-000c29eae008_8c768cca
  #
  #
  # docker exec -it 08315bce234b /bin/bash
  #
  # ifconfig
  eth0      Link encap:EthernetHWaddr 02:42:AC:16:02:09
  inet addr:172.22.2.9Bcast:0.0.0.0Mask:255.255.255.0
  inet6 addr: fe80::42:acff:fe16:209/64 Scope:Link
  UP BROADCAST RUNNINGMTU:1500Metric:1
  RX packets:10 errors:0 dropped:0 overruns:0 frame:0
  TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:823 (823.0 b)TX bytes:718 (718.0 b)
  lo      Link encap:Local Loopback
  inet addr:127.0.0.1Mask:255.0.0.0
  inet6 addr: ::1/128 Scope:Host
  UP LOOPBACK RUNNINGMTU:65536Metric:1
  RX packets:8 errors:0 dropped:0 overruns:0 frame:0
  TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:518 (518.0 b)TX bytes:518 (518.0 b)
  # netstat -anplt
  Active Internet connections (servers and established)
  Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
  tcp      0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      26/sshd
  tcp      0      0 0.0.0.0:5000                0.0.0.0:*                   LISTEN      -
  tcp      0      0 0.0.0.0:6379                0.0.0.0:*                   LISTEN      27/redis-server 0.0
  tcp      0      0 :::22                     :::*                        LISTEN      26/sshd
  #
  # ps axu
  USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  root         10.00.2113481288 ?      Ss   03:54   0:00 /bin/sh /etc/rc.local
  root      260.00.6641682972 ?      S    03:54   0:00 /usr/sbin/sshd -D
  root      270.10.3364841896 ?      Ssl03:54   0:00 redis-server 0.0.0.0:6379
  root      300.10.3114841816 ?      S    03:59   0:00 /bin/bash
  root      450.00.2133641044 ?      R+   04:00   0:00 ps axu
  #
  # ps -ef
  UID      PIDPPIDC STIME TTY          TIME CMD
  root         1   00 03:54 ?      00:00:00 /bin/sh /etc/rc.local
  root      26   10 03:54 ?      00:00:00 /usr/sbin/sshd -D
  root      27   10 03:54 ?      00:00:00 redis-server 0.0.0.0:6379
  root      30   00 03:59 ?      00:00:00 /bin/bash
  root      46    300 04:01 ?      00:00:00 ps -ef
  #登陆第二个容器:
  # docker exec -it 5c6581d919a5 /bin/bash
  root@perofu-wduar:/#
  root@perofu-wduar:/# ifconfig
  eth0      Link encap:EthernetHWaddr 02:42:ac:16:02:09
  inet addr:172.22.2.9Bcast:0.0.0.0Mask:255.255.255.0
  inet6 addr: fe80::42:acff:fe16:209/64 Scope:Link
  UP BROADCAST RUNNINGMTU:1500Metric:1
  RX packets:10 errors:0 dropped:0 overruns:0 frame:0
  TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:823 (823.0 B)TX bytes:718 (718.0 B)
  lo      Link encap:Local Loopback
  inet addr:127.0.0.1Mask:255.0.0.0
  inet6 addr: ::1/128 Scope:Host
  UP LOOPBACK RUNNINGMTU:65536Metric:1
  RX packets:8 errors:0 dropped:0 overruns:0 frame:0
  TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:518 (518.0 B)TX bytes:518 (518.0 B)
  root@perofu-wduar:/#
  root@perofu-wduar:/# ps axu
  USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  root         10.00.9555204716 ?      Ss   08:54   0:00 /usr/bin/python /usr/local/bin/gunicorn --access-logfile - --error-logfile - --max-requests 100 -k gevent --grac
  root      160.95.8 104620 28940 ?      S    08:54   0:07 /usr/bin/python /usr/local/bin/gunicorn --access-logfile - --error-logfile - --max-requests 100 -k gevent --grac
  root      170.96.3 104632 31392 ?      S    08:54   0:07 /usr/bin/python /usr/local/bin/gunicorn --access-logfile - --error-logfile - --max-requests 100 -k gevent --grac
  root      200.96.3 104644 31356 ?      S    08:54   0:07 /usr/bin/python /usr/local/bin/gunicorn --access-logfile - --error-logfile - --max-requests 100 -k gevent --grac
  root      210.96.3 104656 31456 ?      S    08:54   0:07 /usr/bin/python /usr/local/bin/gunicorn --access-logfile - --error-logfile - --max-requests 100 -k gevent --grac
  root      280.70.3181401968 ?      S    09:08   0:00 /bin/bash
  root      440.00.2155681132 ?      R+   09:08   0:00 ps axu
  root@perofu-wduar:/#
  root@perofu-wduar:/# netstat -anptl
  Active Internet connections (servers and established)
  Proto Recv-Q Send-Q Local Address         Foreign Address         State       PID/Program name
  tcp      0      0 0.0.0.0:22            0.0.0.0:*               LISTEN      -
  tcp      0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      1/python
  tcp      0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      -
  tcp6       0      0 :::22                   :::*                  LISTEN      -
  root@perofu-wduar:/#
  #在同一个pod的两个容器中,都有ip:172.22.2.9,都出现了redis的6397端口和python端口5000
  # /usr/bin/kubectl get pod
  NAME             READY   STATUS    RESTARTS   AGE
  perofu-wduar   2/2       Running   2          17h

页: [1]
查看完整版本: 深入kubernetes之Pod——一pod多容器