使用docker创建calico网络失败怎么办

48次阅读
没有评论

共计 2397 个字符,预计需要花费 6 分钟才能阅读完成。

这篇文章给大家分享的是有关使用 docker 创建 calico 网络失败怎么办的内容。丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,一起跟随丸趣 TV 小编过来看看吧。

使用 docker 创建 calico 网络失败。

# docker network create --driver calico --ipam-driver calico-ipam testcalico
Error response from daemon: failed to update store for object type *libnetwork.endpointCnt: client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint.

查看 docker 日志:

# journalctl -fu docker
-- Logs begin at Sun 2018-05-06 10:42:10 CST. --
May 06 10:51:11 gpu16 dockerd[1045]: time= 2018-05-06T10:51:11.997488908+08:00  level=warning msg= Registering as \ 192.168.56.16:2375\  in discovery failed: client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint. 
May 06 10:51:13 gpu16 dockerd[1045]: time= 2018-05-06T10:51:13.209441579+08:00  level=error msg= discovery error: client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint. 
May 06 10:51:13 gpu16 dockerd[1045]: time= 2018-05-06T10:51:13.211323271+08:00  level=error msg= discovery error: client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint. 
May 06 10:51:13 gpu16 dockerd[1045]: time= 2018-05-06T10:51:13.213320054+08:00  level=error msg= discovery error: Unexpected watch error

首先想到的错误原因可能是:calico 网络后台的分布式存储是 etcd,而环境中使用的 V3 版本的 etcd,而该版本在 API 方面既支持 V2 又支持 V3。docker 中未正确配置需要的版本,即 docker 要求使用的 etcd API 版本和 etcd 提供的 API 版本不一致,导致出现该问题。
验证:命令行手动去获取 etcd 的版本号:curl http:// etcd_ip :2379/version

# curl http://192.168.56.96:2379/version
{etcdserver : 3.1.9 , etcdcluster : 3.1.0}

返回正常。
看到 http,忽然想到我们的环境访问 http 和 https 是需要设置代理 http_proxy 和 https_proxy,同样,也需要设置 no_proxy 来过滤不使用代理的 IP。如果要访问的 IP 不在 no_proxy 的范围内,代理就会返回非法的 http 应答,而这个应答不是 json 格式的,很可能就对应了错误日志中的“response is invalid json”部分。在环境变量中,已经设置了 http_proxy,https_proxy 和 no_proxy,但是,docker 不能使用操作系统的这三个环境变量,我们需要配置 docker 的这三个环境变量。而且,在创建 calico 网络时,docker 会通过 http 请求向 etcd 注册,因此在 no_proxy 中需要包含 etcd 集群的 IP。

# mkdir -p /etc/systemd/system/docker.service.d/
# vim /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment= HTTP_PROXY=http://192.168.11.200:8080/   HTTPS_PROXY=https://192.168.11.200:8080/   NO_PROXY=192.168.56.109,192.168.56.96 
# systemctl daemon-reload
# systemctl restart docker

待 docker 服务重启完毕,再尝试创建 calico 网络,成功。

# docker network create --driver calico --ipam-driver calico-ipam testcalico
53cbe9b82451b017be6d5d80a8fc17e320f6269521dfeabb7e07fd79ee92e3ef

感谢各位的阅读!关于“使用 docker 创建 calico 网络失败怎么办”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-25发表,共计2397字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)