HeadLiness类型的Service
在某些场景中,开发人员可能不想使用Service提供的负载均衡功能,而希望自己来控制负载均衡策略,针对这种情况,kubernetes提供了HeadLiness Service,
这类Service不会分配Cluster IP,如果想要访问service,只能通过service的域名进行查询。
创建
创建service-headliness.yaml
apiVersion: v1 kind: Service metadata: name: service-headliness namespace: dev spec: selector: app: nginx-pod clusterIP: None # 将clusterIP设置为None,即可创建headliness Service type: ClusterIP ports: - port: 80 targetPort: 80
创建并查看
# 创建service [root@master ~]# kubectl create -f service-headliness.yaml # 获取service, 发现CLUSTER-IP未分配 [root@master ~]# kubectl get svc service-headliness -n dev -o wide # 查看service详情 [root@master ~]# kubectl describe svc service-headliness -n dev
查看域名的解析情况
[root@master ~]# kubectl get pod -n dev [root@master ~]# kubectl exec -it pc-deployment-7d7dd5499b-8ld77 -n dev -- cat /etc/resolv.conf 默认规则 service名称.命名空间. svc.cluster.local [root@master ~]# yum -y install bind-utils #产生dig工具 [root@master ~]# dig @10.96.0.10 service-headliness.dev.svc.cluster.local
注:也可用host命令来查看pod的真实ip host service名称 注:下图中myheadless是service名字
参考
黑马B站k8s课程https://www.bilibili.com/video/BV1Qv41167ck/ https://gitee.com/yooome/golang/blob/main/k8s%E8%AF%A6%E7%BB%86%E6%95%99%E7%A8%8B-%E8%B0%83%E6%95%B4%E7%89%88/k8s%E8%AF%A6%E7%BB%86%E6%95%99%E7%A8%8B.md https://www.yuque.com/fairy-era/yg511q/xyqxge标签:HeadLiness,headliness,Service,service,dev,master,类型,root From: https://www.cnblogs.com/gys001/p/16935653.html