kubernetes - kubectl 端口转发和代理的区别

标签 kubernetes

kubectl proxykubectl 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 while kubectl 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/

相关文章:

amazon-web-services - 通过 API 网关公开在 EKS 中运行的 Kubernetes 服务

dns - 具有嵌套子域 (GCP) 的 Kubernetes 主机入口

ssl - Kubernetes 入口 : SSL (HTTP -> HTTPS) redirect not working (Nginx Docker)

kubernetes - 卡夫卡经纪人完全书面存储

kubernetes - 部署在EKS上的服务无法在其EXTERNAL-IP上应答

kubernetes - 错误 : You must be logged in to the server - the server has asked for the client to provide credentials - "kubectl logs" command gives error

Kubernetes Ingress 未重定向到正确的路径

docker - 具有多个容器的 Pod 上具有多个公开端口的单个服务

linux - Kubernetes 无法为超时的 Pod 挂载卷

docker - Kubernetes 取消了对 Docker 的支持但支持 containerd(它是 Docker 的一部分)是什么意思?