<p>I am attempting to create an NGINX-INGRESS (locally at first, then to be deployed to AWS behind a load-balancer). However I am new to Kubernetes, and I understand the <em>Ingress</em> model for NGINX- the configurations are confusing me as to weather I should be deploying an NGINX-INGRESS <strong><em>Service</em></strong>, <strong><em>Ingress</em></strong> or <strong><em>Both</em></strong></p>

<p>I am working with multiple Flask-Apps I would like to have routed by path (<code>/users</code>, <code>/content</code>, etc.) My services are named <code>user-service</code> on <code>port: 8000</code> (their container port is 8000 as well)</p>

<p>In <a href="https://stackoverflow.com/questions/58604787/two-flask-apps-on-different-paths-with-kubernetes-ingress-resource-nginx">this</a> example an <em>Ingress</em> is defined. However, when I apply an ingress (in the same Namespace as my Flask there is no response from <code>http://localhost</code></p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-name
  namespace: my-namespace
spec:
  rules:
  - http:
      paths:
      - path: /users
        backend:
          serviceName: users-service 
          servicePort: 8000
      - path: /content
        backend:
          serviceName: content-service 
          servicePort: 8000
</code></pre>

<p>Furthermore, looking at the <a href="https://kubernetes.github.io/ingress-nginx/" rel="nofollow noreferrer">nginx-ingress</a> "Deployment" docs, under Docker for Mac (which I assume I can use as I am using <em>Docker</em> on a MacOS) they <a href="https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.30.0/deploy/static/provider/cloud-generic.yaml" rel="nofollow noreferrer">define a Service</a> like so:</p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  externalTrafficPolicy: Local
  type: LoadBalancer
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: http
    - name: https
      port: 443
      protocol: TCP
      targetPort: https

---
</code></pre>

<p>This seems to function for me (When I open "localhost" I get Nginx "not found", but it is a service in a different namespace then my apps- and there is no association between the port 80/443 and my service-ports.</p>

<p>For reference here is one of my deployment/service definitions:</p>

<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:
    name: users-service
    labels:
        app: users-service
    namespace: example
spec:
    replicas: 1
    selector:
        matchLabels:
            app: users-service
    template:
        metadata:
            labels:
                app: users-service
        spec:
            containers:
                - name: users-service
                  image: users-service:latest
                  imagePullPolicy: Never
                  ports:
                  - containerPort: 8000
---
kind: Service
apiVersion: v1
metadata:
  name: users-service
spec:
  selector:
    app: users-service
  ports:
  - protocol: TCP
port: 8000
</code></pre>

<p><strong>Update</strong></p>

<p>I followed a video for setting up an NGINX-Controller+Ingress, here the results, entering "localhost/users" does not work, </p>

<p>describe-ingress:</p>

<pre><code>(base) MacBook-Pro-2018-i9:microservices jordanbaucke$ kubectl describe ingress users-ingress
Name:             users-ingress
Namespace:        default
Address:          
Default backend:  default-http-backend:80 (&lt;error: endpoints "default-http-backend" not found&gt;)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *           
              /users   users-service:8000 (10.1.0.75:8000)
Annotations:  Events:  &lt;none&gt;
</code></pre>

<p>users-service:</p>

<pre><code>(base) MacBook-Pro-2018-i9:microservices jordanbaucke$ kubectl describe svc users-service
Name:              users-service
Namespace:         default
Labels:            &lt;none&gt;
Annotations:       Selector:  app=users-service
Type:              ClusterIP
IP:                10.100.213.229
Port:              &lt;unset&gt;  8000/TCP
TargetPort:        8000/TCP
Endpoints:         10.1.0.75:8000
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

<p>nginx-ingress</p>

<pre><code>(base) MacBook-Pro-2018-i9:microservices jordanbaucke$ kubectl describe svc nginx-ingress
Name:                     nginx-ingress
Namespace:                default
Labels:                   &lt;none&gt;
Annotations:              Selector:  name=nginx-ingress
Type:                     NodePort
IP:                       10.106.167.181
LoadBalancer Ingress:     localhost
Port:                     http  80/TCP
TargetPort:               80/TCP
NodePort:                 http  32710/TCP
Endpoints:                10.1.0.74:80
Port:                     https  443/TCP
TargetPort:               443/TCP
NodePort:                 https  32240/TCP
Endpoints:                10.1.0.74:443
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

<p>Now when I try to enter the combination of <code>NodeIP:NodePort/users</code>, it does not connect? </p>

<p>From inside my <code>nginx-ingress</code> pod, calling:</p>

<p><code>curl 10.1.0.75:8000</code> or <code>curl 10.100.213.229:8000</code> returns results.</p>

jordan.baucke
<p>For nginx or any other ingress to work properly: </p>

<ol>
<li>Nginx ingress controller need to deployed on the cluster</li>
<li>A LoadBalancer or NodePort type service need to be created to expose nginx ingress controller via port 80 and 443 in the same namespace where nginx ingress controller is deployed.LoadBalancer works in supported public cloud(AWS etc). NodePort works if running locally.</li>
<li>ClusterIP type service need to be created for workload pods in the namespace where workload pods are deployed.</li>
<li>Workload Pods will be exposed via nginx ingress and you need to create ingress resource in the same namespace as of the clusterIP service of your workload Pods.</li>
<li>You will use either the LoadBalancer(in case nginx ingress controller was exposed via LoadBalancer) or NodeIP:NodePort(in case Nginx ingress controller was exposed via NodePort) to access your workload Pods.</li>
</ol>

<p>So in this case since docker desktop is being used Loadbalancer type service(ingress-nginx) to expose nginx ingress controller will not work. This needs to be of NodePort type. Once done workload pods can be accessed via <code>NodeIP:NodePort/users</code> and <code>NodeIP:NodePort/content</code>. <code>NodeIP:NodePort</code> should give nginx homepage as well.</p>
