I have ingress as:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: mongoexpress-ingress
spec:
rules:
- host: mylocalmongoexpress.com
http:
paths:
- backend:
serviceName: mongoexpress-service
servicePort: 8081
When I run 'kubectl apply -f mongoexpress-ingress.yaml', I get error:
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
Going through online resources, I couldn't find issue in yaml file.
So what am I missing here?
CodePudding user response:
Ingress specification has changed from v1beta1 to v1. Try:
...
spec:
rules:
- host: mylocalmongoexpress.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: mongoexpress-service
port:
number: 8081
CodePudding user response:
As an addition to other answers, you can always use kubectl explain
in such situations, if you try to do this: kubectl explain ingress.spec.rules.http.paths.backend.service --api-version=networking.k8s.io/v1
then you'll get:
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.
This way you can easily find what fields are available for which resource in which API version.
CodePudding user response:
You seems to mix Ingress versions. You declared networking.k8s.io/v1, but your block of YAML corresponds to networking.k8s.io/v1beta1 - which is no longer available as of 1.22
.
v1beta1
- backend:
serviceName: mongoexpress-service
servicePort: 8081
v1
- backend:
service:
name: mongoexpress-service
port:
number: 8081