<p>I am setting up NGINX ingress controller on  AWS EKS. </p>

<p>I went through k8s Ingress resource and it is very helpful to understand we map LB ports to k8s service ports with e.g file def. I installed nginx controller till <a href="https://kubernetes.github.io/ingress-nginx/deploy/#prerequisite-generic-deployment-command" rel="nofollow noreferrer">pre-requisite step</a>. Then the tutorial directs me to create an <strong>ingress</strong> resource.</p>

<p><a href="https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/#create-an-ingress-resource" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/#create-an-ingress-resource</a></p>

<p>But below it is telling me to apply a <strong>service</strong> config. I am confused with this provider-specific step. Which is different in terms of <code>kind, version, spec</code> definition  (Service vs Ingress).</p>

<p><a href="https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/aws/service-l7.yaml" rel="nofollow noreferrer">https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/aws/service-l7.yaml</a></p>

<p>I am missing something here?</p>

<p>This is a concept that is at first a little tricky to wrap your head around. The Nginx ingress controller is nothing but a service of type <code>LoadBalancer</code>. What is does is be the public-facing endpoint for your services. The IP address assigned to this service can route traffic to multiple services. So you can go ahead and define your services as <code>ClusterIP</code> and have them exposed through the Nginx ingress controller.</p>
<p>Here's a diagram to portray the concept a little better:
<a href="https://i.stack.imgur.com/xq4YO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xq4YO.png" alt="nginx-ingress" /></a>
<a href="https://www.nginx.com/blog/announcing-nginx-ingress-controller-for-kubernetes-release-1-3-0/" rel="noreferrer">image source</a></p>
<p>On that note, if you have acquired a static IP for your service, you need to assign it to your Nginx ingress-controller. So what is an ingress? Ingress is basically a way for you to communicate to your Nginx ingress-controller how to direct traffic incoming to your LB public IP. So as it is clear now, you have one loadbalancer service, and multiple ingress resources. Each ingress corresponds to a single service that can change based on how you define your services, but you get the idea.</p>
<p>Let's get into some yaml code. As mentioned, you will need the ingress controller service regardless of how many ingress resources you have. So go ahead and apply <a href="https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/aws/service-l7.yaml" rel="noreferrer">this code</a> on your EKS cluster.</p>
<p>Now let's see how you would expose your pod to the world through Nginx-ingress. Say you have a <code>wordpress</code> deployment. You can define a simple <code>ClusterIP</code> service for this app:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: ${WORDPRESS_APP}
  namespace: ${NAMESPACE}
  name: ${WORDPRESS_APP}
spec:
  type: ClusterIP
  ports:
  - port: 9000
    targetPort: 9000
    name: ${WORDPRESS_APP}
  - port: 80
    targetPort: 80
    protocol: TCP
    name: http
  - port: 443
    targetPort: 443
    protocol: TCP
    name: https
  selector:
    app: ${WORDPRESS_APP}
</code></pre>
<p>This creates a service for your <code>wordpress</code> app which is not accessible outside of the cluster. Now you can create an ingress resource to expose this service:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  namespace: ${NAMESPACE}
  name: ${INGRESS_NAME}
  annotations:
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: &quot;true&quot;
spec:
  tls:
  - hosts:
    - ${URL}
    secretName: ${TLS_SECRET}
  rules:
  - host: ${URL}
    http:
      paths:
      - path: /
        backend:
          serviceName: ${WORDPRESS_APP}
          servicePort: 80
</code></pre>
<p>Now if you run <code>kubectl get svc</code> you can see the following:</p>
<pre><code>NAME                      TYPE          CLUSTER-IP      EXTERNAL-IP    PORT(S)                   AGE
wordpress                 ClusterIP     10.23.XXX.XX   &lt;none&gt;         9000/TCP,80/TCP,443/TCP   1m
nginx-ingress-controller  LoadBalancer  10.23.XXX.XX    XX.XX.XXX.XXX  80:X/TCP,443:X/TCP   1m
</code></pre>
<p>Now you can access your <code>wordpress</code> service through the URL defined, which maps to the public IP of your ingress controller LB service.</p>
