kuberneteskubernetes-nodeport

How to expose a single REST API to outside cluster in Kubernetes?


I am new to Kubernetes and if I am not wrong, a service can be exposed inside the cluster using ClusterIP, and to the outside world using NodePort or LoadBalancer types. But my requirement is that I have a single container that has few REST APIs. I want that one API (the basic health check API) should be exposed to the outside, and the rest of the APIs should be available only within the cluster (accessible by other nodes). How can I achieve this?


Solution

  • You can keep your service as ClusterIP and use the ingress.

    With ingress and ingress controller, you can setup and expose the desired path outside of cluster.

    Ingress, you can install the Nginx ingress controller and create the ingress resource.

    Read more about the nginx ingress controller setup and ingress reosuce setup.