入口不能路由API

发布于 2025-01-31 12:38:40 字数 2111 浏览 2 评论 0原文

我的入口无法路由端点。

我提供了一切。 nginx-controller工作正常。我将HostName bago.com添加为LoadBalancerip。但这无效。

这是我的Ingres的YAML文件

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
spec:
  rules:
    - host: bago.com
    - http:
        paths:
          - path: /web1/
            pathType: Exact
            backend:
              service:
                name: web1-clusterip
                port:
                  number: 8081
          - path: /web2/
            pathType: Exact
            backend:
              service:
                name: web2-clusterip
                port:
                  number: 8082

SVC,

bahaddin@bahaddin-ThinkPad-E15-Gen-2:~/projects/personal/exposer/k8s-ingress$ k get svc
NAME             TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
kubernetes       ClusterIP   10.12.0.1     <none>        443/TCP    154m
web1-clusterip   ClusterIP   10.12.6.102   <none>        8081/TCP   145m
web2-clusertip   ClusterIP   10.12.9.22    <none>        8082/TCP   149m

bahaddin@bahaddin-ThinkPad-E15-Gen-2:~/projects/personal/exposer/k8s-ingress$ k get ingress
NAME              CLASS    HOSTS      ADDRESS          PORTS   AGE
minimal-ingress   <none>   bago.com   34.102.241.199   80      121m
bahaddin@bahaddin-ThinkPad-E15-Gen-2:~/projects/personal/exposer/k8s-ingress$ 

在这里运行的Ingress是我的API Java代码。

@RequestMapping("/web1")
@RestController
public class Controller {

    @GetMapping("/hello")
    public String foo() {
        return "hello from web1 ms";
    }

}

server.port = 8081在容器级上

我的服务

Web1-service.
apiVersion: v1
kind: Service
metadata:
  name: web1-clusterip
spec:
  ports:
    - protocol: "TCP"
      port: 8081
  selector:
    app: web1-dp
  type: ClusterIP

,但是当我输入浏览器时,

http://bago.com/web1/hello 
http://bago.com/web1/hello

我发现一个404错误

屏幕截图
“在此处输入图像说明”

My ingress cannot route to endpoint.

I provided everything. Nginx-controller works properly. I added the hostname bago.com as loadbalancerip. But it doesn't work.

Here is my ingres's yaml file

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
spec:
  rules:
    - host: bago.com
    - http:
        paths:
          - path: /web1/
            pathType: Exact
            backend:
              service:
                name: web1-clusterip
                port:
                  number: 8081
          - path: /web2/
            pathType: Exact
            backend:
              service:
                name: web2-clusterip
                port:
                  number: 8082

svc and ingress running

bahaddin@bahaddin-ThinkPad-E15-Gen-2:~/projects/personal/exposer/k8s-ingress$ k get svc
NAME             TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
kubernetes       ClusterIP   10.12.0.1     <none>        443/TCP    154m
web1-clusterip   ClusterIP   10.12.6.102   <none>        8081/TCP   145m
web2-clusertip   ClusterIP   10.12.9.22    <none>        8082/TCP   149m

bahaddin@bahaddin-ThinkPad-E15-Gen-2:~/projects/personal/exposer/k8s-ingress$ k get ingress
NAME              CLASS    HOSTS      ADDRESS          PORTS   AGE
minimal-ingress   <none>   bago.com   34.102.241.199   80      121m
bahaddin@bahaddin-ThinkPad-E15-Gen-2:~/projects/personal/exposer/k8s-ingress$ 

Here is my API java code.

@RequestMapping("/web1")
@RestController
public class Controller {

    @GetMapping("/hello")
    public String foo() {
        return "hello from web1 ms";
    }

}

server.port=8081 on container level

my service

Web1-service.
apiVersion: v1
kind: Service
metadata:
  name: web1-clusterip
spec:
  ports:
    - protocol: "TCP"
      port: 8081
  selector:
    app: web1-dp
  type: ClusterIP

But when I type in the browser

http://bago.com/web1/hello 
http://bago.com/web1/hello

I got a 404 not found error
Screenshot
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静水深流 2025-02-07 12:38:40

您的入学表现有一个问题。列表中有两个项目,而您想拥有一个项目。此外,您缺少Ingress类。

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
spec:
  rules:
    # these are indivudal list items
    - host: bago.com
    - http: ...

您必须更改清单,以便您有一个项目。您还应该添加入口课。

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
spec:
  # this should be the ingress class, i.e. nginx
  ingressClassName: my-ingress-class
  rules:
    # this list has only 1 items, which is an object. 
    # note the dash (-) 
    - host: bago.com
      http: ...

You have an issue in your ingress manifest. You have two items in the list, while you want to have one. Additionally, you are missing the ingress class.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
spec:
  rules:
    # these are indivudal list items
    - host: bago.com
    - http: ...

You have to change the manifest so that you have a single item. You should also add the ingress class.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
spec:
  # this should be the ingress class, i.e. nginx
  ingressClassName: my-ingress-class
  rules:
    # this list has only 1 items, which is an object. 
    # note the dash (-) 
    - host: bago.com
      http: ...
知你几分 2025-02-07 12:38:40

我看到,对于入口,您将类别为&lt; none&gt;如果您的nginx-controller使用类,则必须将其定义为indressClassName Spec部分创建入口(规则)。

您可以通过描述Ingress-Controller来识别className
kubectl描述部署。 -n =&lt;命名空间&gt;并寻找- in inress-class参数默认情况下,类名称为nginx

如果群集上存在多个Ingress-Controller,则可以通过定义类,我们可以判断哪个Ingress-Controller负责哪个特定的入口规则负责,此类名称将很有用。

I see that for the ingress, you have class as <none> if your nginx-controller is making use of a class then you have to define that as ingressClassName under the spec section while creating ingress (rules).

you can identify the classname by describing the ingress-controller.
kubectl describe deployments.apps <your-ingress-controller-deployment> -n=<namespace> and look for --ingress-class parameter by default the classname should be nginx.

This class name is useful if more than one ingress-controller are present on the cluster, by defining the class we can tell which ingress-controller is responsible for which specific ingress rules.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文