Exposing a service in Kubernetes using nginx reverse proxy
Asked Answered
R

2

14

I am new to Kubernetes and wanted to understand how I can expose a service running in Kubernetes to the outside world. I have exposed it using a NodePort on the cluster. So, for example: A service exposes port 31234 on the host and I can get to the service from another server through https://kubeserverIP:31234.

What I want to achieve is serve this service through nginx (on a different server, out of Kube control) via a url,say, http://service.example.com. I have tried deploying nginx with an upstream pointing to the service but that is not working and get a bad gateway error.

Is there something which I am missing here? Or is there a neater way of achieving this.

I have a baremetal installation of Kubernetes cluster and have no access to gce load balancer or other vendor LBs.

Thanks

Receptionist answered 11/7, 2018 at 14:53 Comment(0)
R
9

Thanks for pointing in the right direction.

Essential steps broadly were:

  1. Create an app and its service definition.

  2. Create a namespace for ingress.

  3. Create a default backend deployment and service for redirecting all requests not defined in Ingress rules. Create these in the ingress space
  4. Create the nginx ingress controller deployment.
  5. Create RBAC rules.
  6. Finally create the ingress rule for the applications with the paths and the ports.

Found a very useful guide which explained things in details: https://akomljen.com/kubernetes-nginx-ingress-controller/

Receptionist answered 13/7, 2018 at 12:52 Comment(0)
P
9

You're almost there! Your next step will be to setup a ingress controller. There is an NGINX Ingress controller plugin that you can checkout here.

Edit: Here's an example configuration: https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/complete-example

Polyptych answered 11/7, 2018 at 18:11 Comment(1)
In the complete example link I don't see where ngnix is configured.Chace
R
9

Thanks for pointing in the right direction.

Essential steps broadly were:

  1. Create an app and its service definition.

  2. Create a namespace for ingress.

  3. Create a default backend deployment and service for redirecting all requests not defined in Ingress rules. Create these in the ingress space
  4. Create the nginx ingress controller deployment.
  5. Create RBAC rules.
  6. Finally create the ingress rule for the applications with the paths and the ports.

Found a very useful guide which explained things in details: https://akomljen.com/kubernetes-nginx-ingress-controller/

Receptionist answered 13/7, 2018 at 12:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.