警告:networking.k8s.io/v1beta1 Ingress 在 v1.19+ 中已弃用,在 v1.22+ 中不可用;使用 networking.k8s.io/v1 入口

Warning: networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress

我的 ingress.yml 文件如下

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "example-issuer"
spec:
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          serviceName: example-service
          servicePort: http
        path: /                 
  tls:
  - secretName: example-tls-cert
    hosts:
      - example.com

将 apiVersion: networking.k8s.io/v1beta1 更改为 networking.k8s.io/v1 后出现以下错误。

验证数据时出错:[ValidationError(Ingress.spec.rules[0].http.paths[0].backend):io.k8s.api.networking.[=25 中的未知字段“serviceName” =], ValidationError(Ingress.spec.rules[0].http.paths[0].backend)

试试下面的方法

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "example-issuer"
spec:
  rules:
  - host: example.com
    http:
      paths:
      - pathType: Prefix
        path: /
        backend:
          service:
            name: example-service
            port:
              number: 80
  tls:
   - secretName: example-tls-cert
     hosts:
       - example.com