kubectl port-forward 如何工作? [英] How kubectl port-forward works?

查看:30
本文介绍了kubectl port-forward 如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

kubectl 公开可用于为应用程序创建服务并分配 IP 地址以从 Internet 访问它的命令.

kubectl exposes commands that can be used to create a Service for an application and assigns an IP address to access it from internet.

据我所知,要访问 Kubernetes 集群中的任何应用程序,应该创建一个服务资源,并且应该有一个可从外部网络访问的 IP 地址.

As far as I understand, to access any application within Kubernetes cluster there should be a Service resource created and that should have an IP address which is accessible from an external network.

但是在 port-forward 的情况下,kubectl 如何在没有外部访问的 IP 地址的情况下创建到应用程序的连接?

But in case of port-forward how does kubectl create a connection to the application without an IP address which is accessible externally?

推荐答案

kubectl port-forward 制作特定的 Kubernetes API 请求.这意味着运行它的系统需要访问 API 服务器,并且任何流量都将通过单个 HTTP 连接进行隧道传输.

kubectl port-forward makes a specific Kubernetes API request. That means the system running it needs access to the API server, and any traffic will get tunneled over a single HTTP connection.

拥有这对调试非常有用(如果一个特定的 pod 正在运行,您可以直接连接到它;在微服务环境中,您可以与一个不会公开的后端服务对话),但这不是替代方案设置服务对象.当我使用 kubectl port-forward 时,它明显比通过服务连接到 pod 慢,而且我发现该命令在几分钟后就停止了.同样,这些对于调试来说不是大问题,但它们不是我想要的生产系统.

Having this is really useful for debugging (if one specific pod is acting up you can connect to it directly; in a microservice environment you can talk to a back-end service you wouldn't otherwise expose) but it's not an alternative to setting up service objects. When I've worked with kubectl port-forward it's been visibly slower than connecting to a pod via a service, and I've found seen the command just stop after a couple of minutes. Again these aren't big problems for debugging, but they're not what I'd want for a production system.

这篇关于kubectl port-forward 如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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