gpt4 book ai didi

Nginx Ingress 给出 404 未找到任何入口资源

转载 作者:行者123 更新时间:2023-12-04 12:39:45 25 4
gpt4 key购买 nike

Nginx Controller 在本地设置任何入口资源时都会抛出 404 错误。

nginx-ingress Controller 设置是根据以下文档中详述的步骤进行的,并且入口 Controller 在本地设置中作为 NodePort 服务公开

https://github.com/nginxinc/kubernetes-ingress/blob/master/docs/installation.md#5-access-the-live-activity-monitoring-dashboard--stub_status-page

以下示例入口资源用于测试入口
香蕉.yaml

kind: Pod
apiVersion: v1
metadata:
name: banana-app
namespace: nginx-ingress
labels:
app: banana
spec:
containers:
- name: banana-app
image: hashicorp/http-echo
args:
- "-text=banana"

---

kind: Service
apiVersion: v1
metadata:
name: banana-service
namespace: nginx-ingress
spec:
selector:
app: banana
ports:
- port: 5678

苹果.yaml
kind: Pod
apiVersion: v1
metadata:
name: apple-app
namespace: nginx-ingress
labels:
app: apple
spec:
containers:
- name: apple-app
image: hashicorp/http-echo
args:
- "-text=apple"

---

kind: Service
apiVersion: v1
metadata:
name: apple-service
namespace: nginx-ingress
spec:
selector:
app: apple
ports:
- port: 5678 #

入口文件.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
namespace: nginx-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: nginx
spec:
rules:
- http:
paths:
- path: /apple
backend:
serviceName: apple-service
servicePort: 5678
- path: /banana
backend:
serviceName: banana-service
servicePort: 5678

以下是服务列表
NAMESPACE       NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
nginx-ingress apple-service ClusterIP 10.111.230.109 <none> 5678/TCP 95m
nginx-ingress banana-service ClusterIP 10.102.139.127 <none> 5678/TCP 95m
nginx-ingress nginx-ingress NodePort 10.97.65.187 <none> 80:30207/TCP,443:31031/TCP 6d23h
[root@kube01 ingress]# kubectl get ing
NAME HOSTS ADDRESS PORTS AGE
example-ingress * 80 131m
[root@kube01 ingress]# kubectl describe ing example-ingress
Name: example-ingress
Namespace: default
Address:
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
*
/apple apple-service:5678 (10.244.2.7:5678)
/banana banana-service:5678 (10.244.1.11:5678)
Annotations:
ingress.kubernetes.io/rewrite-target: /
Events: <none>

如果我按如下方式直接 curl pod ,它会按预期工作
[root@kube01 ingress]# curl http://10.244.2.7:5678/apple
apple
[root@kube01 ingress]# curl http://10.244.1.11:5678/banana
banana
[root@kube01 ingress]#

但是,如果我尝试通过 Nodeport 入口 Controller 访问它,我总是找不到如下
[root@kube01 ingress]# curl http://xx.xx.xx.193:30207/apple
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.17.2</center>
</body>
</html>
[root@kube01 ingress]# curl http://xx.xx.xx.193:30207/banana
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.17.2</center>
</body>
</html>
[root@kube01 ingress]#


curl http://xx.xx.xx.193:30207/apple
curl http://xx.xx.xx.193:30207/banana
从外部访问或从浏览器访问时,上述语句应分别显示苹果和香蕉

更新:我进入运行入口 Controller 的 pod 并检查其配置文件,发现入口资源未应用于 Controller 。我尝试重新启动容器但没有运气。我也尝试重新应用入口资源,但 pod 中的配置文件没有改变。进入 Controller 的所有内容都在配置文件中的位置标记中抛出 404。任何有关资源未应用于 Controller 的帮助表示赞赏
root@nginx-ingress-685d7964cd-djvgf:/etc/nginx# cat nginx.conf

user nginx;
worker_processes auto;
daemon off;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';


access_log /var/log/nginx/access.log main;


sendfile on;
#tcp_nopush on;

keepalive_timeout 65s;
keepalive_requests 100;

#gzip on;

server_names_hash_max_size 512;


variables_hash_bucket_size 256;
variables_hash_max_size 1024;

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}





server {
listen 80 default_server;
listen 443 ssl default_server;

ssl_certificate /etc/nginx/secrets/default;
ssl_certificate_key /etc/nginx/secrets/default;

server_name _;
server_tokens "on";
access_log off;



location / {
return 404;
}
}
# stub_status
server {
listen 8080;

allow 127.0.0.1;
deny all;
location /stub_status {
stub_status;
}
}

include /etc/nginx/config-version.conf;
include /etc/nginx/conf.d/*.conf;

server {
listen unix:/var/run/nginx-502-server.sock;
access_log off;

location / {
return 502;
}
}
}

stream {
log_format stream-main '$remote_addr [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time';

access_log /var/log/nginx/stream-access.log stream-main;


}
root@nginx-ingress-685d7964cd-djvgf:/etc/nginx#

最佳答案

我有一些评论(我注意到的):

1 , 您的入口在默认命名空间中工作:

  Namespace:        default
instead of nginx-ingress namespace

2 , 在您的 kubectl describe ing example-ingress没有像这样的注释:
kubernetes.io/ingress.class:  nginx

3 ,我遇到了同样的问题,我无法访问该服务,但是当您使用 ssl-redirect: "false" 更改入口 Controller 的配置映射时,它会起作用。选项。然后它会在没有 spec.rules.host parameter 的情况下工作在您的入口资源中。

希望这有帮助

关于Nginx Ingress 给出 404 未找到任何入口资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57425817/

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