kubernetes 无法为入口控制器创建规则

t2a7ltrp  于 2023-04-05  发布在  Kubernetes
关注(0)|答案(5)|浏览(192)

我在下面的查询中出错了吗?

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /nginx
        backend:
          serviceName: nginx
          servicePort: 80

我得到的错误:

error validating "ingress.yaml": error validating data: [ValidationError(Ingress.spec.rules[0].http.paths[0].backend): unknown field "serviceName" in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[0].backend): unknown field "servicePort" in io.k8s.api.networking.v1.IngressBackend]; if you choose to ignore these errors, turn validation off with
--validate=false
smdnsysy

smdnsysy1#

Ingress规范在更新到v1后已更改。请尝试:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /nginx
        pathType: ImplementationSpecific
        backend:
          service:
            name: nginx
            port:
              number: 80
bvhaajcl

bvhaajcl2#

根据this documentation,您需要更改ServiceName和ServicePort。
每个HTTP规则都包含(...)一个路径列表(例如/testpath),每个路径都有一个关联的后端,后端定义为service.nameservice.port.nameservice.port.number。在负载均衡器将流量定向到引用的服务之前,主机和路径都必须与传入请求的内容匹配。
下面是您的yaml文件,其中包含更正:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /nginx
        backend:
          service:
            name: nginx
            port:
              number: 8080
xdnvmnnf

xdnvmnnf3#

ServiceName和ServicePort没有像v1中那样的关键字可用。

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /nginx
        backend:
          service:
            name: nginx
            port:
              number: 8080
zsbz8rwp

zsbz8rwp4#

服务名称和服务端口语法不正确。请按照以下示例操作

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx-example
  rules:
  - http:
      paths:
      - path: /testpath
        pathType: Prefix
        backend:
          service:
            name: test
            port:
              number: 80
31moq8wy

31moq8wy5#

api版本:networking.k8s.io/v1类型:入口元数据:name:nginx-ingress注解:nginx.ingress.kubernetes.io/rewrite-target::rules:

  • HTTP:路径:
  • path:/nginx pathType:特定于实现的后端:服务:名称:nginx端口:数量:80

相关问题