404在尝试从Postman访问Ingress时发生。

huangapple go评论82阅读模式
英文:

404 when trying to access ingress from postman

问题

I have an ingress controller with two services running behind it. I also have an SSL certificate installed with Lets Encrypt and cert-manager.

For some reason, whenever I make a request to my endpoints, it returns a 404 not found error. For example:

http://stefandeboer.com/api/neume-billing-service/Transaction

returns:

<html>

<head>
	<title>404 Not Found</title>
</head>

<body>
	<center>
		<h1>404 Not Found</h1>
	</center>
	<hr>
	<center>nginx</center>
</body>

</html>

This is the YAML for my ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/use-regex: "true"
  creationTimestamp: "2023-06-05T22:51:36Z"
  generation: 3
  name: neume-ingress
  namespace: default
  resourceVersion: "1888643"
  uid: 9abf4d0f-3370-4856-b3e2-c555c7042739
spec:
  rules:
  - host: stefandeboer.com
  - http:
      paths:
      - backend:
          service:
            name: neume-user-service
            port:
              number: 80
        path: /api/neume-user-service(/|$)(.*)
        pathType: Prefix
      - backend:
          service:
            name: neume-billing-service
            port:
              number: 80
        path: /api/neume-billing-service(/|$)(.*)
        pathType: Prefix
  tls:
  - hosts:
    - stefandeboer.com
    secretName: tls-secret
status:
  loadBalancer:
    ingress:
    - ip: 20.4.165.91

Both my pods are running in the same namespace:

NAME                                                READY   STATUS    RESTARTS   AGE
neume-billing-service-deployment-769ff6487b-sjk5d   1/1     Running   0          31m
neume-user-service-deployment-5674b4b75d-8zhgp      1/1     Running   0          29m

What could I be doing wrong here?

英文:

I have an ingress controller with two services running behind it. I also have an SSL certificate installed with Lets Encrypt and cert-manager.

For some reason, whenever i make a request to my endpoints, it returns a 404 not found error. For example

http://stefandeboer.com/api/neume-billing-service/Transaction

returns

<html>

<head>
	<title>404 Not Found</title>
</head>

<body>
	<center>
		<h1>404 Not Found</h1>
	</center>
	<hr>
	<center>nginx</center>
</body>

</html>

This is the YAML for my ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/use-regex: "true"
  creationTimestamp: "2023-06-05T22:51:36Z"
  generation: 3
  name: neume-ingress
  namespace: default
  resourceVersion: "1888643"
  uid: 9abf4d0f-3370-4856-b3e2-c555c7042739
spec:
  rules:
  - host: stefandeboer.com
  - http:
      paths:
      - backend:
          service:
            name: neume-user-service
            port:
              number: 80
        path: /api/neume-user-service(/|$)(.*)
        pathType: Prefix
      - backend:
          service:
            name: neume-billing-service
            port:
              number: 80
        path: /api/neume-billing-service(/|$)(.*)
        pathType: Prefix
  tls:
  - hosts:
    - stefandeboer.com
    secretName: tls-secret
status:
  loadBalancer:
    ingress:
    - ip: 20.4.165.91

Both my pods are running in the same namespace:

NAME                                                READY   STATUS    RESTARTS   AGE
neume-billing-service-deployment-769ff6487b-sjk5d   1/1     Running   0          31m
neume-user-service-deployment-5674b4b75d-8zhgp      1/1     Running   0          29m

What could i be doing wrong here?

答案1

得分: 1

It looks like you have a configuration issue with your ingress. The host declaration must be part of the same object as the HTTP declaration.

Instead of:

  rules:
  - host: stefandeboer.com
  - http:

You need to do it like this:

   rules:
   - host: stefandeboer.com
     http:
英文:

its looks like that you have miss configuration on your ingress, the host declaration must be part of the same object as the HTTP declaration.

instead of:

  rules:
  - host: stefandeboer.com
  - http:

you need to do it like this:

   rules:
   - host: stefandeboer.com
     http:

答案2

得分: 0

在对我的YAML文件进行一些调整后,它就像魔法一样运行了!我将http放在主机对象下,并确保在目标重写之后添加了$2。

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/use-regex: "true"
  creationTimestamp: "2023-06-06T00:57:42Z"
  generation: 4
  name: neume-ingress
  namespace: default
  resourceVersion: "1925615"
  uid: d3b349c2-49d1-488b-bc15-148acfce095a
spec:
  rules:
  - host: stefandeboer.com
    http:
      paths:
      - backend:
          service:
            name: neume-user-service
            port:
              number: 80
        path: /neume-user-service(/|$)(.*)
        pathType: Prefix
      - backend:
          service:
            name: neume-billing-service
            port:
              number: 80
        path: /neume-billing-service(/|$)(.*)
        pathType: Prefix
  tls:
  - hosts:
    - stefandeboer.com
    secretName: tls-secret
status:
  loadBalancer:
    ingress:
    - ip: 20.4.165.91
英文:

After making some tweaks to my YAML file it worked like a charm!
I put the http under the host object and made sure to add the $2 after the target-rewrite.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/use-regex: "true"
  creationTimestamp: "2023-06-06T00:57:42Z"
  generation: 4
  name: neume-ingress
  namespace: default
  resourceVersion: "1925615"
  uid: d3b349c2-49d1-488b-bc15-148acfce095a
spec:
  rules:
  - host: stefandeboer.com
    http:
      paths:
      - backend:
          service:
            name: neume-user-service
            port:
              number: 80
        path: /neume-user-service(/|$)(.*)
        pathType: Prefix
      - backend:
          service:
            name: neume-billing-service
            port:
              number: 80
        path: /neume-billing-service(/|$)(.*)
        pathType: Prefix
  tls:
  - hosts:
    - stefandeboer.com
    secretName: tls-secret
status:
  loadBalancer:
    ingress:
    - ip: 20.4.165.91

huangapple
  • 本文由 发表于 2023年6月6日 07:08:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76410512.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定