Search code examples
yamlmicroservicesazure-aks

Routing to Internal IP? AKS


I use an Azure Kubernetes service to provide my microservices. When I log in to my API gateway it works. But when I try to contact another microservice via the Api-Gateway I get an error (500 Internal Server Error). I have also set up a Eureka Naming Server in Kubernetes and all of my provided microservices are registered there. But why can't my API gateway communicate with my microservices? It also works on the local machine.

My Yaml Files

apiVersion: apps/v1
kind: Deployment
metadata:
  name: discoveryservice-front
spec:
  replicas: 1
  selector:
    matchLabels:
      app: discoveryservice-front
  template:
    metadata:
      labels:
        app: discoveryservice-front
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
        - name: discoveryservice-front
          image: containerregistry.azurecr.io/discoveryservice:16
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 250m
              memory: 512Mi
          ports:
          - containerPort: 8762
            name: discovery
            
---
apiVersion: v1
kind: Service
metadata:
  name: eureka
spec:
  type: LoadBalancer
  ports:
  - port: 8762
  selector:
    app: discoveryservice-front
apiVersion: apps/v1
kind: Deployment
metadata:
  name: apigateway-front
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apigateway-front
  template:
    metadata:
      labels:
        app: apigateway-front
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
        - name: apigateway-front
          image: containerregistry.azurecr.io/apigateway:27
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 250m
              memory: 512Mi
          ports:
          - containerPort: 8800
            name: apigateway
            
---
apiVersion: v1
kind: Service
metadata:
  name: apigateway-front
spec:
  type: LoadBalancer
  ports:
  - port: 8800
  selector:
    app: apigateway-front
    
    
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: contacts-back
spec:
  replicas: 1
  selector:
    matchLabels:
      app: contacts-back
  template:
    metadata:
      labels:
        app: contacts-back
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: contacts-back
        image: containerregistry.azurecr.io/contacts:26
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 250m
            memory: 512Mi
        ports:
        - containerPort: 8100
          name: contacts-back
          
---
apiVersion: v1
kind: Service
metadata:
  name: contacts-back
spec:
  ports:
  - port: 8100
  selector:
    app: contacts-back
---


apiVersion: apps/v1
kind: Deployment
metadata:
  name: templates-back
spec:
  replicas: 1
  selector:
    matchLabels:
      app: templates-back
  template:
    metadata:
      labels:
        app: templates-back
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: templates-back
        image: containerregistry.azurecr.io/templates:25
        resources:
         requests:
            cpu: 100m
            memory: 128Mi
         limits:
            cpu: 250m
            memory: 512Mi
        ports:
         - containerPort: 8200
           name: templates-back
---
apiVersion: v1
kind: Service
metadata:
  name: templates-back
spec:
  ports:
  - port: 8200
  selector:
    app: templates-back

All of my microservices run on the same node. My idea may be to reinstall routing in the API gateway. But is it possible to route to internal IPs? Can anyone tell me what I am doing wrong?


Solution

  • Since you are running your API-Gateway inside the cluster, the process should be able to access all other pod using their service definition.

    Assuming that all of your services/deployments are deployed in the same namespace. the api-gateway should be able to reference them by service name

    e.g (fqdn)

    contacts-back.<namespace>.svc.cluster.local:8100