Accessing a micro service created inside a kubernetes cluster (Laravel/Lumen PHP)

Viewed 149

I am having some troubles understanding and getting this to work.

So basically I have created an API Gateway that receives flow from the outside world, this one created with Lumen (PHP) and inside a kubernetes cluster, and I want to access another micro service that is inside the same kubernetes cluster, also a Lumen and using PHP which goes by the name microinquilino-service. I am using Google Cloud Platform to do so. I am able to reach the micro service but when I try to navigate threw the menus in the micro service I can't reach another page inside this micro service because it keeps saying that " microinquilino-service:8081/payment", that is in the address, does not exist.

It seems like this address does not exist and I dont know how can I do to make it work so that i can navigate threw my micro service without any trouble.

I am currently using the curl library to make a call to this service just by doing so :

apiGatewayController.php

    public function showCurrentUser(Request $request)
{
    
    $ch = curl_init();

    
    curl_setopt($ch, CURLOPT_URL, "http://microinquilino-service:8081/");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    
    curl_exec($ch);

    curl_close($ch);
}

All help would be much appreciated at this point ! Thank you in advance.

1 Answers

Your PHP application pod/container would need to be deployed to the same namespace as your microinquilino-service service. If they live in different namespaces, your PHP app won't find that service.

The service would need to be defined as:

apiVersion: v1
kind: Service
metadata: 
  name: microinquilino-service
  namespace: my-namespace # Same NS as the PHP app
spec:
  selector:
    app: microinquilino
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081
Related