入口不能路由API
我的入口无法路由端点。
我提供了一切。 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的入学表现有一个问题。列表中有两个项目,而您想拥有一个项目。此外,您缺少Ingress类。
您必须更改清单,以便您有一个项目。您还应该添加入口课。
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.
You have to change the manifest so that you have a single item. You should also add the ingress class.
我看到,对于入口,您将类别为
&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 asingressClassName
under thespec
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 benginx
.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.