首页 文章

Kubernetes HyperV集群公开服务

提问于
浏览
0

TL; DR;

如何从我的主机,通过Hyper-V连接到我的kubernetes集群,并进入Kubernetes代理(kube-proxy) .


所以我使用两个Ubuntu 18.04.1 LTS服务器进行hyper-v设置 . 相同的设置 .

一个是大师

OS Image:                   Ubuntu 18.04.1 LTS
Operating System:           linux
Architecture:               amd64
Container Runtime Version:  docker://18.6.0
Kubelet Version:            v1.11.1
Kube-Proxy Version:         v1.11.1

另一个节点:

OS Image:                   Ubuntu 18.04.1 LTS
Operating System:           linux
Architecture:               amd64
Container Runtime Version:  docker://18.6.0
Kubelet Version:            v1.11.1
Kube-Proxy Version:         v1.11.1

它默认运行这些pod:

kube-system   coredns-78fcdf6894-6ld8l               1/1       Running   1          4h
kube-system   coredns-78fcdf6894-ncp79               1/1       Running   1          4h
kube-system   etcd-node1                             1/1       Running   1          4h
kube-system   kube-apiserver-node1                   1/1       Running   1          4h
kube-system   kube-controller-manager-node1          1/1       Running   1          4h
kube-system   kube-proxy-942xh                       1/1       Running   1          4h
kube-system   kube-proxy-k6jl4                       1/1       Running   1          4h
kube-system   kube-scheduler-node1                   1/1       Running   1          4h
kube-system   kubernetes-dashboard-6948bdb78-9fbv8   1/1       Running   0          25m
kube-system   weave-net-fzj8h                        2/2       Running   2          3h
kube-system   weave-net-s648g                        2/2       Running   3          3h

这两个节点通过两个IP地址暴露给我的LAN:

192.168.1.116
192.168.1.115

我暴露了我的部署:

service.yml

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort # internal cluster management
  ports:
  - port: 80 # container port
    nodePort: 30001 # outside port
    protocol: TCP
    targetPort: http
  selector:
    app: my-api
    tier: backend

列出来:

$ kubectl get svc -o wide
my-service   NodePort    10.105.166.48   <none>        80:30001/TCP   50m       app=my-api,tier=backend
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        4h        <none>

如果我坐在主节点上并卷曲吊舱

$ kubectl get pods -o wide
my-api-86db46fc95-2d6wf   1/1       Running   0          22m       10.32.0.7   node2
$ curl 10.32.0.7:80/api/health
{"success": true}

我的api显然是在pod中 .

当我查询服务IP时

$ curl 10.105.166.48:80/api/health

要么

$ curl 10.105.166.48:30001/api/health

它只是超时

我的主网络配置:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.1.116  netmask 255.255.255.0  broadcast 192.168.1.255

weave: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1376
    inet 10.40.0.0  netmask 255.240.0.0  broadcast 10.47.255.255

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
    inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255

我的iptables只是将所有内容列为 source anywhere destination anywhere ,其中包含对KUBE和DOCKER的大量引用 .

我甚至试图设置dashboard无济于事......

访问网址:

https://192.168.1.116:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

执行 nslookup 显示没有主机名:

$ nslookup my-service
Server:         127.0.0.53
Address:        127.0.0.53#53

** server can't find eyemenu-api-service: SERVFAIL

1 回答

  • 1

    要命中nodeport 30001,您需要使用节点的ip .

    curl nodeip:30001 / api / health

    群集内的Pod不知道节点端口30001 .

    nodePort将端口暴露给kubernetes集群的所有工作节点,因此您可以使用以下任一方法:

    curl node1:30001 / api / health或curl node2:30001 / api / health

相关问题