gpt4 book ai didi

nginx - 错误 : getaddrinfo ENOTFOUND ingress-nginx. ingress-nginx-controller.svc.cluster.local

转载 作者:行者123 更新时间:2023-12-03 23:59:14 28 4
gpt4 key购买 nike

我正在使用 NextJS,我需要它知道它何时在服务器或浏览器上发出请求。要在服务器端做,因为我是在微服务架构中构建的,我需要获取服务的服务名称和命名空间来完成这样的 url http://SERVICENAME.NAMESPACE.svc.cluster.local .
所以在我的终端中,我打印出所有不同的命名空间,如下所示:

$kubectl get namespace

NAME STATUS AGE
default Active 9d
ingress-nginx Active 9d
kube-node-lease Active 9d
kube-public Active 9d
kube-system Active 9d
所以 ingress-nginx是我正在寻找的。然后我跑了:
$kubectl get services -n ingress-nginx

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer 10.100.129.149 localhost 80:30463/TCP,443:31399/TCP 9d
ingress-nginx-controller-admission ClusterIP 10.111.40.184 <none> 443/TCP 9d
所以据我所知 ingress-nginx-controller是我的服务名称。
所以我向 http://ingress-nginx.ingress-nginx-controller.svc.cluster.local/api/users/currentuser 提出请求,但我也必须像这样指定一个主机:
LandingPage.getInitialProps = async () => {
if (typeof window === "undefined") {
const { data } = await axios.get(
"http://ingress-nginx.ingress-nginx-controller.svc.cluster.local/api/users/currentuser",
{
headers: {
Host: "ticketing.dev",
},
}
);

return data;
} else {
const { data } = await axios.get("/api/users/currentuser");

return data;
}
};
但是当我提出请求时,我仍然在浏览器上打印出来:
enter image description here
我拉了 kubectl日志和一切都是 200 :
192.168.65.3 - - [06/Nov/2020:01:30:15 +0000] "GET /_next/static/chunks/pages/_app.js?ts=1604626215582 HTTP/2.0" 200 600778 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 51 0.131 [default-client-srv-3000] [] 10.1.0.244:3000 601240 0.132 200 406761022b9aad1a8cd45b9574f3082c
192.168.65.3 - - [06/Nov/2020:01:30:15 +0000] "GET /_next/static/chunks/main.js?ts=1604626215582 HTTP/2.0" 200 1141017 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 46 0.259 [default-client-srv-3000] [] 10.1.0.244:3000 1141886 0.258 200 da2d882e400bebe57a8ce403acd55c8b
192.168.65.3 - - [06/Nov/2020:01:30:16 +0000] "GET /_next/static/chunks/0.js HTTP/2.0" 200 1578 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 32 0.003 [default-client-srv-3000] [] 10.1.0.244:3000 1595 0.003 200 264ab274cf006691d92b1f03f05ffbca
192.168.65.3 - - [06/Nov/2020:01:30:27 +0000] "GET /_next/webpack-hmr?page=/ HTTP/2.0" 200 1499 "https://ticketing.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36" 34 11.495 [default-client-srv-3000] [] 10.1.0.244:3000 1543 11.495 200 99420f1d80b74b84c0cb42ead9981d43
我错过了什么?我不认为问题出在 ingress-srv.yml文件:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: ticketing.dev
http:
paths:
- path: /api/users/?(.*)
backend:
serviceName: auth-srv
servicePort: 3000
- path: /?(.*)
backend:
serviceName: client-srv
servicePort: 3000

最佳答案

基于访问服务的 URL:

http://SERVICENAME.NAMESPACE.svc.cluster.local 
所以应该是
http://ingress-nginx-controller.ingress-nginx.svc.cluster.local

关于nginx - 错误 : getaddrinfo ENOTFOUND ingress-nginx. ingress-nginx-controller.svc.cluster.local,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64707777/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com