Access service api exposed as clusterIP in kubernete

5/29/2019

I have two application, both deployed in same cluster.

Now from web, there is an ajax request to get data from api, but it always return 502 Connection refused.

here is my jquery code (web).

$.get("http://10.43.244.118/api/users", function (data) {
        console.log(data);
        $('#table').bootstrapTable({
            data: data
        });
    });

Note: when I change the service type to LoadBalancer from ClusterIP then it works fine.

-- Programmer
c#
docker
google-cloud-platform
google-kubernetes-engine
kubernetes

2 Answers

5/29/2019
1\Ajax is a front-end call to api.
2\The front-end call is to directly communicate with the user(Browser) and the called end and the api service.
3\ ClusterIP is internal to the cluster,User(Browser) cannot communicate with it.
4\ NodePort and LoadBalancer can expose the internal network, of course, it can be accessed normally.
-- lmlmvxi
Source: StackOverflow

5/29/2019

ClusterIP services (usually) only work within the cluster. You can technically make your CNI address space available externally, but that is rare and you probably shouldn't count on it. The correct way to expose something outside the cluster is either a NodePort service or a LoadBalancer (which is a NodePort plus a cloud load balancer).

-- coderanger
Source: StackOverflow