误删docker0网桥之后怎么办呢?

今天,在搭建k8s node节点环境的时候,好巧不巧,执行了如下命令:

[root@hxin221 ~]# ifconfig docker0 down &>/dev/null
[root@hxin221 ~]# brctl delbr docker0 &>/dev/null

  妥妥的把docker网桥删除了,不要问我为什么删除它,我只能说当时神游太虚了。

这下子,问题来了,我在k8s创建一个pod的时候,出问题了:

test         mywebcalculator-1-0-1-index0         0/1       ImageNotReady   0          4s        [cpu:1/1 memory:268435456/268435456]                    <none>               ***.***.***.221

  嗯,出错了,就查原因了,先查看下docker的状态吧

[root@hxin221 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/docker.service.d
           └─flannel.conf
   Active: active (running) since Tue 2018-07-24 14:41:09 CST; 6s ago
     Docs: https://docs.docker.com
  Process: 3887 ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT (code=exited, status=0/SUCCESS)
  Process: 3885 ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT (code=exited, status=0/SUCCESS)
  Process: 3883 ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT (code=exited, status=0/SUCCESS)
 Main PID: 3190 (dockerd)
   Memory: 33.5M
   CGroup: /system.slice/docker.service
           ├─3190 /usr/bin/dockerd --bip=10.0.77.1/24 --mtu=1450 --bip=10.0.77.1/24 --mtu=1450 --bip=10.0.77.1/24 --mtu=1450
           ├─3210 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
           └─5370 docker-containerd-shim fb19c7c56afcc16e3b08977de9be597cb7cf153fafc998717a0449b3d00f9d27 /var/run/docker/libcontainerd/fb19c7c56afcc16e3b08977de9be597cb7cf153fafc998717a0449b3d00f9d27 docker-runc

Jul 24 14:41:08 hxin221 dockerd[3190]: time="2018-07-24T14:41:08.253923793+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
Jul 24 14:41:08 hxin221 dockerd[3190]: time="2018-07-24T14:41:08.254224418+08:00" level=warning msg="mountpoint for pids not found"
Jul 24 14:41:08 hxin221 dockerd[3190]: time="2018-07-24T14:41:08.254460443+08:00" level=info msg="Loading containers: start."
Jul 24 14:41:08 hxin221 dockerd[3190]: time="2018-07-24T14:41:08.273844445+08:00" level=info msg="Firewalld running: false"
Jul 24 14:41:09 hxin221 dockerd[3190]: time="2018-07-24T14:41:09.307222239+08:00" level=info msg="Loading containers: done."
Jul 24 14:41:09 hxin221 dockerd[3190]: time="2018-07-24T14:41:09.322792104+08:00" level=info msg="Daemon has completed initialization"
Jul 24 14:41:09 hxin221 dockerd[3190]: time="2018-07-24T14:41:09.322832435+08:00" level=info msg="Docker daemon" commit=092cba3 graphdriver=devicemapper version=1.13.1
Jul 24 14:41:09 hxin221 dockerd[3190]: time="2018-07-24T14:41:09.332075018+08:00" level=info msg="API listen on /var/run/docker.sock"
Jul 24 14:41:09 hxin221 systemd[1]: Started Docker Application Container Engine.
Jul 24 14:41:12 hxin221 dockerd[3190]: time="2018-07-24T14:41:12.618808849+08:00" level=error msg="Handler for GET /images/registry.wae.haplat.net/test/mywebcalculator:1.0.0/json returned error: No such image: registry.wae.haplat.net/test/mywebcalculator:1.0.0"

  最后一条报错的原因,下载不到,为什么呢?

我又在master上查看了事件:

[root@wscdn09 ~]# kubectl get events --namespace test
FIRSTSEEN   LASTSEEN   COUNT     NAME                    KIND      SUBOBJECT           REASON      SOURCE                     MESSAGE
8s        8s        1         mywebcalculator-1-0-1-index0   Pod                 FailedSync   {kubelet ***.***.***.221}   Error syncing pod, skipping: API error (404): {"message":"failed to create endpoint k8s_POD.8c50e42c_mywebcalculator-1-0-1-index0_test_75e67623-8f0d-11e8-8336-d4bed9aa7cbc_e13625a3 on network bridge: adding interface veth721b28f to bridge docker0 failed: could not find bridge docker0: route ip+net: no such network interface"}

  就是这个原因了,找不到bridge,呵呵了,这个坑可以有,查看ifconfig确认下

flannel.1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1450
        inet 10.0.77.0  netmask 255.255.0.0  broadcast 0.0.0.0
        inet6 fe80::48ed:42ff:fec3:2cb  prefixlen 64  scopeid 0x20<link>
        ether 4a:ed:42:c3:02:cb  txqueuelen 0  (Ethernet)
        RX packets 6496081  bytes 305348102 (291.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4819250  bytes 404274861 (385.5 MiB)
        TX errors 0  dropped 616845 overruns 0  carrier 0  collisions 0

  真没有docker0,只有flannel1.1,既然找不到,找不到就创建一个呗,根据flannel1.1

[root@hxin221 ~]# docker network create --driver bridge --subnet 10.0.77.1/24 --gateway 10.0.77.1 docker0
Error response from daemon: failed to allocate gateway (10.0.77.1): Address already in use

  (⊙o⊙)…,子网段在用?

[root@hxin221 ~]#  docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "7cf94d44da578e9ead3aeca12f772ce9bae3c5faedacf870fd4c7da0e33b9d42",
        "Created": "2018-07-24T14:45:33.910042834+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "10.0.77.1/24",
                    "Gateway": "10.0.77.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1450"
        },
        "Labels": {}
    }
]

  好吧,你还真的在,不是已经删除了吗?怎么还在呢?我也不知道那么多了。网上捞了一圈,看到一条有用的信息,反正大家copy来copy去的,也不知道真假,谁都说自己是原创,不管他,先试试;

[root@hxin221 ~]# systemctl daemon-reload 
[root@hxin221 ~]# systemctl restart docker 
[root@hxin221 ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 10.0.77.1  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 02:42:98:1f:bc:cc  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  好吧,回来了,可以确定,docker0确实是在 systemctl restart docker 重新启动的时候就会再次检查创建!

 

以上

 

posted @ 2018-07-24 15:30  我为什么要写这个  阅读(7028)  评论(0编辑  收藏  举报