I have a backend pod, service related to it "backend-service" and another frontend pod trying to access the backend on url http://backend-service:8000 . I port forward my frontend , open the url in browser I could see backend url called on networks tab but no request is coming on my backend.
我有一个后端pod,与之相关的服务“后端服务”和另一个试图访问url上后端的前端podhttp://backend-service:8000。我转发我的前端,在浏览器中打开url,我可以看到网络选项卡上调用的后端url,但我的后端没有请求。
But when port-forward my backend and use url "http://localhost:8000", things work
但是当端口转发我的后端并使用url时“http://localhost:8000“,一切正常
更多回答
When you say "frontend pod", do you mean a Pod serving code that runs in the browser? The browser is outside the cluster and can't see the Kubernetes-internal hostnames; you need to make the backend visible via an Ingress or something similar. "Unknown host" error calling containerized backend from frontend covers a similar case for plain Docker, the Kubernetes Ingress system would replace the reverse proxy discussed there.
当你说“前端pod”时,你是指在浏览器中运行的pod服务代码吗?浏览器在集群之外,看不到Kubernetes内部主机名;您需要通过Ingress或类似的东西使后端可见。从前端调用容器化后端的“未知主机”错误涵盖了与普通Docker类似的情况,Kubernetes Ingress系统将取代那里讨论的反向代理。
Yes, the frontend pod means that. Ok, I do have ingress in place which I installed using helm and my backend.yaml has ingress host set to local.example.com. And since I am doing this locally I have an entry in my /etc/hosts too. Can you help me where am I going wrong
是的,前端吊舱就是这个意思。好的,我确实有使用helm安装的ingress,并且我的backend.yaml的ingress主机设置为local.example.com。由于我在本地执行此操作,我的/etc/hosts中也有一个条目。你能帮我吗我哪里错了
优秀答案推荐
A few things to check:
需要检查的几件事:
Are you deploying a Service
for your backend? Without a Service
you won't be able to access the backend's ports from anywhere unless you port-forward them manually. This is likely why you can't access the backend without a port-forward.
您是否正在为后端部署服务?如果没有服务,您将无法从任何地方访问后端的端口,除非您手动端口转发它们。这可能就是没有端口转发就无法访问后端的原因。
Second: Are your Services in different namespaces? If you are deploying in different namespaces, you can't just use the service name to connect like you can in docker. To connect to a service in Kubernetes, the format is <serviceName>.<namespace>.svc.cluster.local
. So for you it might be backend-server.backend.svc.cluster.local
. Check your Services and namespaces and also update your connection strings to use the k8s format.
第二:您的服务是否在不同的命名空间中?如果您在不同的命名空间中进行部署,则不能像在docker中那样仅使用服务名称进行连接。要连接到Kubernetes中的服务,格式为<serviceName>
.svc.cluster.local。因此,对您来说,它可能是backend-server.backend.svc.classer.local。请检查您的服务和命名空间,并更新您的连接字符串以使用k8s格式。
Since, the frontend was trying to call the backend service through a backend api endpoint, so I had to actually pass the url format like "local.example.com/backend". In the url, there should be an ingress path (here /backend) pointing to your backend service.
因为,前端试图通过后端api端点调用后端服务,所以我必须实际传递类似“local.example.com/backend”的url格式。在url中,应该有一个指向后端服务的入口路径(here/backend)。
When we try to hit the backend on a browser based setup, its actually the url that needs to be passed not "serviceName.namespace"
当我们尝试在基于浏览器的设置中访问后端时,实际上需要传递的是url,而不是“serviceName.namespace”
更多回答
我是一名优秀的程序员,十分优秀!