设置Kubernetes-Pod无法访问API

时间:2018-12-06 13:01:52

标签: kubernetes installation

我正在尝试在(Ubuntu 16)VM上设置基本的Kubernetes集群。我刚刚按照入门文档进行操作,并且期望可以正常工作的集群,但是不幸的是,没有运气-没有pod似乎无法连接到Kubenernetes API。由于我是Kubernetes的新手,所以我很难找到问题所在。 供应脚本:

apt-get update && apt-get upgrade -y
apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl docker.io
apt-mark hold kubelet kubeadm kubectl
swapoff -a
sysctl net.bridge.bridge-nf-call-iptables=1
kubeadm init
mkdir -p /home/ubuntu/.kube
cp -i /etc/kubernetes/admin.conf /home/ubuntu/.kube/config
chown -R ubuntu:ubuntu /home/ubuntu/.kube
runuser -l ubuntu -c "kubectl apply -f \"https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')\""
runuser -l ubuntu -c "kubectl taint nodes --all node-role.kubernetes.io/master-"

安装似乎很好。

ubuntu@packer-Ubuntu-16:~$ kubectl get pods -o wide --all-namespaces
NAMESPACE     NAME                                       READY   STATUS             RESTARTS   AGE   IP               NODE               NOMINATED NODE   READINESS GATES
kube-system   coredns-86c58d9df4-lbp46                   0/1     CrashLoopBackOff   7          18m   10.32.0.2        packer-ubuntu-16   <none>           <none>
kube-system   coredns-86c58d9df4-t8nnn                   0/1     CrashLoopBackOff   7          18m   10.32.0.3        packer-ubuntu-16   <none>           <none>
kube-system   etcd-packer-ubuntu-16                      1/1     Running            0          17m   145.100.100.100  packer-ubuntu-16   <none>           <none>
kube-system   kube-apiserver-packer-ubuntu-16            1/1     Running            0          18m   145.100.100.100  packer-ubuntu-16   <none>           <none>
kube-system   kube-controller-manager-packer-ubuntu-16   1/1     Running            0          17m   145.100.100.100  packer-ubuntu-16   <none>           <none>
kube-system   kube-proxy-dwhhf                           1/1     Running            0          18m   145.100.100.100  packer-ubuntu-16   <none>           <none>
kube-system   kube-scheduler-packer-ubuntu-16            1/1     Running            0          17m   145.100.100.100  packer-ubuntu-16   <none>           <none>
kube-system   weave-net-sfvz5                            2/2     Running            0          18m   145.100.100.100  packer-ubuntu-16   <none>           <none>

问题:Kubernetes Pod将主机的eth0 ip(145.100.100.100)的IP作为IP正常吗?对我来说似乎很奇怪,我希望他们拥有虚拟IP吗?

您可以看到coredns窗格崩溃了,因为它无法访问API。

这是我所了解的服务:

ubuntu@packer-Ubuntu-16:~$ kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   22m

CoreDNS崩溃,因为API无法访问:

ubuntu@packer-Ubuntu-16:~$ kubectl logs -n kube-system coredns-86c58d9df4-lbp46
.:53
2018-12-06T12:54:28.481Z [INFO] CoreDNS-1.2.6
2018-12-06T12:54:28.481Z [INFO] linux/amd64, go1.11.2, 756749c
CoreDNS-1.2.6
linux/amd64, go1.11.2, 756749c
 [INFO] plugin/reload: Running configuration MD5 = f65c4821c8a9b7b5eb30fa4fbc167769
E1206 12:54:53.482269       1 reflector.go:205] github.com/coredns/coredns/plugin/kubernetes/controller.go:318: Failed to list *v1.Namespace: Get https://10.96.0.1:443/api/v1/namespaces?limit=500&resourceVersion=0: dial tcp 10.96.0.1:443: i/o timeout
E1206 12:54:53.482363       1 reflector.go:205] github.com/coredns/coredns/plugin/kubernetes/controller.go:311: Failed to list *v1.Service: Get https://10.96.0.1:443/api/v1/services?limit=500&resourceVersion=0: dial tcp 10.96.0.1:443: i/o timeout
E1206 12:54:53.482540       1 reflector.go:205] github.com/coredns/coredns/plugin/kubernetes/controller.go:313: Failed to list *v1.Endpoints: Get https://10.96.0.1:443/api/v1/endpoints?limit=500&resourceVersion=0: dial tcp 10.96.0.1:443: i/o timeout

我尝试启动一个简单的alpine吊舱/容器。实际上10.96.0.1不会对ping或其他任何响应。

我被困在这里。我已经尝试过很多Google搜索,但没有任何进展,我的理解很基础。我想网络可能有问题,但我不知道该怎么办(对我来说,get pods时,pod出现了主机IP,这似乎很可疑,但这也许也是正常的吗?)

1 个答案:

答案 0 :(得分:0)

我发现问题是由主机的document-fragment-query规则引起的。