在 Kubernetes Ingress 从 v1beta1切换到 v1时,在 io.k8s.api.networking.v1.IngresBackend 中获取错误“未知字段“ serviceName”

我有下面的 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 版本之外,我没有做任何其他的改变。

返回:

Client Version: version.Info{Major:"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.Info{Major:"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"}
68773 次浏览

我认为这个 公关包含了你所要求的改变。

`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进入文件,看起来新的语法应该是:

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集群来测试我自己,但是我想这就是你要碰到的。

请尝试以下方法:

% minikube addons enable dashboard
% minikube addons enable metrics-server

然后,将 dashboard-ingress.yaml中的 apiVersion改为:

apiVersion: networking.k8s.io/v1beta1