简体   繁体   English

django 的 Kubernetes 端口转发

[英]Kubernetes port forward for django

I have a kubernetes cluster in which in one of the docker container I am running django.我有一个 kubernetes 集群,其中一个 docker 容器正在运行 django。 It is listening on port 8999它正在侦听端口 8999

http://0.0.0.0:8999 http://0.0.0.0:8999

Whereas the service is listening on port 8444而服务正在侦听端口 8444

I need to access django admin from outside so I did port forward我需要从外部访问 django admin 所以我做了端口转发

kubectl port-forward service/django-service 8444:8444 kubectl 端口转发服务/django-service 8444:8444

But it is not loading the page.但它没有加载页面。 I am not sure if I should port forward the 8444 or 8999. Please advise.我不确定是否应该转发 8444 或 8999。请指教。

say your django app is running in a container inside a pod naming - 'django-75f59d57f4-4nd6q'假设您的 django 应用程序在 pod 命名的容器中运行 - 'django-75f59d57f4-4nd6q'

Verify that the django-75f59d57f4-4nd6q is running in the Pod, and listening on port 8999验证 django-75f59d57f4-4nd6q 是否在 Pod 中运行,并监听 8999 端口

kubectl get pod django-75f59d57f4-4nd6q --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'

If you get - 8999 in the result如果你得到 - 结果为 8999

and if you want to port-forward it to 8444 do this -如果您想将其端口转发到 8444,请执行以下操作 -

kubectl port-forward django-75f59d57f4-4nd6q 8444:8999

and if you have named the service as django-service as then do如果您已将该服务命名为 django-service ,那么请执行以下操作

kubectl port-forward service/django-service 8444:8999

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM