<p>What am I going wrong in the below query?</p>
<pre class="lang-yaml prettyprint-override"><code>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
</code></pre>
<p>The error I am getting:</p>
<pre><code>error validating &quot;ingress.yaml&quot;: error validating data: [ValidationError(Ingress.spec.rules[0].http.paths[0].backend): unknown field &quot;serviceName&quot; in io.k8s.api.networking.v1.IngressBackend, ValidationError(Ingress.spec.rules[0].http.paths[0].backend): unknown field &quot;servicePort&quot; in io.k8s.api.networking.v1.IngressBackend]; if you choose to ignore these errors, turn validation off with
--validate=false
</code></pre>

Subhajit Das
<p>According to <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">this documentation</a> you need to change ServiceName and ServicePort.</p>
<blockquote>
<p>Each HTTP rule contains (...) a list of paths (for example,  <code>/testpath</code>), each of which has an associated backend defined with a  <code>service.name</code>  and a  <code>service.port.name</code>  or  <code>service.port.number</code>. Both the host and path must match the content of an incoming request before the load balancer directs traffic to the referenced Service.</p>
</blockquote>
<p>Here is your yaml file with corrections:</p>
<pre class="lang-yaml prettyprint-override"><code>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
</code></pre>
