入口类的入口控制器名称

入口类的入口控制器名称

本文介绍了入口类的入口控制器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置我的入口控制器,入口类和入口,以在集群外部公开服务.这是全新的群集设置.

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?

推荐答案

我已经使用IngressClassIngressNginx 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 is nginx
  • Ingress using ingressClassName same as IngressClass name

输出:响应404

场景2

  • 具有自定义名称的IngressClass
  • 具有自己的ingress-class入口测试的Nginx入口控制器
  • 使用与ingressClass名称相同的ingressClassName的
  • IngressClass with custom name
  • Nginx Ingress Controller with owningress-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 value test
  • 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 value nginx
  • 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-controllerNginx 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-controllerNginx Incorporatedk8s.io/ingress-nginxOpen 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.

这篇关于入口类的入口控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 22:56