使用kubeadm安装k8s之后,出现如下 connection refuse问题

[root@localhost kubernetes]# kubectl get pod
The connection to the server localhost:8080 was refused - did you specify the right host or port?

原因是因为:node节点缺少admin.conf文件,从master导入进去即可

scp admin.conf root@192.168.242.XXX:/etc/kubernetes

然后又出现一个问题,kubectl get nodes命令只出现master节点问题,原来是因为主节点和从节点的主机名都是localhost.localdomain

解决方案:host改名字

更改所有节点的主机名,便于区分:

master节点:hostnamectl --static set-hostname k8s-master
node1节点:hostnamectl --static set-hostname k8s-node1
node2节点:hostnamectl --static set-hostname k8s-node2
重启后生效,也可以运行hostname $hostname直接生效

node节点; kubeadm join

[root@localhost kubernetes]# kubectl get nodes
NAME                    STATUS   ROLES    AGE   VERSION
localhost.localdomain   Ready    master   4h    v1.11.1
[root@localhost kubernetes]#   kubeadm join 192.168.242.134:6443 --token d1m53m.nhiwh52j7cvzn93e --discovery-token-ca-cert-hash sha256:3c81d3a0f34f63b715f4997d79ae1ca3c98fe7e7bbe2d0a6ff3ee07c62733a23
[preflight] running pre-flight checks
	[WARNING RequiredIPVSKernelModulesAvailable]: the IPVS proxier will not be used, because the following required kernel modules are not loaded: [ip_vs_wrr ip_vs_sh ip_vs ip_vs_rr] or no builtin kernel ipvs support: map[ip_vs_wrr:{} ip_vs_sh:{} nf_conntrack_ipv4:{} ip_vs:{} ip_vs_rr:{}]
you can solve this problem with following methods:
 1. Run 'modprobe -- ' to load missing kernel modules;
2. Provide the missing builtin kernel ipvs support

I0625 04:34:47.892507   22582 kernel_validator.go:81] Validating kernel version
I0625 04:34:47.892617   22582 kernel_validator.go:96] Validating kernel config
	[WARNING SystemVerification]: docker version is greater than the most recently validated version. Docker version: 17.12.1-ce. Max validated version: 17.03
	[WARNING Hostname]: hostname "k8s-node1" could not be reached
	[WARNING Hostname]: hostname "k8s-node1" lookup k8s-node1 on 192.168.242.2:53: server misbehaving
[preflight] Some fatal errors occurred:
	[ERROR FileAvailable--etc-kubernetes-pki-ca.crt]: /etc/kubernetes/pki/ca.crt already exists
	[ERROR FileAvailable--etc-kubernetes-kubelet.conf]: /etc/kubernetes/kubelet.conf already exists
	[ERROR FileAvailable--etc-kubernetes-bootstrap-kubelet.conf]: /etc/kubernetes/bootstrap-kubelet.conf already exists
	[ERROR Port-10250]: Port 10250 is in use
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
[root@localhost kubernetes]# kubeadm reset
[reset] WARNING: changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] are you sure you want to proceed? [y/N]: y
[preflight] running pre-flight checks
[reset] stopping the kubelet service
[reset] unmounting mounted directories in "/var/lib/kubelet"
[reset] removing kubernetes-managed containers
[reset] cleaning up running containers using crictl with socket /var/run/dockershim.sock
[reset] failed to list running pods using crictl: exit status 1. Trying to use docker instead[reset] no etcd manifest found in "/etc/kubernetes/manifests/etcd.yaml". Assuming external etcd
[reset] deleting contents of stateful directories: [/var/lib/kubelet /etc/cni/net.d /var/lib/dockershim /var/run/kubernetes]
[reset] deleting contents of config directories: [/etc/kubernetes/manifests /etc/kubernetes/pki]
[reset] deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf /etc/kubernetes/bootstrap-kubelet.conf /etc/kubernetes/controller-manager.conf /etc/kubernetes/scheduler.conf]
[root@localhost kubernetes]#   kubeadm join 192.168.242.134:6443 --token d1m53m.nhiwh52j7cvzn93e --discovery-token-ca-cert-hash sha256:3c81d3a0f34f63b715f4997d79ae1ca3c98fe7e7bbe2d0a6ff3ee07c62733a23
[preflight] running pre-flight checks
	[WARNING RequiredIPVSKernelModulesAvailable]: the IPVS proxier will not be used, because the following required kernel modules are not loaded: [ip_vs ip_vs_rr ip_vs_wrr ip_vs_sh] or no builtin kernel ipvs support: map[ip_vs:{} ip_vs_rr:{} ip_vs_wrr:{} ip_vs_sh:{} nf_conntrack_ipv4:{}]
you can solve this problem with following methods:
 1. Run 'modprobe -- ' to load missing kernel modules;
2. Provide the missing builtin kernel ipvs support

I0625 04:35:49.534991   23343 kernel_validator.go:81] Validating kernel version
I0625 04:35:49.535085   23343 kernel_validator.go:96] Validating kernel config
	[WARNING SystemVerification]: docker version is greater than the most recently validated version. Docker version: 17.12.1-ce. Max validated version: 17.03
	[WARNING Hostname]: hostname "k8s-node1" could not be reached
	[WARNING Hostname]: hostname "k8s-node1" lookup k8s-node1 on 192.168.242.2:53: server misbehaving
[discovery] Trying to connect to API Server "192.168.242.134:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://192.168.242.134:6443"
[discovery] Requesting info from "https://192.168.242.134:6443" again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "192.168.242.134:6443"
[discovery] Successfully established connection with API Server "192.168.242.134:6443"
[kubelet] Downloading configuration for the kubelet from the "kubelet-config-1.11" ConfigMap in the kube-system namespace
[kubelet] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[preflight] Activating the kubelet service
[tlsbootstrap] Waiting for the kubelet to perform the TLS Bootstrap...
[patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "k8s-node1" as an annotation

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

Run 'kubectl get nodes' on the master to see this node join the cluster.
[root@localhost kubernetes]# kubectl get nodes
W0625 04:36:06.319945   24022 loader.go:221] Config not found: /etc/kubernetes/admin.conf
The connection to the server localhost:8080 was refused - did you specify the right host or port?
[root@localhost kubernetes]# kubectl get nodes
NAME                    STATUS   ROLES    AGE   VERSION
k8s-node1               Ready    <none>   32s   v1.11.1
localhost.localdomain   Ready    master   4h    v1.11.1

Logo

开源、云原生的融合云平台

更多推荐