1 no matches for kind “Ingress” in version “networking.k8s.io/v1”
在 kubernetes v1.18.20 根据 traefik
官方文档部署 时,当执行 kubectl apply -f 04-whoami-ingrsss.yaml
时 上执行以下 yaml 文件创建 ingress 资源的时候出现了这种报错 error: unable to recognize "04-whoami-ingress.yaml": no matches for kind "Ingress" in version "networking.k8s.io/v1"
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: whoami-ingress
namespace: ingress-ns
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: whoami
port:
name: web
查看 kubernetes
官方文档:https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/、https://kubernetes.io/blog/2021/07/26/update-with-ingress-nginx/ 和 ingress-nginx
官方文档: https://kubernetes.github.io/ingress-nginx/,其中有下面这两段话
kubernetes官网:
The v1.22 release will stop serving the following deprecated API versions in favor of newer and more stable API versions:
Ingress in the extensions/v1beta1 API version will no longer be served
Migrate to use the networking.k8s.io/v1beta1 API version, available since v1.14. Existing persisted data can be retrieved/updated via the new version.
ingress-nginx 官网:
也就是说自从 Kubernetes v1.14
版本开始 Ingress
资源才被加入到 networking.k8s.io/v1beta1
这个v1beta1 版本中来,至于什么时候开始这个 networking.k8s.io/v1beta1 这个beta版本变成了稳定版本,可以看这里,也就是说到了 kubernetes v1.19 版本
,Ingress
资源才被加入到 networking.k8s.io/v1
这个版本中来。
因此我们可以把 Ingress
在 k8s
各个版本中所处的 apiVersion
做一个归纳:
Versionkuberentes v.14 <&#61; Version <&#61; kuberentes v1.18 | kubernetes v1.19 <&#61;Version | |
---|
extensions/v1beta1 | networking.k8s.io/v1beta1 | networking.k8s.io/v1 |
当我把yaml 文件中的 networking.k8s.io/v1 修改为 networking.k8s.io/v1beta1 &#xff0c;又发生了如下的错误&#xff1a;
error: error validating "04-whoami-ingress.yaml": error validating data: ValidationError(Ingress.spec.rules[0].http.paths[0].backend): unknown field "service" in io.k8s.api.networking.v1beta1.IngressBackend; if you choose to ignore these errors, turn validation off with --validate&#61;false
也就是说在这个 networking.k8s.io/v1beta1
这个 apiVersion
版本下&#xff0c; 我们ingress 的yaml 里&#xff0c;有些 field
字段是不存在的&#xff0c;比如: service
, e.g &#xff0c;下面我们需要修改我们的 04-whoami-ingress.yaml
文件&#xff0c;请参考这里&#xff1a;https://doc.traefik.io/traefik/providers/kubernetes-ingress/
。
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: whoami-ingress
namespace: ingress-ns
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: whoami
servicePort: 80