[英]How does kubernetes DNS work and what is the hostname of the service?
Example, I deployed an ASP.NET Core web api "mydotnetservice1".例如,我部署了一个 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?
我尝试使用http://mydotnetservice1:5000调用 API,但它似乎不起作用,这是正确的地址吗?
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服务的 dns 名称采用以下格式
servicename.namespace.svc.cluster.local
service is virtual.服务是虚拟的。 you can use port as 80 in service definition.
您可以在服务定义中使用端口作为 80。 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
在您的情况下,端口号为 5000。您还需要包含端口号以从其他 pod 调用该服务
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.