kubectl apply ingress: 未知字段错误
kubectl apply ingress: Unknown field error
我的入口是:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: mongoexpress-ingress
spec:
rules:
- host: mylocalmongoexpress.com
http:
paths:
- backend:
serviceName: mongoexpress-service
servicePort: 8081
当我 运行 'kubectl apply -f mongoexpress-ingress.yaml' 时,我得到错误:
error: error validating "mongoexpress-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]; if you
choose to ignore these errors, turn validation off with
--validate=false
通过在线资源,我找不到 yaml 文件中的问题。
那么我在这里错过了什么?
您似乎混用了 Ingress 版本。您声明了 networking.k8s.io/v1, but your block of YAML corresponds to networking.k8s.io/v1beta1 - 从 1.22
.
起不再可用
v1beta1
- backend:
serviceName: mongoexpress-service
servicePort: 8081
v1
- backend:
service:
name: mongoexpress-service
port:
number: 8081
入口规范 has changed 从 v1beta1 到 v1。尝试:
...
spec:
rules:
- host: mylocalmongoexpress.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: mongoexpress-service
port:
number: 8081
作为其他答案的补充,在这种情况下,您始终可以使用 kubectl explain
,如果您尝试这样做:kubectl explain ingress.spec.rules.http.paths.backend.service --api-version=networking.k8s.io/v1
那么您将得到:
FIELDS:
name <string> -required-
Name is the referenced service. The service must exist in the same
namespace as the Ingress object.
port <Object>
Port of the referenced service. A port name or port number is required for
a IngressServiceBackend.
通过这种方式,您可以轻松找到哪些字段可用于哪个 API 版本的哪个资源。
我的入口是:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: mongoexpress-ingress
spec:
rules:
- host: mylocalmongoexpress.com
http:
paths:
- backend:
serviceName: mongoexpress-service
servicePort: 8081
当我 运行 'kubectl apply -f mongoexpress-ingress.yaml' 时,我得到错误:
error: error validating "mongoexpress-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]; if you choose to ignore these errors, turn validation off with --validate=false
通过在线资源,我找不到 yaml 文件中的问题。
那么我在这里错过了什么?
您似乎混用了 Ingress 版本。您声明了 networking.k8s.io/v1, but your block of YAML corresponds to networking.k8s.io/v1beta1 - 从 1.22
.
v1beta1
- backend:
serviceName: mongoexpress-service
servicePort: 8081
v1
- backend:
service:
name: mongoexpress-service
port:
number: 8081
入口规范 has changed 从 v1beta1 到 v1。尝试:
...
spec:
rules:
- host: mylocalmongoexpress.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: mongoexpress-service
port:
number: 8081
作为其他答案的补充,在这种情况下,您始终可以使用 kubectl explain
,如果您尝试这样做:kubectl explain ingress.spec.rules.http.paths.backend.service --api-version=networking.k8s.io/v1
那么您将得到:
FIELDS:
name <string> -required-
Name is the referenced service. The service must exist in the same
namespace as the Ingress object.
port <Object>
Port of the referenced service. A port name or port number is required for
a IngressServiceBackend.
通过这种方式,您可以轻松找到哪些字段可用于哪个 API 版本的哪个资源。