Kubernetes – Curl works on service IP but not service name

9/19/2020

I am new to kubernetes so I apologize if I have skipped some obvious steps or am not clear with my question.

I have defined a service game-app-service and a deployment game-app-deployment. Both of these are up and running fine.

I am trying to route requests from an API Gateway service (Ambassador) to this service. When trying to curl a game-app-service endpoint from the Ambassador pod, I have discovered that I always receive empty replies and it connects to an IP that is not the service ip. However, if I swap out game-app-service with the ip address of the service and the port it is listening on:

curl -v -X POST 10.102.142.157:8084/api/test

Everything works correctly and I get the expected response from the server.

Something I noticed is curl -v -X POST game-app-service/api/test resolves to the same IP as curl -v -X POST random/api/test– 92.242.140.21 port 80. This leads me to believe that something is wrong with my DNS resolution. However, I have verified that my core-dns pods are up and running, so I am not sure why that might be.

Below, I have listed my configs for my service and deployment for reference:

apiVersion: v1
kind: Service
metadata:
  name: game-app-service
spec:
  selector:
    app: game-app-deployment
  ports:
    - protocol: TCP
      port: 8084
      targetPort: 8084
apiVersion: apps/v1
kind: Deployment
metadata:
  name: game-app-deployment
  labels:
    app: game-app-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: game-app-deployment
  template:
    metadata:
      labels:
        app: game-app-deployment
    spec:
      containers:
      - name: game-service-app
        image: weflop/game-service-app
        imagePullPolicy: Never
        ports:
        - containerPort: 8084

Does anyone have any ideas why I cannot use my service name in place of the IP Address?

UPDATE:

Running wget -O- game-service-app gives me a HTTP status of 200 but a response of:

 [<=>   
                                                                                                           ]       0  --.-KB/s               <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="refresh" content="0;url=https://searchassist.verizon.com/main?ParticipantID=euekiz39ksg8nwp7iqj2fp5wzfwi5q76&FailedURI=http%3A%2F%2Fgame-service-app%2F&FailureMode=1&Implementation=&AddInType=4&Version=pywr1.0&ClientLocation=us"/><script type="text/javascript">url="https://searchassist.verizon.com/main?ParticipantID=euekiz39ksg8nwp7iqj2fp5wzfwi5q76&FailedURI=http%3A%2F%2Fgame-service-app%2F&FailureMode=1&Implementation=&AddInType=4&Version=pywr1.0&ClientLocation=us";if(top.location!=location){var w=window,d=document,e=d.documentElement,b=d.body,x=w.innerWidth||e.clientWidth||b.clientWidth,y=w.innerHeight||e.clientHeight||b.clientHeight;url+="&w="+x+"&h="+y;}-                                                      [ <=>    

Indicating a failed DNS lookup.

-- user2779450
ambassador
google-cloud-dns
kube-dns
kubernetes
service-discovery

1 Answer

9/21/2020

Turns out, the issue was that my API Gateway was in a separate namespace than my services and that was causing problems. By specifying "game-service-app.<my-namespace>" whenever referencing the service, I was able to resolve this.

-- user2779450
Source: StackOverflow