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 8, 2019 in Kubernetes by anonymous

recategorized Feb 8, 2019 by Vardhan 1,652 views

1 answer to this question.

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, 2019 by Kalgi
• 52,350 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
• 7,060 points
5,609 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,890 points
5,103 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,300 points
4,221 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
• 52,350 points
1,323 views
+1 vote
1 answer
0 votes
3 answers

Nginx reverse proxy URL getting rewritten

Hey @Gopi, try your ingress probably like ...READ MORE

answered Feb 12, 2019 in Kubernetes by Kalgi
• 52,350 points
4,711 views
0 votes
1 answer

Kubernetes nginx-ingress TLS issue

You have to create a secret named test-secret. ➜ ...READ MORE

answered Sep 11, 2018 in Kubernetes by Kalgi
• 52,350 points
1,969 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
• 18,520 points
2,676 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
• 52,350 points
7,661 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP