如何将流量从物理服务器的端口路由到minikube集群? [英] How to route traffic from pysical server's port to minikube cluster?

查看:44
本文介绍了如何将流量从物理服务器的端口路由到minikube集群?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将流量从一个端口通过kubernetes集群(使用minikube)发送到另一个物理端口.我不知道如何将流量从物理端口路由到群集,以及从群集路由到第二个物理端口.我通过入口公开集群(并且我也测试了服务解决方案),我有一项服务将外部tarffic发送到Pod,另一项服务将流量从第一个Pod发送到第二个Pod.但是我真的不知道如何将流量从端口发送到群集,以及如何从群集发送到接收端口...

我的集群在其中进行了描述:

此答案不承认:

  • 用于将流量从 Pod 路由到物理端口 enp0s5 的软件.

旁注!

由于有很多有用的信息,请考虑输入答案中包含的每个链接.


Minikube 是一种工具,可生成您的单节点Kubernetes集群以用于开发目的在您的计算机(PC,笔记本电脑,服务器等)上.

它使用不同的驱动程序来运行Kubernetes(可以部署为 bare-metal ,在 docker virtualbox 中部署> kvm 等).这样可以与主机( Ubuntu 服务器)隔离.这也意味着在此设置的网络部分方面有所区别.

通过使用 kvm2 驱动程序对 minikube 进行设置,您将需要对设置进行一些其他更改,以便能够从 192.168.0.150 到您的部署(一组 Pods ).

让我们假设 Deployment 清单如下:

  apiVersion:apps/v1种类:部署元数据:名称:nginx部署规格:选择器:matchLabels:应用程式:nginx复制品:1模板:元数据:标签:应用程式:nginx规格:容器:-名称:nginx图片:nginx端口:-containerPort:80 

我们还假设 Service 清单如下:

  apiVersion:v1种类:服务元数据:名称:nginx部署规格:类型:NodePort选择器:应用程式:nginx#<-必须与Deployment matchLabels相符端口:-协议:TCP端口:80targetPort:80nodePort:30000 

上面示例中的 NodePort 类型的

Service 将在 minikube 实例(IP)上公开您的 Deployment .端口 30000 .

在此特定示例中, Service (一种抽象方式公开运行在一组Pod上的应用程序作为网络服务)将公开 minikube 实例和您的主机中的 Pod ,但不公开用于外部访问(例如 192.168.0.0/24 网络中的其他计算机).

允许外部流量的选项是:

  • 在您的主机上运行( Ubuntu 服务器):
    • $ kubectl port-forward --address 192.168.0.150 service/nginx-deployment 8000:80

kubectl 将允许将 8000 端口上的 Ubuntu 服务器上的连接直接转发到 nginx-deployment 服务,并固有地为您的 Pod 提供服务.

旁注!

  • 您还可以在PC/笔记本电脑上使用 kubectl port-forward ,这样就可以将来自PC/笔记本电脑端口的流量定向到您的 Pod .

  • -地址192.168.0.150 设置为专门针对 enp0s6 .

  • 使用操作系统内置的端口转发.

您可以通过以下答案了解更多信息:


以上说明应有助于您将流量直接从 enp0s6 定向到您的 Pod .从 Pod 向您的 enp0s5 接口发送流量非常简单.您可以运行(来自 Pod ):

  • curl 10.0.0.150 ( enp0s5 )
  • curl 10.0.0.X ( enp0s5 网络中的设备)

替代

作为替代方案,您可以尝试在不使用 minikube 的情况下配置自己的Kubernetes集群.这将固有地消除隔离层,并允许您进行更直接的访问.有很多选项,例如:


我建议您检查其他资源,因为Kubernetes是一个复杂的解决方案,有很多发现:

I want to sent traffic from one port through kubernetes cluster (using minikube) to another physical port. I don't know how to route traffic from physical port to cluster and from cluster to the second physical port. I'm exposing cluster via ingress (and I tested service solution also), i have one service to send external tarffic to pod and another to sent traffic from first pod to second pod. But I really don't know how to send this traffic from port to cluster and how to sent from cluster to receiving port...

My cluster is described in there: How to route test traffic through kubernetes cluster (minikube)?

解决方案

Assuming that:

  • Traffic needs to enter through a physical enp0s6 port on Ubuntu Server and be sent to Pod
  • Pod is configured with some software capable of routing traffic.
  • Pod from the image is routing traffic received to a physical enp0s5 port on the same Ubuntu Server machine (or further down the line).

This answer does not acknowledge:

  • Software used to route the traffic from Pod to a physical port enp0s5.

A side note!

Please consider entering each link that I included in the answer as there are a lot of useful information.


Minikube is a tool that spawn your single node Kubernetes cluster for development purposes on your machine (PC, Laptop, Server, etc.).

It uses different drivers to run Kubernetes (it can be deployed as bare-metal, in docker, in virtualbox, in kvm, etc.). This allows for isolation from host (Ubuntu Server). It also means that there are differences when it comes to the networking part of this setup.

By the setup of minikube with kvm2 driver you will need to make some additional changes to your setup to be able to route traffic from 192.168.0.150 to your Deployment (set of Pods).

Let' assume that the Deployment manifest is following:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1 
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

Also let's assume that the Service manifest is following:

apiVersion: v1
kind: Service
metadata:
  name: nginx-deployment
spec:
  type: NodePort 
  selector:
    app: nginx # <-- this needs to match with Deployment matchLabels
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 30000 

Service of type NodePort from above example will expose your Deployment on a minikube instance (IP) on port 30000.

In this particular example Service (An abstract way to expose an application running on a set of Pods as a network service) will expose the Pod within minikube instance and your host but not for external access (like other machine in the 192.168.0.0/24 network).

Options to allow external traffic are either:

  • Run on your host (Ubuntu Server):
    • $ kubectl port-forward --address 192.168.0.150 service/nginx-deployment 8000:80

kubectl will allow connections on your Ubuntu Server on port 8000 to be forwarded directly to the nginx-deployment service and inherently to your Pod.

Side notes!

  • You can also use kubectl port-forward on your PC/Laptop and by that you can direct traffic from the PC/Laptop port to your Pod.

  • --address 192.168.0.150 is set to target specifically enp0s6.

  • Use OS built-in port forwarding.

You can read more about it by following this answer:


Above explanation should help you to direct the traffic to your Pod directly from enp0s6. Sending traffic from Pod to your enp0s5 interface is pretty straightforward. You can run (from your Pod):

  • curl 10.0.0.150 (enp0s5)
  • curl 10.0.0.X (device in enp0s5 network)

Alternative

As an alternative you can try to provision your own Kubernetes cluster without using minikube. This will inherently eliminate the isolation layer and allow you for a more direct access. There are a lot of options like for example:


I encourage you to check the additional resources as Kubernetes is a complex solution and there is a lot to discover:

这篇关于如何将流量从物理服务器的端口路由到minikube集群?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆