kubectl proxy
和 kubectl port-forwarding
看起来相似,有时让我感到困惑,我想知道它们的差异和它们自己的用例。
最佳答案
如“How kubectl port-forward
works?”中所述
kubectl port-forward
forwards connections to a local port to a port on a pod.Compared to
kubectl proxy
,kubectl port-forward
is more generic as it can forward TCP traffic whilekubectl proxy
can only forward HTTP traffic.
例如,请参见 Kubernetes port forwarding simple like never before 中的“Alex Barashkov” :
Port forwarding mostly used for the purpose of getting access to internal cluster resources and debugging.
How does it work?
Generally speaking, using port forwarding you could get on your ‘localhost’ any services launched in your cluster.
For example, if you have Redis installed in the cluster on 6379, by using a command like this:kubectl port-forward redis-master-765d459796-258hz 7000:6379
you could forward Redis from the cluster to localhost:7000, access it locally and do whatever you want to do with it.
对于有限的 HTTP 访问,请参阅 kubectl 代理,以及例如来自 On Securing the Kubernetes Dashboard 的“Joe Beda” :
The easiest and most common way to access the cluster is through kubectl proxy. This creates a local web server that securely proxies data to the dashboard through the Kubernetes API server.
如来自 A Step-By-Step Guide To Install & Use Kubernetes Dashboard 的“Awanish”所示:
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
Accessing Dashboard using the kubectl
kubectl proxy
It will proxy server between your machine and Kubernetes API server.
Now, to view the dashboard in the browser, navigate to the following address in the browser of your Master VM:
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
关于kubernetes - kubectl 端口转发和代理的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58360323/