Nginx routing for kubernetes services

0 votes
I am having same requirements like metioned in this post - https://tech.holidayextras.com/routing-to-internal-kubernetes-services-using-proxies-and-ingress-controllers-e7eb44954d53

But I am not sure of what is that ipaddresses of backends mentioned there. I assumed it is the ips of my master and worker nodes in my cluster

My kubernetes has master node ip as 10.118.6.35 and worker node ip as 10.118.2.215 which are AWS ec2 instances.

So when I configured like below in my nginx.conf(please refer below), I am getting index.html rendered when I do
curl https://10.118.6.35
As well from my browser it is working fine.

But when I do https://10.118.6.35/hello-kenzan
I am getting nginx error page default 404 page
But I expect to route it to my kubernetes services running in NodePort 80:30854

I have followed steps as mentioned in that post.
FYI, I am showing the echo-ing.yaml below -

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: echomap
      annotations: {
        'kubernetes.io/ingress.class': nginx
       }
    spec:
      rules:
      - host: ip-10-118-6-35.ec2.internal
        http:
          paths:
          - path: /hello-kenzan
            backend:
               service and: hello-kenzan
               service port: 80

And below is nginx.conf -

    http {
           ssl_certificate ...
            ....
            ....
      server {
       listen     443 SSL;
       server_name www.ip-10.118-6-35.ec2.internal.com;
       root /usr/share/nginx/html;
       ssl_certificate ...
       ...
       ...
       include /etc/nginx/default.d/*.conf;
    
       location / {
       }
       error_page 404 /404.html;
          location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
          location = /50x.html {
        }
    }
    upstream backend_nodes {
        server 10.118.6.35:31001;
        server 10.118.2.215:31001;
      }
    upstream backend_nodes_ssl {
        server 10.118.6.35:32001;
        server 10.118.2.215:32001;
      }
    server {
        listen 80;
        server_name backends.nodes;
         location / {
           proxy_pass https://backend_nodes;
          }
       }
     server {
        listen 443;
        server_name backends.nodes.ssl;
         location / {
           proxy_pass https://backend_nodes_ssl;
          }
       }
    }

Please suggest what must go in the backend nodes ip.
Feb 7 in Kubernetes by anonymous

recategorized Feb 8 by Vardhan 62 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
Best answer

Hey, backend is a service running on your cluster and when asked about the IP address of the backend, it refers to the IP address of the service. To get this IP addres execute the following command:

kubectl get svc

It'll list down all the services with their clusterIP and external IP's. If used the service NodePort, the service will not have any external IP. In such a case use the clusterIP to access the service. If you've used LoadBalancer as your service type then you can access the service using the ExternalIP. 

answered Feb 8 by Kalgi
• 36,220 points
Thanks for the reply..

**Update**

Hey finally made it to work when I try with IP address from browser instead of DNS name -

https://10.118.6.35/hello-kenzan  <- this working now
https://myservice.myorg.com/hello-kenzan <- this not working by giving nginx error page temporarily unavailable.

But https://myservice.myorg.com <- works by taking to welcome to nginx index page.

This is my modified nginx.conf -

````
 
 http {
           ssl_certificate ...
            ....
            ....

server {
       listen     80;
       server_name ip-10.118-6-35.ec2.internal;
       root /usr/share/nginx/html;
       
       include /etc/nginx/default.d/*.conf;
    
       location / {
       }
       location /hello-kenzan {
           proxy_pass https://backend_nodes;
          }
       error_page 404 /404.html;
          location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
          location = /50x.html {
        }
    }
      server {
       listen     443 SSL;
       server_name ip-10.118-6-35.ec2.internal;
       root /usr/share/nginx/html;
       ssl_certificate ...
       ...
       ...
       include /etc/nginx/default.d/*.conf;
    
       location / {
       }
       location /hello-kenzan {
           proxy_pass https://backend_nodes_ssl;
       }
       error_page 404 /404.html;
          location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
          location = /50x.html {
        }
    }
    upstream backend_nodes {
        server 10.96.88.237:80
      }
    upstream backend_nodes_ssl {
        server 10.96.88.237:443
      }
   
  }
  
 ````

Any thoughts??
Ahh, that looks good. Exposing the service on a particular port made it work.
Yeah thanks again now DNS also is working!

Related Questions In Kubernetes

0 votes
2 answers

DNS does not resolve with NGINX in Kubernetes

adding to @kalgi's answer Using just the hostname ...READ MORE

answered Aug 30, 2018 in Kubernetes by Nilesh
• 6,900 points
286 views
0 votes
1 answer

Unable to get cgroup stats for docker and kubelet services

Try and start kubelet with the following ...READ MORE

answered Sep 3, 2018 in Kubernetes by DareDev
• 6,670 points
113 views
0 votes
1 answer

Forcing ssl for Kubernetes Ingress on GKE

https://github.com/kubernetes/ingress-gce#frontend-https If you want to block http, you ...READ MORE

answered Sep 6, 2018 in Kubernetes by ajs3033
• 7,080 points
797 views
0 votes
1 answer

Customize the routing logic in kubernetes ingress controller

Try building your own customized image based on ...READ MORE

answered Sep 7, 2018 in Kubernetes by Kalgi
• 36,220 points
54 views
0 votes
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17 in Others by anonymous
681 views
0 votes
3 answers

Nginx reverse proxy URL getting rewritten

 take a look at  nginx.ingress.kubernetes.io/app-root and  nginx.ingress.kubernetes.io/rewrite-target annotations(https://kubernetes.github.io/.../nginx.../annotations/). I'm not sure ...READ MORE

answered Mar 6 in Kubernetes by Madhu
335 views
0 votes
2 answers

single point of entry for multiple services in kubernetes ingress

I tried having something similar too. Deployment apiVersion: extensions/v1beta1 kind: ...READ MORE

answered Sep 7, 2018 in Kubernetes by Hannah
• 14,080 points
55 views
0 votes
1 answer

Disable SSL redirect for Kubernetes NGINX ingress

Adding ingress.kubernetes.io/ssl-redirect: "false" to annotations will disable the SSL redirect: apiVersion: extensions/v1beta1 kind: ...READ MORE

answered Sep 12, 2018 in Kubernetes by Kalgi
• 36,220 points
1,037 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.