无法部署 Kubernetes Ingress apiVersion networking.k8s.io/v1

Can't deploy Kubernetes Ingress apiVersion networking.k8s.io/v1

我正在准备所有 Ingress 清单文件以保持最新的 apiVersion (networking.k8s.io/v1) 以将我的集群从 1.19 升级到 1.22。

我正在删除之前的 Ingress 规则,然后重新创建:

k delete ingress/my-ingress
k create -f /tmp/ingress.yaml

不幸的是,Ingress 已创建,但 apiVersion extensions/v1beta1 与我清单上的不同:

$ k get ingress/my-ingress -o yaml
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
  creationTimestamp: "2021-08-11T19:42:08Z"

这是我使用的 YAML 示例:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
  labels:
    app.kubernetes.io/instance: my-app
    app.kubernetes.io/name: my-app
  name: my-ingress
  namespace: default
spec:
  rules:
  - host: application.com
    http:
      paths:
        - path: /
          pathType: ImplementationSpecific
          backend:
            service:
              name: my-app
              port:
                number: 443

Kubernetes 版本:

Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.1", GitCommit:"c4d752765b3bbac2237bf87cf0b1c2e307844666", GitTreeState:"clean", BuildDate:"2020-12-18T12:09:25Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"19+", GitVersion:"v1.19.13-eks-8df270", GitCommit:"8df2700a72a2598fa3a67c05126fa158fd839620", GitTreeState:"clean", BuildDate:"2021-07-31T01:36:57Z", GoVersion:"go1.15.14", Compiler:"gc", Platform:"linux/amd64"}

入口控制器版本(我从 0.41 升级以避免任何类型的问题):

Image: k8s.gcr.io/ingress-nginx/controller:v0.48.1@sha256:e9fb216ace49dfa4a5983b183067e97496e7a8b307d2093f4278cd550c303899

This is working as expected, in particular check github answer

当您创建入口对象时,它可以通过任何版本读取 - 服务器处理转换为请求的版本。 在您的请求中 get ingress/my-ingress -o yaml 您没有指定版本,应该阅读。在这种情况下,kubectl 会搜索服务器返回的文档,以找到其中第一个具有请求资源的文档。它可以是任何版本,如您的情况。

因此,如果您想查看特定版本,您可以:

  1. 通过添加清单文件改进您的请求,因为文件中指定了版本
    $ kubectl get -f ingress.yaml -o yaml                                                                                                                
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      annotations:
        ...
  1. 其他选项是在获取请求中限定必要的版本:
    $ kubectl get ingresses.v1.networking.k8s.io
    NAME         CLASS    HOSTS             ADDRESS   PORTS   AGE
    my-ingress   <none>   application.com             80      12m

    $ kubectl get ingresses.v1beta1.networking.k8s.io
    Warning: networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
    NAME         CLASS    HOSTS             ADDRESS   PORTS   AGE
    my-ingress   <none>   application.com             80      13m