Headless Service
有时不需要或不想要负载均衡,以及单独的 Service IP 。遇到这种情况,可以通过指定 Cluster
IP(spec.clusterIP) 的值为 “None” 来创建 Headless Service 。这类 Service 并不会分配 Cluster IP, kube-proxy 不会处理它们,而且平台也不会为它们进行负载均衡和路由
1 2 3 4 5 6 7 8 9 10 11 12 13
| apiVersion: v1 kind: Service metadata: name: myapp namespace: default spec: selector: app: myapp clusterIP:"None" ports: - name: http port: 80 targetPort: 80
|
svc一旦创建成功后,会被写入到 coredns 中
他的写入的格式体是:svc名称 + 当前命名空间 + 当前集群的域名(集群域名我没没改过,默认就是svc.cluser.local. ) 通过我们当前的coredns的地址进行解析出一个域名
1 2 3
| dig -t A myapp-headservice.default.svc.cluster.local. @10.244.0.34 dig命令需要安装 yum -y install bind-utils
|