skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. 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:

    1. Exact: Matches the URL path exactly.
    2. Prefix: Matches based on a URL path prefix split by ‘/’. Matching is done on a path element by element basis. A path element refers is the list of labels in the path split by the ‘/’ separator. A request is a match for path p if every p is an element-wise prefix of p of the request path. Note that if the last element of the path is a substring of the last element in request path, it is not a match (e.g. /foo/bar matches /foo/bar/baz, but does not match /foo/barbaz).
    3. ImplementationSpecific: Interpretation of the Path matching is up to the IngressClass. Implementations can treat this as a separate PathType or treat it identically to Prefix or Exact path types. Implementations are required to support all path types.

    Lastly, the backend service definition has changed. Try the bellow example:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: example-router
      namespace: example-router
      annotations:
        cert-manager.io/cluster-issuer: "letsencrypt-prod"
        #acme.cert-manager.io/http01-edit-in-place: "true"
        #acme.cert-manager.io/http01-ingress-class: "nginx"
        kubernetes.io/ingress.class: "nginx"
    spec:
      tls:
      - hosts:
        - examlpe.com
        - www.examlpe.com
        secretName: example-tls-secret
      rules:
      - host: examlpe.com
        http:
          paths:
          - pathType: ImplementationSpecific
            path: "/"
            backend:
              service:
                name: backend-service
                port: 
                  number: 80
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search