Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未找到任何入口资源的Nginx入口404_Nginx_Kubernetes Ingress_Nginx Ingress - Fatal编程技术网

未找到任何入口资源的Nginx入口404

未找到任何入口资源的Nginx入口404,nginx,kubernetes-ingress,nginx-ingress,Nginx,Kubernetes Ingress,Nginx Ingress,Nginx控制器正在本地为任何入口资源设置抛出404错误 nginx入口控制器的设置是根据以下文档中详述的步骤进行的,入口控制器在本地设置中作为节点端口服务公开 以下示例入口资源用于测试入口 香蕉 kind: Pod apiVersion: v1 metadata: name: banana-app namespace: nginx-ingress labels: app: banana spec: containers: - name: banana-app

Nginx控制器正在本地为任何入口资源设置抛出404错误

nginx入口控制器的设置是根据以下文档中详述的步骤进行的,入口控制器在本地设置中作为节点端口服务公开

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

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 
苹果

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 # 
安格拉斯菲尔亚马尔

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
然而,如果我试图通过Nodeport入口控制器访问它,我总是无法找到它,如下所示

[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]#

我没有什么评论(我注意到):

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

  Namespace:        default
  instead of nginx-ingress namespace
2,在您的
kubectl描述ing示例入口中
没有如下注释:

kubernetes.io/ingress.class:  nginx
3,我遇到了同样的问题,无法访问该服务,但当您使用
ssl重定向:“false”
选项更改入口控制器的configmap时,该服务将起作用。然后,它将在入口资源中不使用
spec.rules.host参数
的情况下工作

希望这有助于我解决这个问题

我的入口看起来像这样(
ingres.yaml
):

我为路径添加了一个通配符,如下所示:

          - path: /*
并重新应用此入口资源:
kubectl apply-f ingres.yaml


然后它成功了

嗨,我看这是个老案子。你解决了吗?嗨,解决了。我没有为入口设置主机地址。设置入口的主机地址后,当我尝试不带“https”的url时,它已解决
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#

  Namespace:        default
  instead of nginx-ingress namespace
kubernetes.io/ingress.class:  nginx
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-ingress
  namespace: sample
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web-service
                port:
                  number: 80
          - path: /*