<p>Can you help me? I want to deploy Ingres for nodeport. But I can't understand if this possible? </p>

<p>I tried to find some information in Google but I got Ingress for load balancing or some difficult examples Ingress Ruby on rails and etc. </p>

<p>I'll try to provide the simplest example that I can think of below. I will use the <code>nginxdemos/hello</code> docker image for my example. Locally this works as this:</p>

<pre><code>$docker run -p 80:80 -d nginxdemos/hello    
...
$curl -I http://localhost

HTTP/1.1 200 OK
Server: nginx/1.13.8
Date: Tue, 08 Oct 2019 06:14:52 GMT
Content-Type: text/html
Connection: keep-alive
Expires: Tue, 08 Oct 2019 06:14:51 GMT
Cache-Control: no-cache
</code></pre>

<p>Cool. Here is our backend deployment:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-backend
  namespace: java2days
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx-server
  template:
    metadata:
      labels:
        app: nginx-server
    spec:
      containers:
        - name: nginx-server
          image: nginxdemos/hello
          ports:
            - containerPort: 80
              name: server-port
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 15
            periodSeconds: 15
            timeoutSeconds: 3
          readinessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 15
            periodSeconds: 15
            timeoutSeconds: 3
</code></pre>

<p>Shortly we will have 2 replicas of an nginx server. Up and running on nodes somewhere in the cloud:</p>

<pre><code>$kubectl get pods

NAME                            READY   STATUS    RESTARTS   AGE
nginx-backend-dfcdb9797-dnx7x   1/1     Running   0          21m
nginx-backend-dfcdb9797-pnrhn   1/1     Running   0          21m
</code></pre>

<p>Let's create a NodePort service now. Here is the service yaml:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: java2days
spec:
  ports:
    - port: 80
      protocol: TCP
      targetPort: 80
      name: http
  selector:
    app: nginx-server
  type: NodePort
</code></pre>

<p>Note the selector, it matches the backend service. Now it is time for the ingress controller.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress
  namespace: java2days
spec:
  rules:
    - http:
        paths:
          - backend:
              serviceName: nginx-service
              servicePort: 80
            path: /*
</code></pre>

<p>You will have to wait for about 5-10 minutes until GCloud provisions an IP address for this Ingress. Finally it is done, something like this:</p>

<pre><code>$kubectl get ingress

NAME            HOSTS   ADDRESS         PORTS   AGE
nginx-ingress   *       x.y.z.p         80      15m
</code></pre>

<p>From my local machine now:</p>

<pre><code>$curl -I http://x.y.z.p

HTTP/1.1 200 OK
</code></pre>

<p>Great it is working. If you open it in the browser and refresh multiple times you will see that the server ID changes and load balancing works. Additional entry point for reading - <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/ingress" rel="nofollow noreferrer">here</a>.</p>

<p>Do not forget to clean up the resources when you finish experimenting.</p>
