kubernetes 404当试图访问入口从 Postman

vdzxcuhz  于 2023-06-21  发布在  Kubernetes
关注(0)|答案(2)|浏览(114)

我有一个入口控制器,在它后面运行两个服务。我也有一个SSL证书安装与让加密和cert-manager。
由于某种原因,每当我向我的端点发出请求时,它都会返回404未找到错误。比如说,

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

退货

<html>

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

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

</html>

这是我的入口的YAML:

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

我的两个pod都在同一个命名空间中运行:

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

我能做错什么呢?

jucafojl

jucafojl1#

看起来你在你的入口上错过了配置,主机声明必须和HTTP声明是同一个对象的一部分。
而不是:

rules:
  - host: stefandeboer.com
  - http:

你需要这样做:

rules:
   - host: stefandeboer.com
     http:
8mmmxcuj

8mmmxcuj2#

在对我的YAML文件做了一些调整后,它就像一个魅力!我把http放在host对象下面,并确保在target-rewrite之后添加$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

相关问题