上节我们通过 kubeadm 在 k8s-master 上部署了 Kubernetes,本节安装 Pod 网络并添加 k8s-node1 和 k8s-node2,完成集群部署。
安装 Pod 网络
要让 Kubernetes Cluster 能够工作,必须安装 Pod 网络,否则 Pod 之间无法通信。
Kubernetes 支持多种网络方案,这里我们先使用 flannel,后面还会讨论 Canal。
执行如下命令部署 flannel:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
添加 k8s-node1 和 k8s-node2
在 k8s-node1 和 k8s-node2 上分别执行如下命令,将其注册到 Cluster 中:
kubeadm join --token d38a01.13653e584ccc1980 192.168.56.105:6443
这里的 --token
来自前面 kubeadm init
输出的第 ⑨ 步提示,如果当时没有记录下来可以通过 kubeadm token list
查看。
kubeadm join
执行如下:
根据提示,我们可以通过 kubectl get nodes
查看节点的状态。
目前所有节点都是 NotReady
,这是因为每个节点都需要启动若干组件,这些组件都是在 Pod 中运行,需要首先从 google 下载镜像,我们可以通过如下命令查看 Pod 的状态:
kubectl get pod --all-namespaces
Pending
、ContainerCreating
、ImagePullBackOff
都表明 Pod 没有就绪,Running
才是就绪状态。我们可以通过 kubectl describe pod <Pod Name>
查看 Pod 具体情况,比如:
kubectl describe pod kube-flannel-ds-v0p3x --namespace=kube-system
为了节省篇幅,这里只截取命令输出的最后部分,可以看到在下载 image 时失败,如果网络质量不好,这种情况是很常见的。我们可以耐心等待,因为 Kubernetes 会重试,我们也可以自己手工执行 docker pull
去下载这个镜像。
等待一段时间,image 都成功下载后,所有 Pod 会处于 Running
状态。
这时,所有的节点都已经 Ready
,Kubernetes Cluster 创建成功,一切准备就绪。
小结
本章通过 kubeadm 部署了三节点的 Kubernetes 集群,后面章节我们都将在这个实验环境中学习 Kubernetes 的各项技术。
1.7.4的,为什么不用1.8.0版本来做教程呢,昨天发布了1.8.5,功能改进太多了
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
是的,截图的时候是1.7.4。不过后面章节都是在1.8中实践的。不用担心,没有问题
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
可能写文章的时候,最新版本是1.7.4
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
老师,请问一下这是什么问题?当我执行“kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml”时出现“W1210 16:28:33.554588 19525 factory_object_mapping.go:423] Failed to download OpenAPI (Get https://192.168.80.130:6443/swagger-2.0.0.pb-v1: Forwarding failure), falling back to swagger
Unable to connect to the server: Forwarding failure”
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
看上去像是 api server 服务没起来,先用 kubectl get pod 确保 k8s 的 pod 已经正常运行
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
可能是./kubectl/config中的秘钥不对,重新复制一份进去应该就行了
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
"W1025 01:38:11.959624 45595 factory_object_mapping.go:423] Failed to download OpenAPI (Get http://localhost:8080/swagger-2.0.0.pb-v1: dial tcp 127.0.0.1:8080: getsockopt: connection refused), falling back to swagger\nThe connection to the server localhost:8080 was refused - did you specify the right host or port?"。老师能帮我看一下这是什么问题吗?这也是有人在github上问的一个问题,https://github.com/kubernetes-incubator/kubespray/issues/1866。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
我下的kubernetes是1.8.6,试了很多次,都未能解决这个问题。只要执行kubectl准会输出:The connection to the server localhost:8080 was refused - did you specify the right host or port?。有点忧伤
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
亲测v1.8.5,部署完后三节点状态都是ready,但kubectl get pods --all-namespaces现实kube-dns状态停留在 ContainerCreating,journalctl -u kubelet | grep kube-dns看到“ Error deleting network: failed to find plugin "portmap" in path [/opt/flannel/bin /opt/cni/bin]”,解决办法到https://github.com/projectcalico/cni-plugin/releases/download/v1.9.1/portmap下载portmap并放到/opt/cni/bin,加上可执行权限。。。。。。。大坑啊
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
按照你说的方法搞定了。。帮了大忙了,我都没发现这个问题
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
或者disable portmap。具体看这个解决办法
https://github.com/coreos/flannel/issues/890
用下面这个版本安装 flannel
https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
我也是,不过我换了个vps就好了。。我之前用的vultr,后来变成digitalocean,就没这个问题了。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
来帮着后来人填坑,我遇到的问题是两台node几点无法启动flannel,最后发现是因为两台node节点没有开启docker proxy,导致flannel images无法在node节点上下载。这里面要特别强调网络的问题,一定要确保所有节点都能够正常的访问docker源才行
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
老师,您好!有个问题请教下您。当node节点执行kubeadm join时,node节点所需的镜像是master把自己的镜像给他们,还是master下发命令让node节点自己下载所需的镜像。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
node节点自己下载所需的镜像。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit