6.2.2 向Service对象请求服务

Service资源的默认类型为ClusterIP,它仅能接收来自集群中的Pod对象中的客户端程序的访问请求。下面创建一个专用的Pod对象,利用其交互式接口完成访问测试。为了简单起见,这里选择直接创建一个临时使用的Pod对象作为交互使用的客户端进行,它使用CirrOS镜像,默认的命令提示符为“/#”:

**[terminal]
**[delimiter $ ]**[command kubectl run cirros-$RANDOM --rm -it --image=cirros -- sh]
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
If you don't see a command prompt, try pressing enter.
/ #

CirrOS是设计用来进行云计算环境测试的Linux微型发行版,它拥有HTTP客户端工具curl等。

而后,在容器的交互式接口中使用curl命令对myapp-svc服务的ClusterIP(10.233.16.105)和Port(80/tcp)发起访问请求测试:

**[terminal]
**[delimiter / # ]**[command curl http://10.233.16.105:80]
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>

myapp容器中的“/hostname.html”页面能够输出当前容器的主机名,可反复向myapp-svc的此URL路径发起多次请求已验证其调度的效果:

**[terminal]
**[delimiter / # ]**[command for loop in 1 2 3 4; do curl http://10.233.16.105:80/hostname.html; done]
myapp-deploy-5cbd66595b-fjzdm
myapp-deploy-5cbd66595b-2lhds
myapp-deploy-5cbd66595b-mzbn6
myapp-deploy-5cbd66595b-fjzdm

当前Kubernetes集群的Service代理模式为iptables,他默认使用随机调度至与其关联的某个后端Pod资源上。命令取样次数越大,其调度效果也越来越接近于算法的目标效果。

results matching ""

    No results matching ""