skip to Main Content

What am I going wrong in the below query?

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /nginx
        backend:
          serviceName: nginx
          servicePort: 80

The error I am getting:

error validating "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

5

Answers


  1. Ingress spec has changed since updated to v1. Try:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: nginx-ingress
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - http:
          paths:
          - path: /nginx
            pathType: ImplementationSpecific
            backend:
              service:
                name: nginx
                port:
                  number: 80
    
    Login or Signup to reply.
  2. ServiceName and ServicePort no keywords are available like that in v1 .

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: nginx-ingress
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - http:
          paths:
          - path: /nginx
            backend:
              service:
                name: nginx
                port:
                  number: 8080
    
    Login or Signup to reply.
  3. service name and service port syntax is incorrect. Follow the below sample

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: minimal-ingress
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      ingressClassName: nginx-example
      rules:
      - http:
          paths:
          - path: /testpath
            pathType: Prefix
            backend:
              service:
                name: test
                port:
                  number: 80
    
    Login or Signup to reply.
  4. According to this documentation you need to change ServiceName and ServicePort.

    Each HTTP rule contains (…) a list of paths (for example, /testpath), each of which has an associated backend defined with a service.name and a service.port.name or service.port.number. Both the host and path must match the content of an incoming request before the load balancer directs traffic to the referenced Service.

    Here is your yaml file with corrections:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: nginx-ingress
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - http:
          paths:
          - path: /nginx
            backend:
              service:
                name: nginx
                port:
                  number: 8080
    
    Login or Signup to reply.
  5. apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
    name: nginx-ingress
    annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
    rules:

    • http:
      paths:

      • path: /nginx
        pathType: ImplementationSpecific
        backend:
        service:
        name: nginx
        port:
        number: 80
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search