在 Kubernetes Ingress 从 v1beta1 切换到 v1 时出现错误“io.k8s.api.networking.v1.IngressBackend”中的“未知字段“serviceN
Posted
技术标签:
【中文标题】在 Kubernetes Ingress 从 v1beta1 切换到 v1 时出现错误“io.k8s.api.networking.v1.IngressBackend”中的“未知字段“serviceName”【英文标题】:Get error "unknown field "serviceName" in io.k8s.api.networking.v1.IngressBackend" when switch from v1beta1 to v1 in Kubernetes Ingress 【发布时间】:2021-01-15 09:15:53 【问题描述】:我的 Ingress 使用了以下 YAML,它有效(并继续有效):
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
namespace: test-layer
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: mylocalhost.com
http:
paths:
- path: /
backend:
serviceName: test-app
servicePort: 5000
但是,它告诉我它已被弃用,我应该改为使用 networking.k8s.io/v1
。当我这样做(见下文)时,它会引发错误。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-ingress
namespace: test-layer
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: mylocalhost.com
http:
paths:
- path: /
backend:
serviceName: test-app
servicePort: 5000
错误
error: error validating "test-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];
if you choose to ignore these errors, turn validation off with --validate=false
除了更改 API 版本之外,我没有进行其他更改。
kubectl version
返回:
Client Version: version.InfoMajor:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:30:33Z", GoVersion:"go1.15", Compiler:"gc", Platform:"windows/amd64"
Server Version: version.InfoMajor:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:23:04Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"
【问题讨论】:
【参考方案1】:请尝试以下方法:
% minikube addons enable dashboard
% minikube addons enable metrics-server
然后,将dashboard-ingress.yaml
中的apiVersion
改为:
apiVersion: networking.k8s.io/v1beta1
【讨论】:
嗨,阿卜杜勒。欢迎来到 Stack Overflow,感谢您的贡献。当您的答案被否决时,这可能会令人沮丧。不要让它成为。它只是意味着其他人没有发现这个答案与所提出的问题非常匹配。您可以(如果您愿意)删除您的答案(如果您也同意它不符合标准并且不会帮助他人),或者离开它。两种方式都没有坏处。对比迈出第一步,我期待您为回答其他问题做出贡献。【参考方案2】:我认为这个PR 包含您要询问的更改。
`Ingress` and `IngressClass` resources have graduated to `networking.k8s.io/v1`. Ingress and IngressClass types in the `extensions/v1beta1` and `networking.k8s.io/v1beta1` API versions are deprecated and will no longer be served in 1.22+. Persisted objects can be accessed via the `networking.k8s.io/v1` API. Notable changes in v1 Ingress objects (v1beta1 field names are unchanged):
* `spec.backend` -> `spec.defaultBackend`
* `serviceName` -> `service.name`
* `servicePort` -> `service.port.name` (for string values)
* `servicePort` -> `service.port.number` (for numeric values)
* `pathType` no longer has a default value in v1; "Exact", "Prefix", or "ImplementationSpecific" must be specified
Other Ingress API updates:
* backends can now be resource or service backends
* `path` is no longer required to be a valid regular expression
如果您查看1.19 Ingress doc,看起来新语法是:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
很遗憾,我没有 1.19 集群来测试自己,但我认为这就是您遇到的问题。
【讨论】:
谢谢,看来是对的。希望他们更新高级文档以匹配 他们怎么能在这些配置文件中进行如此重大的更改!无法想象那些负责在 Kubernetes 上维护许多复杂部署结构的噩梦! @lyrio 因为它之前只是测试版,现在是完整版。注意之前是networking.k8s.io/v1beta1
,现在是发布版本networking.k8s.io/v1
它运行良好 - GKE 用户注意 - 入口更新大约需要 5 - 10 分钟,静态 IP 停机
效果很好。谢谢。以上是关于在 Kubernetes Ingress 从 v1beta1 切换到 v1 时出现错误“io.k8s.api.networking.v1.IngressBackend”中的“未知字段“serviceN的主要内容,如果未能解决你的问题,请参考以下文章