0

I have converted my Docker-compose.yml file to Kubernetes MiniKube using Kompose. After the conversion, I was no longer able to see my microservices in my Eureka discovery-service.

I converted the file using the command, 'Kompose convert' on the Docker-compose.yml file.

Here is a before and after comparison of two of my microservices:

Before (docker-compose.yml)

  discovery-service:
    build: ./discovery-service
    image: springcloud/eureka:latest
    container_name: eureka-discovery-server-container
    ports:
      - "8761:8761"
    environment:
        spring.config.import-check.enabled: false

    networks:
        microservices_network:

            aliases:
                - discovery-service-container
                - eureka-discovery-server-container
                - discovery-service

After (discovery-service-deployment.yml)

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe convert -f docker-compose.yml
    kompose.version: 1.28.0 (c4137012e)
  creationTimestamp: null
  labels:
    io.kompose.service: discovery-service
  name: discovery-service
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: discovery-service
  strategy: {}
  template:
    metadata:
      annotations:
        kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe convert -f docker-compose.yml
        kompose.version: 1.28.0 (c4137012e)
      creationTimestamp: null
      labels:
        io.kompose.network/microservices-kubernetes-microservices-network: "true"
        io.kompose.service: discovery-service
    spec:
      containers:
        - env:
            - name: spring.config.import-check.enabled
              value: "false"
          image: springcloud/eureka:latest
          name: eureka-discovery-server-container
          ports:
            - containerPort: 8761
          resources: {}
      restartPolicy: Always
status: {}

After: (discovery-service-service.yml):

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe convert -f docker-compose.yml
    kompose.version: 1.28.0 (c4137012e)
  creationTimestamp: null
  labels:
    io.kompose.service: discovery-service
  name: discovery-service
spec:
  ports:
    - name: "8761"
      port: 8761
      targetPort: 8761
  selector:
    io.kompose.service: discovery-service
status:
  loadBalancer: {}

Before: login-service (docker-compose.yml)

  login-service:
    container_name: login-service-container
    image: springboot-app-login
    restart: always
    build: ./login-service
    ports:
      - "8083:8080"
    depends_on:
      login-db-docker-image:
        condition: service_healthy
      discovery-service:
        condition: service_started
    networks:
        - microservices_network

After: login-service-deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe convert -f docker-compose.yml
    kompose.version: 1.28.0 (c4137012e)
  creationTimestamp: null
  labels:
    io.kompose.service: login-service
  name: login-service
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: login-service
  strategy: {}
  template:
    metadata:
      annotations:
        kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe convert -f docker-compose.yml
        kompose.version: 1.28.0 (c4137012e)
      creationTimestamp: null
      labels:
        io.kompose.network/microservices-kubernetes-microservices-network: "true"
        io.kompose.service: login-service
    spec:
      containers:
        - image: springboot-app-login
          name: login-service-container
          ports:
            - containerPort: 8080
          resources: {}
      restartPolicy: Always
status: {}

After: login-service-service.yml

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe convert -f docker-compose.yml
    kompose.version: 1.28.0 (c4137012e)
  creationTimestamp: null
  labels:
    io.kompose.service: login-service
  name: login-service
spec:
  ports:
    - name: "8083"
      port: 8083
      targetPort: 8080
  selector:
    io.kompose.service: login-service
status:
  loadBalancer: {}

The Eureka discovery service is running on port 8761 and visible in the browser, but there are no services showing at all. It was working fine when I was using docker compose and docker containers. What changed? Any insight would be appreciated.

brohjoe
  • 854
  • 4
  • 17
  • 39
  • 1
    How does the login service know how to contact the discovery service? For an environment closer to what Kubernetes provides, you might try editing the `docker-compose.yml` file to delete all of the `networks:`, `depends_on:`, and `container_name:` blocks – Kubernetes only has a single global network, a Service only has a single name, and there are a couple of layers of auto-generated names derived from a Deployment name. – David Maze Jun 06 '23 at 23:46
  • 1
    to debug, look at `kubectl get svc` to get services. Do you see the other service? Check that the containers are actually running with `kubectl get pods`. i also note there is a dependency on a login-db-docker-image but i don't see anything about it in the code you show. if the discovery service depends on a DB somehow, it needs to be running. – MrE Jun 07 '23 at 00:36
  • @DavidMaze I was wondering about that. I see minikube created a 'default-networkpolicy.yaml' with `kind: NetworkPolicy`, and a 'network-networkpolicy.ymal`. So if I'm hearing you correctly, I can simply delete these configs because K8s uses it's own methodology for networks? As far as the 'depends_on` and 'container_name` is concerned, I don't see where that has effected the resulting K8s config docs. What do you think? I see what you're saying about editing the docker-compose to closely fit K8s requirements though and the point is well taken. – brohjoe Jun 07 '23 at 13:06
  • @MrE : I see all of the containers are not running. I'm attempting to fix that. Discovery service is not dependent on any dbs. Thanks. – brohjoe Jun 07 '23 at 13:28
  • 1
    Kubernetes doesn't have anything like `depends_on:`, and I think Kompose just ignores that. – David Maze Jun 07 '23 at 14:35
  • my guess is your pods fail because they can't reach the discovery service that is not up yet. The compose 'depends_on' makes it so a service won't be started until the dependent service it up, but in k8s, you'll need to do this check yourself, either with an init container waiting for the condition, or by implementing a retry in the main container code. Check the logs of the failing pods to see why they fail to start – MrE Jun 07 '23 at 15:34

0 Answers0