I have an application running on my own server with kubernetes
. This application is supposed to work as a gateway and has a LoadBalancer
service, which is exposing it to "the world". Now I'd like to connect this application with other applications running within the very same kubernetes cluster
, so they can exchange HTTP requests
with each other.
So let's say that my Gateway app is running on the port 9000
, the app which I'd like to call runs on 9001
. When I make curl my_cluster_ip:9001
it gives me a response. Nevertheless I never know, what the Cluster IP
will be, so I can't implement this to my gateway app.
Use case is typing to the web browser url_of_my_server:9000
-> this will call the gateway -> it sends HTTP Request
to the other app running in the cluster on the port 9001
-> response back to the gateway -> response back to the user.
Where the magic has to happen and how to easily make these two apps to talk with each other, while only one will be exposed to "the world" and the other one will be accessible only from within the cluster?
You can expose your app on port 9001 as a service (lets say myservice
). When you do that myservice.<namespace>.svc.cluster.local
will resolve to IP addres of your app. More Info on DNS here : https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
And then you can access your app within Kubernetes cluster as: http://myservice.<namespace>.svc.cluster.local:9001
You have a couple of options for internal service discovery:
Also note that support for your HTTP proxy setup already exist in Kubernetes; take a look at Ingress and Ingress Controllers.