我使用kubernetes v1.9和centos7
在我初始化集群并成功创建rc之后,当我创建服务时,kubernetes将失败:
[root@localhost ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.5", GitCommit:"f01a2bf98249a4db383560443a59bed0c13575df", GitTreeState:"clean", BuildDate:"2018-03-19T15:59:24Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.6", GitCommit:"9f8ebd171479bec0ada837d7ee641dec2f8c6dd1", GitTreeState:"clean", BuildDate:"2018-03-21T15:13:31Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
[root@localhost ~]# kubectl get rc
NAME DESIRED CURRENT READY AGE
mysql 1 1 1 39m
**BEFORE CREATE SERVICE, EVERYTHING IS OK, BUT WHILE I CREATE SERVICE:**
[root@localhost ~]# kubectl create -f ~/kuber/mysql-svc.yaml
Unable to connect to the server: net/http: TLS handshake timeout
[root@localhost ~]# kubectl get rc
Unable to connect to the server: net/http: TLS handshake timeout
[root@localhost ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.5", GitCommit:"f01a2bf98249a4db383560443a59bed0c13575df", GitTreeState:"clean", BuildDate:"2018-03-19T15:59:24Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
**Unable to connect to the server: net/http: TLS handshake timeout**

yaml文件是这样的:
# cat ~/kuber/mysql-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql

有人可以告诉我这是为什么吗?
如何正确创建服务?
kubelet服务正在运行,但有一些错误信息:
# systemctl status kubelet -l
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/etc/systemd/system/kubelet.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: active (running) since 二 2018-03-27 17:05:50 CST; 15h ago
Docs: http://kubernetes.io/docs/
Main PID: 10352 (kubelet)
CGroup: /system.slice/kubelet.service
├─10352 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true --network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin --cluster-dns=10.96.0.10 --cluster-domain=cluster.local --authorization-mode=Webhook --client-ca-file=/etc/kubernetes/pki/ca.crt --cadvisor-port=0 --cgroup-driver=cgroupfs --rotate-certificates=true --cert-dir=/var/lib/kubelet/pki
└─36095 iptables -w -N KUBE-FIREWALL -t filter
3月 28 08:27:24 localhost.localdomain kubelet[10352]: E0328 08:27:24.160858 10352 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/config/apiserver.go:47: Failed to list *v1.Pod: Get https://192.168.88.129:6443/api/v1/pods?fieldSelector=spec.nodeName%3Dlocalhost.localdomain&limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:27:25 localhost.localdomain kubelet[10352]: E0328 08:27:25.220630 10352 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/kubelet.go:471: Failed to list *v1.Service: Get https://192.168.88.129:6443/api/v1/services?limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:27:25 localhost.localdomain kubelet[10352]: E0328 08:27:25.122992 10352 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/kubelet.go:480: Failed to list *v1.Node: Get https://192.168.88.129:6443/api/v1/nodes?fieldSelector=metadata.name%3Dlocalhost.localdomain&limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:27:26 localhost.localdomain kubelet[10352]: W0328 08:27:25.799971 10352 prober.go:103] No ref for container "docker://48f74ec3374213760ee72a18eee978105d5cb6737a5324020bee6b1b0d45eb79" (kube-dns-6f4fd4bdf-w5rgq_kube-system(788acf83-3197-11e8-b0eb-000c2976ef29):kubedns)
3月 28 08:27:28 localhost.localdomain kubelet[10352]: W0328 08:27:27.560076 10352 status_manager.go:459] Failed to get status for pod "kube-controller-manager-localhost.localdomain_kube-system(cca3952635c33c6b1e1c42d54e3d7e18)": Get https://192.168.88.129:6443/api/v1/namespaces/kube-system/pods/kube-controller-manager-localhost.localdomain: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:27:28 localhost.localdomain kubelet[10352]: E0328 08:27:27.785196 10352 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/config/apiserver.go:47: Failed to list *v1.Pod: Get https://192.168.88.129:6443/api/v1/pods?fieldSelector=spec.nodeName%3Dlocalhost.localdomain&limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:27:28 localhost.localdomain kubelet[10352]: E0328 08:27:28.930804 10352 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/kubelet.go:471: Failed to list *v1.Service: Get https://192.168.88.129:6443/api/v1/services?limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:27:29 localhost.localdomain kubelet[10352]: E0328 08:27:29.130705 10352 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/kubelet.go:480: Failed to list *v1.Node: Get https://192.168.88.129:6443/api/v1/nodes?fieldSelector=metadata.name%3Dlocalhost.localdomain&limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:27:30 localhost.localdomain kubelet[10352]: E0328 08:27:30.379361 10352 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/config/apiserver.go:47: Failed to list *v1.Pod: Get https://192.168.88.129:6443/api/v1/pods?fieldSelector=spec.nodeName%3Dlocalhost.localdomain&limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:27:30 localhost.localdomain kubelet[10352]: W0328 08:27:29.965228 10352 status_manager.go:459] Failed to get status for pod "kube-scheduler-localhost.localdomain_kube-system(0f95caae4a7fffab092dfa6db3c27347)": Get https://192.168.88.129:6443/api/v1/namespaces/kube-system/pods/kube-scheduler-localhost.localdomain: dial tcp 192.168.88.129:6443: getsockopt: connection refused

重启kubelet似乎没用:
[root@localhost ~]# systemctl status kubelet -l
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/etc/systemd/system/kubelet.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/kubelet.service.d
└─10-kubeadm.conf
Active: active (running) since 三 2018-03-28 08:32:03 CST; 1min 28s ago
Docs: http://kubernetes.io/docs/
Main PID: 36455 (kubelet)
CGroup: /system.slice/kubelet.service
└─36455 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true --network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin --cluster-dns=10.96.0.10 --cluster-domain=cluster.local --authorization-mode=Webhook --client-ca-file=/etc/kubernetes/pki/ca.crt --cadvisor-port=0 --cgroup-driver=cgroupfs --rotate-certificates=true --cert-dir=/var/lib/kubelet/pki
3月 28 08:33:30 localhost.localdomain kubelet[36455]: E0328 08:33:30.192129 36455 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/kubelet.go:480: Failed to list *v1.Node: Get https://192.168.88.129:6443/api/v1/nodes?fieldSelector=metadata.name%3Dlocalhost.localdomain&limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:33:30 localhost.localdomain kubelet[36455]: W0328 08:33:30.192360 36455 prober.go:103] No ref for container "docker://c72ddcf19c2ff80e00df0910da43a23600fe335412c8611a00260179c0f6a722" (kube-scheduler-localhost.localdomain_kube-system(0f95caae4a7fffab092dfa6db3c27347):kube-scheduler)
3月 28 08:33:30 localhost.localdomain kubelet[36455]: E0328 08:33:30.192377 36455 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/config/apiserver.go:47: Failed to list *v1.Pod: Get https://192.168.88.129:6443/api/v1/pods?fieldSelector=spec.nodeName%3Dlocalhost.localdomain&limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:33:31 localhost.localdomain kubelet[36455]: E0328 08:33:31.321350 36455 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/kubelet.go:471: Failed to list *v1.Service: Get https://192.168.88.129:6443/api/v1/services?limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:33:31 localhost.localdomain kubelet[36455]: E0328 08:33:31.342084 36455 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/config/apiserver.go:47: Failed to list *v1.Pod: Get https://192.168.88.129:6443/api/v1/pods?fieldSelector=spec.nodeName%3Dlocalhost.localdomain&limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:33:31 localhost.localdomain kubelet[36455]: E0328 08:33:31.342605 36455 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/kubelet.go:480: Failed to list *v1.Node: Get https://192.168.88.129:6443/api/v1/nodes?fieldSelector=metadata.name%3Dlocalhost.localdomain&limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:33:31 localhost.localdomain kubelet[36455]: I0328 08:33:31.761668 36455 kubelet_node_status.go:273] Setting node annotation to enable volume controller attach/detach
3月 28 08:33:32 localhost.localdomain kubelet[36455]: E0328 08:33:32.556183 36455 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/config/apiserver.go:47: Failed to list *v1.Pod: Get https://192.168.88.129:6443/api/v1/pods?fieldSelector=spec.nodeName%3Dlocalhost.localdomain&limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:33:32 localhost.localdomain kubelet[36455]: E0328 08:33:32.556318 36455 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/kubelet.go:480: Failed to list *v1.Node: Get https://192.168.88.129:6443/api/v1/nodes?fieldSelector=metadata.name%3Dlocalhost.localdomain&limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
3月 28 08:33:32 localhost.localdomain kubelet[36455]: E0328 08:33:32.556375 36455 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/kubelet.go:471: Failed to list *v1.Service: Get https://192.168.88.129:6443/api/v1/services?limit=500&resourceVersion=0: dial tcp 192.168.88.129:6443: getsockopt: connection refused
[root@localhost ~]# kubectl get node
The connection to the server 192.168.88.129:6443 was refused - did you specify the right host or port?