简体   繁体   中英

Nginx Ingress Controller gives - 404 not found

I'm using HA-Proxy (Independent server) and Kube.netes v1.25.4 cluster (One master and three workers) bare metal based.

Flow Diagram:-

流程图

I have deployed Jenkins and Nginx ingress controller with help of this Link ,

But when i tried to access our jenkins URL http://jenkins.company.com/jenkins getting 404 Not Found error.

My Jenkins application name space status:-

$ kubectl get all -n jenkins
NAME                           READY   STATUS    RESTARTS      AGE   
pod/jenkins-75cbc954b6-2wfpt   1/1     Running   2 (13d ago)   70d   

NAME                  TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
service/jenkins-svc   ClusterIP   10.96.180.240   <none>        80/TCP    70d

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE                           
deployment.apps/jenkins   1/1     1            1           70d   

NAME                                 DESIRED   CURRENT   READY   AGE   
replicaset.apps/jenkins-75cbc954b6   1         1         1       70d   

Ingress controller status:-

$ kubectl get all -n nginx-ingress
NAME                      READY   STATUS    RESTARTS      AGE
pod/nginx-ingress-5xnz4   1/1     Running   2 (13d ago)   70d
pod/nginx-ingress-h2g9p   1/1     Running   3 (13d ago)   70d
pod/nginx-ingress-jgtc9   1/1     Running   2 (13d ago)   70d

NAME                           DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
daemonset.apps/nginx-ingress   3         3         3       3            3           <none>          70d

Ingress pod log:-

$ kubectl logs nginx-ingress-h2g9p -n nginx-ingress
2023/01/09 03:21:33 [notice] 25#25: signal 29 (SIGIO) received
2023/01/09 03:21:33 [notice] 25#25: signal 17 (SIGCHLD) received from 145
2023/01/09 03:21:33 [notice] 25#25: worker process 145 exited with code 0
2023/01/09 03:21:33 [notice] 25#25: worker process 164 exited with code 0
2023/01/09 03:21:33 [notice] 25#25: worker process 178 exited with code 0
2023/01/09 03:21:33 [notice] 25#25: signal 29 (SIGIO) received

Ingress status:-

$ kubectl get ingress jenkins-ingress -n jenkins
NAME              CLASS   HOSTS                 ADDRESS   PORTS   AGE
jenkins-ingress   nginx   jenkins.company.com             80      63s
$ kubectl describe ingress jenkins-ingress -n jenkins
Name:             jenkins-ingress
Labels:           <none>
Namespace:        jenkins
Address:
Ingress Class:    nginx
Default backend:  <default>
Rules:
  Host             Path  Backends
  ----             ----  --------
  jenkins.company.com
                   /jenkins   jenkins-svc:80 (10.244.2.19:8080)
Annotations:       nginx.ingress.kubernetes.io/rewrite-target: /$2
Events:
  Type    Reason          Age   From                      Message
  ----    ------          ----  ----                      -------
  Normal  AddedOrUpdated  9m4s  nginx-ingress-controller  Configuration for jenkins/jenkins-ingress was added or updated
  Normal  AddedOrUpdated  9m4s  nginx-ingress-controller  Configuration for jenkins/jenkins-ingress was added or updated
  Normal  AddedOrUpdated  9m4s  nginx-ingress-controller  Configuration for jenkins/jenkins-ingress was added or updated

I can't see IP Address values for above ingress and describe ingress outputs.

Even on Kube.netes cluster master terminal also curl fails with below errors.

$ curl -D- http://jenkins.company.com/jenkins -v
*   Trying 160.20.21.6...
* TCP_NODELAY set
* Connected to jenkins.company.com (160.20.21.6) port 80 (#0)
> GET /jenkins HTTP/1.1
> Host: jenkins.company.com
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
< Server: nginx/1.23.2
Server: nginx/1.23.2
< Date: Mon, 09 Jan 2023 02:58:06 GMT
Date: Mon, 09 Jan 2023 02:58:06 GMT
< Content-Type: text/html
Content-Type: text/html
< Content-Length: 153
Content-Length: 153
< Connection: keep-alive
Connection: keep-alive

<
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.23.2</center>
</body>
</html>
* Connection #0 to host jenkins.company.com left intact

My Jenkins service yaml file as follows,

apiVersion: v1
kind: Service
metadata:
  name: jenkins-svc
  namespace: jenkins
  labels:
    app: jenkins
spec:
  selector: 
    app: jenkins
  type: ClusterIP
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

My nginx-ingress.yaml file as follows

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: jenkins-ingress
  namespace: jenkins
spec:
  ingressClassName: nginx
  rules:
  - host: jenkins.company.com
    http:
      paths:
      - path: /jenkins
        pathType: Prefix
        backend:
          service:
            name: jenkins-svc
            port: 
              number: 80

Please let me know whats wrong with my configurations side?

Any help on will be helpful. Thanks in advance.

For me its looks, like your request is not reaching to Nginx container itself. so try below mentioned options.

As Nginx-ingress runs as a daemon set, so Nginx container ports 80 and 443 are mapped with the 80 and 443 ports of the host. so you can use http://{node-IP} to connect to Nginx container. You can make use of any node-IP out of 3 nodes. Once the request reaches to Nginx container then it will be routed to the backend container after checking the resource rules that you created. so you can use http//{node-ip}/jenkins to connect to jenkins container.

To test with curl client. may use hostname spoofing. curl -H "Host: jenkins.company.com" http://{host-ip}/jenkins

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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