• Headless Service 和Service


    定于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   80/TCP,443/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                         80/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

  • 相关阅读:
    Apache、NGINX支持中文URL
    JS中关于clientWidth offsetWidth scrollWidth 等的含义
    设置apache登陆密码验证
    通过java代码访问远程主机
    win7
    Netty从没听过到入门 -- 服务器端详解
    分块分段
    数论-佩尔方程
    数论-毕达哥拉斯三元组
    HDU 5613-Baby Ming and Binary image
  • 原文地址:https://www.cnblogs.com/kevincaptain/p/10600733.html
Copyright © 2020-2023  润新知