Search code examples
springspring-bootdockerkubernetesmicroservices

Microservice deloyed on kubernetes but not giving the desired result


I have successfully deployed a microservice[spring app] on google kubernetes cloud engine.But the endpoint is not working.

Dockerfile enter image description here

deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
 name: user-management-deployment
 labels:
  app: happy-paws  
spec:
 replicas: 3
 selector:
  matchLabels:
   name: user-management-deployment
   app: happy-paws
 template:
  metadata:
   name: user-management-deployment
   labels:
    name: user-management-deployment
    app: happy-paws
  spec:
   containers:
    - name: user-management
      image: docker/user-management
      ports:
       - containerPort: 9106

Service.yml

apiVersion: v1
kind: Service
metadata:
  name: user-management
  labels:
   name: user-management-service
   app: happy-paws
spec:
 type: LoadBalancer
 ports:
  - port: 9106
    targetPort: 9106
 selector:
  name: user-management-pod
  app: happy-paws

application.properties enter image description here please help me in understanding the problem.

UPDATE:

After updating the port, the application started working

Services that are up: user-order-detail LoadBalancer kubernetes ClusterIP order-management LoadBalancer user-management LoadBalancer

user-order-detail hits an endpoint to retrieve all users. I am getting this error :No matches for the virtual host name :user-management**

String url = "user-management/user";
        InstanceInfo instance = eurekaClient.getNextServerFromEureka("user-management", false);
        Object response = restTemplate.getForObject(instance.getHomePageUrl() + url +"/" + userId, Object.class);

Solution

  • Try to understand what service means in kubernetes terminology. On a high level this can be explained as a way to expose your application which is running inside a container (which is running inside a pod(which is running inside a network)) to the external world.

    Each of these blocks can have individual network of their own. Hence concept of Service was introduced. This way you can expose what port of the container needs to be exposed to the world and how it needs to be exposed(Service type, which in your case is LoadBalancer).

    So if you need to access the application running on port 9106 inside the container you need to expose that port.

    spec:
     type: LoadBalancer
     ports:
      - port: 9106
        targetPort: 9106