kubectl port-forward如何工作? [英] How kubectl port-forward works?
问题描述
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
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屋!