spec.rules[0].http.backend.servicePort: Invalid value: "80": must contain at least one letter or number (a-z, 0-9)", Error while calling NetworkingV1beta1Api.createNamespacedIngress() api
I am using io.kubernetes:client-java-api:12.0.1 version as a dependency in gradle
Below is my ingress yaml file
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: myserver-userid
namespace: myserver
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: userid-myserver
http:
paths:
- backend:
serviceName: myserver
servicePort: 80
tls:
- hosts:
- userid-myserver
secretName: myserver-tls
with below line I am creating NetworkingV1beta1Ingress object.
NetworkingV1beta1Ingress codeServerV1Ingress = yaml.loadAs(ingressYamlFile, NetworkingV1beta1Ingress.class);
by calling below api I get error
NetworkingV1beta1Ingress namespacedIngress = networkingV1beta1Api.createNamespacedIngress("myserver", codeServerV1Ingress, "true", null, null);
error :
spec.rules[0].http.backend.servicePort: Invalid value: "80": must contain at least one letter or number (a-z, 0-9)
I could see this error is related to IntOrString Class but not sure Why it. is throwing error and. failing the api call ? can someone pls help on this ?
even I tried with both approaches below
approach 1: servicePort: 80
approach 2: servicePort: "80"
I have also done google search on existing issues but none of them were helpful for me.
2
Answers
Try to separate the servicePort and serviceName to service.name and service.port.number or service.port.name
e.g.
backend:
service:
name: myserver
port:
number: 80
For starters, v1beta1 annotation is deprecated and v1 should be used instead. Pathtype should also be specified.
PathType determines the interpretation of the Path matching, and can be one of the following values:
Lastly, the backend service definition has changed. Try the bellow example:
Keep in mind that the backed service, and the ingress must belong to the same namespace.
PS: The first 3 annotations are essential if you will use CertManager to issue valid certificates in the future.