问题描述
我正在设置我的入口控制器,入口类和入口,以在集群外部公开服务.这是全新的群集设置.
I am setting up my ingress controller, ingress class and ingress to expose a service outside the cluster. This is fresh cluster setup.
我已经使用设置了nginx-ingress控制器
I have setup the nginx-ingress controller using
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.41.0/deploy/static/provider/baremetal/deploy.yaml
根据我的理解,下一步是创建入口类 https://v1-18.docs.kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class
The next step based on my understanding is to create the ingress class https://v1-18.docs.kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class
apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
name: external-lb
spec:
controller: example.com/ingress-controller
parameters:
apiGroup: k8s.example.com/v1alpha
kind: IngressParameters
name: external-lb
他们如何获得控制器的名称example.com/ingress-controller
?
How did they get the name of the controller example.com/ingress-controller
?
推荐答案
我已经使用IngressClass
,Ingress
和Nginx Ingress Controller
运行了多个方案.
I have run multiple scenarios with IngressClass
, Ingress
and Nginx Ingress Controller
.
场景1
- 具有自定义名称的IngressClass
- Nginx Ingress Controller,其默认
--ingress-class
值为nginx
- 使用与ingressClass名称相同的ingressClassName的
- IngressClass with custom name
- Nginx Ingress Controller with default
--ingress-class
value which isnginx
- Ingress using ingressClassName same as IngressClass name
输出:响应404
场景2
- 具有自定义名称的IngressClass
- 具有自己的
ingress-class
入口测试的Nginx入口控制器 - 使用与ingressClass名称相同的ingressClassName的
- IngressClass with custom name
- Nginx Ingress Controller with own
ingress-class
ingress-test - Ingress using ingressClassName same as IngressClass name
输出:响应404
场景3
- 名称为
test
的IngressClass - Nginx入口控制器
--ingress-class
的值为test
- 使用ingressClassName中的
test
进入
- IngressClass with
test
name - Nginx Ingress Controller
--ingress-class
with valuetest
- Ingress using
test
in ingressClassName
输出:正确的响应
Senario 4
- 名称为
nginx
的IngressClass - Nginx入口控制器
--ingress-class
的值为nginx
- 使用ingressClassName中的
nginx
进入
- IngressClass with
nginx
name - Nginx Ingress Controller
--ingress-class
with valuenginx
- Ingress using
nginx
in ingressClassName
输出:正确的响应
结论
首先,请记住,Nginx
有3种类型. Open Source Nginx Ingress Controller
,您可能正在使用它. Nginx Incorporaton
(nginx inc)和Nginx Incorporaton Plus
.
First of all, please keep in mind that there are 3 types of Nginx
. Open Source Nginx Ingress Controller
, you are probably using it. Nginx Incorporaton
(nginx inc) and Nginx Incorporaton Plus
.
在一种情况下,当我在参数--ingress-class=nginx
中将spec.controller: nginx.org/ingress-controller
与Nginx Ingress Controller
一起使用时,在Nginx Ingress Controller
窗格中,您会看到指向k8s.io/ingress-nginx
的条目.
In one of the scenarios, when I have used spec.controller: nginx.org/ingress-controller
with Nginx Ingress Controller
with argument --ingress-class=nginx
, in Nginx Ingress Controller
pod you will see entry which is pointing to k8s.io/ingress-nginx
.
要重现此行为,您将需要使用特定的控制器部署IngressClass
,然后部署nginx.
To reproduce this behavior, you will need to deploy IngressClass
with specific controller and then deploy nginx.
apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
name: nginx
spec:
controller: nginx.org/ingress-controller
部署Nginx Ingress Controller
后,控制器容器将处于CrashLoopBackOff
状态.在日志中,您将找到条目:
After deploying Nginx Ingress Controller
, controller pod will be in CrashLoopBackOff
state. In logs you will find entry:
E1118 15:42:19.008911 8 main.go:134] Invalid IngressClass (Spec.Controller) value "nginx.org/ingress-controller". Should be "k8s.io/ingress-nginx"
仅当IngressClass
名称设置为nginx
时有效.
It works only when IngressClass
name is set to nginx
.
我想说nginx.org/ingress-controller
是Nginx Incorporated
的k8s.io/ingress-nginx
是Open Source Nginx Ingress
的.
如果在controller Deployment manifest
中的--ingress-class
参数中使用了自定义值,则只有保留Ingress spec.ingressClass
值与控制器参数相同.此外,如果存在,则IngressClass spec.controller
可以具有与所需模式"domain like"相匹配的任何值.完全不影响集群上的Ingress
工作流程行为.
If custom value is used for --ingress-class
argument in the controller Deployment manifest
, presence or absence of IngressClass
object with the same name doesn't made any difference in, how the cluster works, if only you keep Ingress spec.ingressClass
value the same with controller argument. Moreover, if it's present, IngressClass spec.controller
can have any value that match the required pattern "domain like" and that didn't affect Ingress
workflow behavior on my cluster at all.
此外,如果我将ingress-class
的正确值相应地放入spec.ingressClass
属性或metadata.annotation.kubernetes.io/ingress.class
,则Ingress
可以正常工作.如果您尝试将两个值都放在同一个Ingres对象中,则会产生如下错误:
In addition, Ingress
works fine if I put the correct value of the ingress-class
either to spec.ingressClass
property or to metadata.annotation.kubernetes.io/ingress.class
accordingly. It gives an error like the following if you try to put both values to the same Ingres object:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
ingressClassName: nginx
The Ingress "test-ingress" is invalid: annotations.kubernetes.io/ingress.class: Invalid value: "nginx": can not be set when the class field is also set
请记住,它仅针对 Nginx入口控件进行了测试.如果您想将IngressClass
与其他Ingress Controllers
一起使用,例如 Traefik 或大使,您可以查看其发行说明.
Please keep in mind it was tested only for Nginx Ingress Controlle. If you would like to use IngressClass
with other Ingress Controllers
like Traefik or Ambasador, you would check their release notes.
这篇关于入口类的入口控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!