集群内访问(clusterip)

集群内访问(ClusterIP)

1. 操作场景

集群内访问表示工作负载暴露给同一集群内其他工作负载访问的方式,可以通过“集群内部域名”访问。
集群内部域名格式为“<服务名称>.<工作负载所在命名空间>.svc.cluster.local:<端口号>”,例如“nginx.default.svc.cluster.local:80”。

2. 创建Service

操作详情请参见 创建Service
ClusterIP类型的Service创建后会自动从Service CIDR中分配一个IP以提供服务发现。

3. 访问Service

在集群内的容器上访问Service。
创建一个Pod并进入到容器内,使用curl命令访问Service的IP:Port或域名,如下所示。
其中域名后缀可以省略,在同个命名空间内可以直接使用<服务名称>:<端口号>访问,如:nginx-clusterip:8080,跨命名空间可以使用<服务名称>.<工作负载所在命名空间>:<端口号>访问,如:nginx-clusterip.default:8080。

curl 10.247.74.52:8080 
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
curl nginx-clusterip.default.svc.cluster.local:8080
...
<h1>Welcome to nginx!</h1>
...
curl nginx-clusterip.default:8080
...
<h1>Welcome to nginx!</h1>
...
curl nginx-clusterip:8080
...
<h1>Welcome to nginx!</h1>
...

4. Headless Service

创建ClusterIP类型的Service时,若勾选开启Headless Service,Service将没有固定的IP地址,访问Service的域名时会通过DNS返回所有的后端Pod实例的IP地址,需要采用DNS负载均衡来实现对后端的负载均衡。
Headless Service更多详情请参见 Kubernetes官网文档

个结果匹配 ""

    无结果匹配 ""