error: 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, ValidationError(Ingress.spec.rules[0].http.paths[0]): missing required field "pathType" in io.k8s.api.networking.v1.HTTPIngressPath, ValidationError(Ingress.spec.rules[0].http.paths[1].backend): unknown field "serviceName" in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[1].backend): unknown field "servicePort" in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[1]): missing required field "pathType" in io.k8s.api.networking.v1.HTTPIngressPath, ValidationError(Ingress.spec.rules[0].http.paths[2].backend): unknown field "serviceName" in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[2].backend): unknown field "servicePort" in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[2]): missing required field "pathType" in io.k8s.api.networking.v1.HTTPIngressPath, ValidationError(Ingress.spec.rules[0].http.paths[3].backend): unknown field "serviceName" in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[3].backend): unknown field "servicePort" in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[3]): missing required field "pathType" in io.k8s.api.networking.v1.HTTPIngressPath]; if you choose to ignore these errors, turn validation off with --validate=false
时间: 2024-02-04 18:04:10 浏览: 30
这个错误信息是由于 Ingress 对象的 API 版本发生了变化,且文件中的部分字段被废弃或修改导致的。
在新的 API 版本中,HTTPIngressPath 对象中新增了 pathType 字段用于指定路径类型,同时 IngressBackend 中的 serviceName 和 servicePort 字段也被修改为了 Service 对象中的 name 和 port 字段。因此,需要将 ingress.yaml 文件中的字段做出相应的修改。
下面是一个修改后的示例:
```
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: example.com
http:
paths:
- path: /example
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
```
需要注意的是,修改后的 Ingress 对象需要使用新的 API 版本,即 networking.k8s.io/v1。如果还是使用旧的 API 版本,会导致类似的错误。此外,如果仍然出现类似的错误,可以使用 `--validate=false` 参数来关闭验证。但是这并不是一个好的解决方案,因为验证可以帮助我们发现配置文件中的错误。