集群服务见通信之Routing Mesh

文章目录

在这里插入图片描述
创建一个overlay的网络

docker network create -d overlay demo

创建whoami service

docker service create --name whoami -p 8080:8080 --network demo -d jwilder/whoami

创建client service

docker service create --name client -d --network demo busybox sh -c "while true;do sleep 3600;done"

进入client service所在的节点,ping whoami 是可以ping同的

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
489c59e8436d        busybox:latest      "sh -c 'while true;d…"   3 minutes ago       Up 3 minutes                            client.1.zmld0iwgetb7p5mab761ge8zu
[node1] (local) root@192.168.0.13 ~
$ docker exec -it 489c59e8436d sh
/ # 
/ # ping whoami
PING whoami (10.0.0.8): 56 data bytes
64 bytes from 10.0.0.8: seq=0 ttl=64 time=0.499 ms
64 bytes from 10.0.0.8: seq=1 ttl=64 time=0.106 ms
64 bytes from 10.0.0.8: seq=2 ttl=64 time=0.089 ms
64 bytes from 10.0.0.8: seq=3 ttl=64 time=0.110 ms

扩展whoami service

docker service scale whoami=2

在client service中再次ping whoami 发现ip是不变的

/ # ping whoami
PING whoami (10.0.0.8): 56 data bytes
64 bytes from 10.0.0.8: seq=0 ttl=64 time=0.106 ms
64 bytes from 10.0.0.8: seq=1 ttl=64 time=0.073 ms
64 bytes from 10.0.0.8: seq=2 ttl=64 time=0.104 ms
64 bytes from 10.0.0.8: seq=3 ttl=64 time=0.071 ms
64 bytes from 10.0.0.8: seq=4 ttl=64 time=0.099 ms

nslookup 命令

localhost:~ xuzhongjie$ nslookup www.imooc.com
Server:		192.168.1.1
Address:	192.168.1.1#53

Non-authoritative answer:
Name:	www.imooc.com
Address: 117.121.101.41
Name:	www.imooc.com
Address: 115.182.41.180
Name:	www.imooc.com
Address: 117.121.101.40

进入client service 容器执行

nslookup whoami
nslookup tasks.whoami

swarm 会给每个service分配虚拟ip
每次访问whoami 返回的id不一样,说明负载均衡。

/ # wget whoami:8000
Connecting to whoami:8000 (10.0.0.8:8000)
saving to 'index.html'
index.html           100% |*************************************************************************************|    17  0:00:00 ETA
'index.html' saved
/ # more index.html 
I'm fc2f8a79b2d5
/ # rm -f index.html 
/ # wget whoami:8000
Connecting to whoami:8000 (10.0.0.8:8000)
saving to 'index.html'
index.html           100% |*************************************************************************************|    17  0:00:00 ETA
'index.html' saved
/ # more index.html 
I'm 99c1aa83eb38

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值