Headless Service 和Service
2024-10-14 03:06:27
定于spec:clusterIP: None
还记得Service的Cluster IP是做什么的吗?对,一个Service可能对应多个EndPoint(Pod),client访问的是Cluster IP,通过iptables规则转到Real Server,从而达到负载均衡的效果(实现原理请见这里)。如下:
有头service
kubectl get service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-service 10.107.124.218 192.168.128.158 /TCP,/TCP 1d
kubectl describe service nginx-service
Name: nginx-service
Namespace: default
Labels:
Selector: component=nginx
Type: ClusterIP
IP: 10.107.124.218
External IPs: 192.168.128.158
Port: nginx-http 80/TCP
Endpoints: 10.244.2.9:80
Port: nginx-https 443/TCP
Endpoints: 10.244.2.9:443
nslookup nginx-service.default.svc.cluster.local 10.96.0.10 #这个ip为k8s dns的ip
Server: 10.96.0.10
Address: 10.96.0.10#53 Name: nginx-service.default.svc.cluster.local
Address: 10.107.124.218
虽然service有2个endpoint,但是dns查询时只会返回service的地址。具体client访问的是哪个Real Server,是由iptables来决定的。
无头service
kubectl get service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx None /TCP 1h
kubectl describe service nginx
Name: nginx
Namespace: default
Labels: app=nginx
Selector: app=nginx
Type: ClusterIP
IP: None
Port: web 80/TCP
Endpoints: 10.244.2.17:80,10.244.2.18:80 #通过web获取到pod的ip地址
nslookup nginx.default.svc.cluster.local 10.96.0.10
Server: 10.96.0.10
Address: 10.96.0.10#53 Name: nginx.default.svc.cluster.local
Address: 10.244.2.17
Name: nginx.default.svc.cluster.local
Address: 10.244.2.18
dns查询会如实的返回2个真实的endpoint
最新文章
- 基于HT for Web 3D技术快速搭建设备面板
- ubuntu 远程开机
- PHPExcel 类
- margin负值的使用
- NLog 安装使用
- 解决win service 2003 IIS发布Gis网站后,访问地图服务出错,无法正常打开而且 事件查看器出现错误提示。
- Git/Github 教程
- block的修饰词为什么选用copy
- 关于jquery ajax跨域请求获取response headers问题
- Error Code: 1175. You are using safe update mode and you tried to update a table
- Android EditText常用属性
- C#设计模式(17)——观察者模式
- lwip协议栈移植(1)
- tomcat one connection one thread one request one thread
- C语言 - 栈和单链表的实现
- MQTT 嵌入式端通讯协议解析(转)
- MySQL5.7修改默认密码、随机密码
- Assetbundle创建与加载
- java图片压缩(Thumbnails)
- 如何在osx的终端下使用字典