简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM