将 k8s 从 1.17.0 升级到 1.22.3 之后部署 ingress 时报错
error: unable to recognize "cnblogs-ingress.yaml": no matches for kind "Ingress" in version "extensions/v1beta1"
原来从 1.19 开始 ingress api 版本变成了 networking.k8s.io/v1
,详见 https://github.com/kubernetes/kubernetes/issues/90077
改为 networking.k8s.io/v1
后出现新的报错
missing required field "pathType" in io.k8s.api.networking.v1.HTTPIngressPath
我们添加的 ingress 规则多数是基于域名的,之前正常使用的配置如下
rules:
- host: q.cnblogs.com
http:
paths:
- backend:
serviceName: q-web
servicePort: 80
而 v1 版必须要指定 path
与 pathType
,需要改成下面这样
rules:
- host: q.cnblogs.com
http:
paths:
- path: /
pathType: Prefix
backend:
serviceName: q-web
servicePort: 80
我们添加了很多这样的规则,幸好可以通过替换的方式一次修改,不然还挺麻烦,将 - backend:
替换为
- path: /
pathType: Prefix
backend:
解决上面的问题后部署又出现新的报错
unknown field "serviceName" in io.k8s.api.networking.v1.IngressBackend
unknown field "servicePort" in io.k8s.api.networking.v1.IngressBackend
要将
backend:
serviceName: q-web
servicePort: 80
改为
backend:
service:
name: q-web
port:
number: 80
继续通过替换进行批量修改,将 serviceName:
替换为
service:
name:
将 servicePort:
替换为
port:
number:
后来发现还需要在 spec
中添加 ingressClassName: nginx
,不然 ingress 规则不会被添加到 nginx.conf 中。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cnblogs-ingress
spec:
ingressClassName: nginx
rules:
- host: q.cnblogs.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: q-web
port:
number: 80
搞定!
ingress.networking.k8s.io/cnblogs-ingress configured
补充:另外需要在 nginx-ingress 部署配置中
- 将
rbac.authorization.k8s.io/v1beta1
改为rbac.authorization.k8s.io/v1
- 将
image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.29.0
改为image: docker.io/bitnami/nginx-ingress-controller:latest