How does kubernetes DNS work and what is the hostname of the service?

6/15/2019

Example, I deployed an ASP.NET Core web api "mydotnetservice1". I tried calling the API using http://mydotnetservice1:5000 but it does not seem to work, is this the correct address?

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: mydotnetservice1
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: mydotnetservice1
    spec:
      containers:
        - image: "mydockerimages/mydotnetservice1"
          imagePullPolicy: Always
          name: mydotnetservice1
          ports:
            - containerPort: 80

-

apiVersion: v1
kind: Service
metadata:
  name: mydotnetservice1
spec:
  type: LoadBalancer
  ports:
  - port: 5000
    targetPort: 80
  selector:
    app: mydotnetservice1
-- 001
asp.net-core
c#
kubernetes

1 Answer

6/15/2019

dns name of the service is in the below format

servicename.namespace.svc.cluster.local

service is virtual. you can use port as 80 in service definition. that way, port can be avoided. in your case, port number is given as 5000. you need to include port number as well to call the service from other pods

-- P Ekambaram
Source: StackOverflow