简体   繁体   English

将服务/窗格加入本地网络

[英]Join Services/Pods to Local Network

I have a single node kubernetes deployment running on a home server, on which I have several services running. 我有一个运行在家庭服务器上的单节点kubernetes部署,我在该服务器上运行了几个服务。 Since it's a small local network, I wanted to block off a portion of the local address range that the rest of my devices use for pod ips, and then route to them directly. 由于这是一个小型局域网,因此我想屏蔽我的其余设备用于Pod ip的部分本地地址范围,然后直接路由到它们。

For example, if I have a web server running, instead of exposing port 80 as an external port and port forwarding from my router to the worker node, I would be able to port forward directly to the pod ip. 例如,如果我有一个运行中的Web服务器,而不是将端口80公开为外部端口并将端口从路由器转发到工作节点,则可以直接将端口转发到Pod ip。

I haven't had much luck finding information on how to do this though, is it possible? 我没有太多运气找到有关如何执行此操作的信息,这可能吗?

I'm new to kubernetes so I am sure I am leaving out important information, please let me know so I can update the question. 我是kubernetes的新手,所以我确定我遗漏了重要信息,请让我知道,以便我可以更新问题。


I got this working by using the macvlan CNI plugin from the reference plugins . 我通过使用参考插件中的macvlan CNI插件使此工作正常进行。 Using kubeadm to set up the cluster, these plugins are already installed and the cluster will be configured to use them. 使用kubeadm设置集群,这些插件已经安装,集群将配置为使用它们。 The only thing to do is drop in a cni.conf (in /etc/cni/net.d ). 唯一要做的是放入cni.conf(在/etc/cni/net.d )。 Mine looks like this 我的看起来像这样

{
    "name": "net",
    "type": "macvlan",
    "mode": "bridge",
    "master": "eno1",
    "ipam": {
        "type": "host-local",
        "ranges": [[{ 
            "subnet": "10.0.0.0/8",
            "gateway": "10.0.0.1",
            "rangeStart": "10.0.10.2",
            "rangeEnd": "10.0.10.254" 
        }]],
        "routes": [
            { "dst": "0.0.0.0/0" }
        ]
    }
}

Putting this in place is all that is needed for coredns to start up and any pods you run will have ips from the range defined in the config. 将其放置到位是coredns启动所需的全部,并且您运行的任何Pod都将具有配置中定义的范围内的ip。 Since this is on the same subnet as the rest of my lan, I can freely ping these containers and my router even lets me play with their settings since they have mac addresses (if you dont want this use ipvlan instead of macvlan, you'll still be able to ping and port forward and everything, your router just wont be enumerating all the devices since they dont have hardware addresses). 由于它与局域网的其余部分位于同一子网中,因此我可以自由地ping这些容器,并且路由器甚至可以让我使用它们的设置,因为它们具有mac地址(如果您不希望使用ipvlan而不是macvlan,则可以仍然能够ping和端口转发以及所有其他功能,您的路由器将不会枚举所有设备,因为它们没有硬件地址。

Couple of caveats: 注意事项:

  1. Services won't work since they're all "fake" (eg they dont have interfaces its all iptables magic that makes them work). 服务将因为它们都是“伪造的”而无法工作(例如,它们没有使所有IPtables发挥作用的接口)。 There's probably a way to make them work but it wasn't worth it for my use case 可能有一种使它们起作用的方法,但是对于我的用例而言,这是不值得的

  2. For whatever reason the DNS server keeps revering to 10.96.0.1. 无论出于何种原因,DNS服务器都会继续使用10.96.0.1。 I have no idea where it got that address from, but I have been working around it by defining dnsPolicy: None and setting dnsConfig.nameservers[0] to my routers IP. 我不知道它从何处获得该地址,但我一直在通过定义dnsPolicy: None解决此dnsPolicy: None并将dnsConfig.nameservers[0]设置为我的路由器IP。 There's probably a better solution for for it. 可能有一个更好的解决方案。

  3. You should run kubeadm with --service-cidr 10.0.10.0/24 --pod-network-cidr 10.0.10.0/24 or it seems like kubelet (or something) doesn't know how to talk to the pods. 您应该使用--service-cidr 10.0.10.0/24 --pod-network-cidr 10.0.10.0/24运行kubeadm, --service-cidr 10.0.10.0/24 --pod-network-cidr 10.0.10.0/24 kubelet(或其他东西)似乎不知道如何与Pod对话。 I actually don't know if --service-cidr matters but it seems like a good idea 我实际上不知道--service-cidr重要,但这似乎是个好主意

  4. Out of the box, your pods wont be able to talk to the master since they are using macvlan devices enslaving its ethernet and for whatever reason macvlan doesn't let you talk between host and guest devices. 开箱即用,您的Pod将无法与主设备进行对话,因为它们使用的是奴役其以太网的macvlan设备,并且无论出于何种原因,macvlan都不会让您在主机和来宾设备之间进行对话。 As you can imagine this isnt a good thing. 您可以想象这不是一件好事。 Solution is to manually add a macvlan device on the host with the same subnet as your pods. 解决方案是在具有与Pod相同子网的主机上手动添加macvlan设备。

  5. It seems like even ports you don't expose from the pod are usable from the lan devices (which isnt cool), probably since the iptables rules think that anything on the lan is cluster-internal. 看来,即使您没有从Pod暴露的端口也可以从lan设备使用(这很酷),这可能是因为iptables规则认为lan上的任何内容都是群集内部的。 I haven't put much time into debugging this. 我没有花很多时间来调试它。

This is probably some kind of cardinal sin for people used to using kubernetes in production, but its kind of cool and useful for a home setup, though it certainly feels like a hack sometimes. 对于习惯于在生产中使用kubernetes的人们来说,这可能是一种主要的罪过,但是它对于家庭设置很酷并且很有用,尽管有时确实感觉像是在被黑客入侵。

I believe the answer to your question is to use the dhcp IPAM plugin to CNI , but being mindful about Pod address recycling. 我相信您问题的答案是将dhcp IPAM插件用于CNI ,但要注意Pod地址回收。 I say be mindful because it might not matter, unless you have high frequency Pod termination, but on the other hand I'm not sure where it falls on the Well That's Unfortunate™ spectrum if a Pod IP is recycled in the cluster. 我说要小心,因为除非您使用高频Pod端接,否则可能无关紧要,但另一方面,如果群集中的Pod IP被回收,我不确定它在Well That's Unfortunate™频谱中的地位。

The bad news is that I have not had any experience with these alternative CNI plugins to be able to speak to the sharp edges one will need to be mindful of, so hopefully if someone else has then they can chime in. 坏消息是,我还没有使用这些替代CNI插件的经验,无法与一个尖锐的边缘说话,因此,希望如果有人有,他们可以加入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM