Home > Software design >  accessing service form another pod Kubernetes
accessing service form another pod Kubernetes

Time:06-27

I have two services running in my k8s.
I am trying to access my wallet service from my user service but my curl cmd just returns 504 gateway timeout.

here is my ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: dev-ingress
  namespace: dev
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    # nginx.ingress.kubernetes.io/use-regex: "true"
    # nginx.ingress.kubernetes.io/rewrite-target: /api/v1$uri
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /api/v1/wallet
        pathType: Prefix
        backend:
          service:
            name: wallet-service
            port:
              number: 80
      - path: /api/v1/user
        pathType: Prefix
        backend:
          service:
            name: accounts-service
            port:
              number: 80

this is the way I passed the env in my account service.

http://wallet-service:3007

and I log the URL when hitting my endpoint

curl http://EXTERNAL_IP/api/v1/user/health/wallet

every other non-related endpoint works.

Any help is appreciated

I am running Azure Kubernetes

CodePudding user response:

I have two services running in my k8s.

  1. Do you have an actual K8S service?

    apiVerison: ...
    kind: Service
    
    • Check it with kubectl get svc -A and you should see your services there
  2. Check to see that your pods are exposed to the services

    kubectl get endpoints -A
    
  3. Are you running on a cloud provider (GCP, Azure, AWS, etc), if so check your security configuration as well (NSG for Azure, a security policy for AWS, etc)

  4. Check inner communication :

    # Log into one of the pods 
    kubectl exec -n <namespace> <pod name> sh
    
    # Try to connect to the other service with the FQDN
    curl -sv <servicename>.<namespace>.svc.cluster.local
    

Update:

  • You commented that you are running on Azure, check the desired ports are opened under the NSG.
  • Assuming that you are running AKS you need to find out the MS_xxxx resource and your NSG group will be located under this resource group, edit it and open the desired ports

You are trying to connect to http://wallet-service:3007/api/v1/wallet/health - Where did you get the 3007 port?

  • Related