使用 kubeadm 在 CentOS 7 搭建 Kubernetes 集群(5)

注意这里 kube-dns 显示状态为 Pending,没有关系,这是因为还没有安装 Pod Network 组件导致的,接下来我们安装 Flannel 网络组件后,它就会自动跑起来了。

5、安装 Flannel 网络组件

kubernetes 提供了很多种网络组件选择,有 Calia、Canal、Flannel、Kube-router、Romana、Weave Net 可以使用,具体使用可以参考 官方文档 (3/4) Installing a pod network 来操作,这里我们选择 Flannel 作为网络组件。

# 安装最新版,注意提前下载好要替代的 image $ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.0/Documentation/kube-flannel.yml

这里我使用 v0.7.1 版本,需要使用两个文件,可在 Github Flannel上获取。

$ kubectl apply -f https://github.com/coreos/flannel/blob/v0.7.1/Documentation/kube-flannel-rbac.yml $ kubectl apply -f https://github.com/coreos/flannel/blob/v0.7.1/Documentation/kube-flannel.yml

安装完毕后,我们稍等一会再来查看下 pod 列表。

$ kubectl get pod --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE kube-system etcd-master.localdomain 1/1 Running 0 23h kube-system kube-apiserver-master.localdomain 1/1 Running 0 1d kube-system kube-controller-manager-master.localdomain 1/1 Running 0 1d kube-system kube-dns-3913472980-37b6d 3/3 Running 0 14m kube-system kube-flannel-ds-vkdzw 2/2 Running 5 4m kube-system kube-proxy-czzg9 1/1 Running 0 1d kube-system kube-scheduler-master.localdomain 1/1 Running 0 1d

现在是不是都是 Running 状态啦!

6、部署 Node 节点

Master 已经正常启动完毕了,现在我们将 Node 加入 cluster 集群中,使用 kubeadm join ... 命令。在 Node 节点上执行(上边执行 init 时日志打印的命令)

$ kubeadm join --token 3aaf19.8e758a48f2050bd1 10.236.65.125:6443 [preflight] Running pre-flight checks [preflight] Starting the kubelet service [discovery] Trying to connect to API Server "10.236.65.125:6443" [discovery] Created cluster-info discovery client, requesting info from "https://10.236.65.125:6443" [discovery] Cluster info signature and contents are valid, will use API Server "https://10.236.65.125:6443" [discovery] Successfully established connection with API Server "10.236.65.125:6443" [bootstrap] Detected server version: v1.6.2 [bootstrap] The server supports the Certificates API (certificates.k8s.io/v1beta1) [csr] Created API client to obtain unique certificate for this node, generating keys and certificate signing request [csr] Received signed certificate from the API server, generating KubeConfig... [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf" Node join complete: * Certificate signing request sent to master and response received. * Kubelet informed of new secure connection details. Run 'kubectl get nodes' on the master to see this machine join.

现在我们在 Master 节点查看下集群节点信息,就会发现已经包含该 Node 节点了。

$ kubectl get node -o wide NAME STATUS AGE VERSION EXTERNAL-IP OS-IMAGE KERNEL-VERSION master.localdomain Ready 1d v1.6.2 <none> CentOS Linux 7 (Core) 3.10.0-514.26.2.el7.x86_64 node0.localdomain Ready 1d v1.6.2 <none> CentOS Linux 7 (Core) 3.10.0-514.26.2.el7.x86_64

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/ccf09e871e52b67aa2845e9bffbb28ef.html