这两天在搭建K8S服务器,因为我的是两台不在同一网段的服务器,遇到了不少大大小小的坑,在多次想放弃的情况下,还是一步步艰难排除万难,取得了最终胜利!言归正传,下面一一列举一下,希望对大家有所帮助。

1、kube init初始化master

在初始化时,遇到了一个坑:

kubeadm init --kubernetes-version=1.14.0 --apiserver-advertise-address=192.168.0.1 --pod-network-cidr=10.244.0.0/16

在--apiserver-advertise-address的这个ip地址我使用的是服务器的外网地址,导致出错,这里要写成内网地址

2、加入work节点

在初始化master节点之后获取到:

kubeadm join 192.168.0.1:6443 --token 51ezko.v8bf2b5yqqd5lufy \
    --discovery-token-ca-cert-hash sha256:95407ad19119963699661fb7474d2446cd1c0440abc07a5071b78bf193630c68
    

在work机器上执行该语句,如下:

排查:

第一步:

1、直接ping一下master服务器:外网地址可以ping通,内网ping不通;

2、telnet 一下master服务器6443端口(api-server),发现不通;

解决方案:

1>先关闭了master节点的防火墙(也可以不关闭,只暴露需要对外开放的端口即可),但是仍然ping不通,有点尴尬了;

2>后来查了相关资料,发现还要在腾讯云服务器管理界面打开端口;

经过以上两步便可以正常ping通了6443端口。

第二步:

继续执行:

kubeadm join 192.168.0.1:6443 --token 51ezko.v8bf2b5yqqd5lufy \
    --discovery-token-ca-cert-hash sha256:95407ad19119963699661fb7474d2446cd1c0440abc07a5071b78bf193630c68

执行结果:

 

[root@VM_0_9_centos ~]# kubeadm join 135.232.168.96:6443 --token 51ezko.v8bf2b5yqqd5lufy \
>     --discovery-token-ca-cert-hash sha256:95407ad19119963699661fb7474d2446cd1c0440abc07a5071b78bf193630c68
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
error execution phase preflight: unable to fetch the kubeadm-config ConfigMap: failed to get config map: Get https://122.127.0.13:6443/api/v1/namespaces/kube-system/configmaps/kubeadm-config: dial tcp 122.127.0.13:6443: i/o timeout

排查问题:

1、先在work服务器ping一下master的内网地址,发现内网地址ping不通;

解决方案:在work服务器上执行如下语句

iptables -t nat -A OUTPUT -d 192.168.0.1 -j DNAT --to-destination 152.132.125.96

注:第一个ip是master节点的内网ip,后一个ip是外网Ip

第三步:大功告成!

[root@VM_0_9_centos ~]# kubeadm join 192.168.0.1:6443 --token 51ezko.v8bf2b5yqqd5lufy     --discovery-token-ca-cert-hash sha256:95407ad19119963699661fb7474d2446cd1c04407a5071b78bf193630c68
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.14" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Activating the kubelet service
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

最后

我们在master主机上查看一下k8s的节点就可以了

 

[root@VM_0_13_centos ~]# kubectl get nodes
NAME   STATUS   ROLES    AGE     VERSION
m      Ready    master   4h54m   v1.14.0
w1     Ready    <none>   23m     v1.14.0

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐