Skip to content

Instantly share code, notes, and snippets.

@ajeetraina
Last active September 25, 2016 16:40
Show Gist options
  • Save ajeetraina/6831a5e2e7c6e4955f1a4af8b7693293 to your computer and use it in GitHub Desktop.
Save ajeetraina/6831a5e2e7c6e4955f1a4af8b7693293 to your computer and use it in GitHub Desktop.
Testing Node Labels under Docker 1.12 Swarm Mode
Platform: Google Cloud
Docker Version: 1.12.1
Setting up Master-1:
master ==>sudo docker swarm init --listen-addr 10.140.0.3
Swarm initialized: current node (doc7u22kg42bo9x0zrjbwtk86) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-02u85v6ggoj4em6e5v6rbjemgo9q324i9sced6dqkr54dyh3k8-68mxomvfy0htjbqm51dz60rtl \
10.140.0.3:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
master ==>
master ==>
Node:1:
node1 ==>sudo docker swarm join --token SWMTKN-1-02u85v6ggoj4em6e5v6rbjemgo9q324i9sced6dqkr54dyh3k8-68mxomvfy0htjb
qm51dz60rtl 10.140.0.3:2377
This node joined a swarm as a worker.
=========================================================================
Troubleshooting:
node1 ==>docker swarm join \
> --token SWMTKN-1-02u85v6ggoj4em6e5v6rbjemgo9q324i9sced6dqkr54dyh3k8-68mxomvfy0htjbqm51dz60rtl \
> 10.140.0.3:2377
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Fix: PLEASE DON"T FORGET TO USE SUDO COMMAND
node1 ==>
==============================================================================
Verify that node1 gets added on the master node:
master ==>sudo docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
243ueb7wuyjpj6w9l9vdmc2mt node3 Ready Active
doc7u22kg42bo9x0zrjbwtk86 * node1 Ready Active Leader
master ==>
Add more nodes accordingly:
master ==>sudo docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
243ueb7wuyjpj6w9l9vdmc2mt node3 Ready Active
38qrnph3a29dslekzmshuo71l instance-1 Ready Active
doc7u22kg42bo9x0zrjbwtk86 * node1 Ready Active Leader
dxc8zuxwpn5fxhpfnfong946p node4 Ready Active
master ==>
Let me label the first worker node [node3] as deployType=test
master ==>sudo docker node update --label-add deployType=test node3
node3
master ==>sudo docker node inspect --format '{{ json .Spec.Labels}}' node3
{"deployType":"test"}
master ==>
Create a service with Node Label Constraint:
master ==>sudo docker service create --name collabtest1 --constraint 'node.labels.deployType == test' alpine ping d
ocker.com
59oo6lh778ccx03okgmfazmn6
Verify that this service should only run on node-3
master ==>sudo docker service ls
ID NAME REPLICAS IMAGE COMMAND
59oo6lh778cc collabtest1 1/1 alpine ping docker.com
master ==>sudo docker service ps collabtest1
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
cmgvlthsr9brn8k1nfmtavao9 collabtest1.1 alpine node3 Running Running 11 seconds ago
Scaling the service and verify that it should only run on node3:
master ==>sudo docker service scale collabtest1=10
collabtest1 scaled to 10
master ==>sudo docker service ps collabtest1
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
cmgvlthsr9brn8k1nfmtavao9 collabtest1.1 alpine node3 Running Running 2 minutes ago
7lwl1eydst2h7tl2hfesd8n04 collabtest1.2 alpine node3 Running Running less than a second ago
0i5gve9q2zhznggkmjdp40njw collabtest1.3 alpine node3 Running Running less than a second ago
b08fnxiwta9xb4fnuu0kf6yj7 collabtest1.4 alpine node3 Running Starting less than a second ago
d6or95yktqzh3mply02z1oauo collabtest1.5 alpine node3 Running Running less than a second ago
b1uh77labkju75rpg5bsrhoco collabtest1.6 alpine node3 Running Running less than a second ago
6061nogqa985k1hsuc5e46rs7 collabtest1.7 alpine node3 Running Running less than a second ago
0gftp5dd08ic0793r2j8kc1yq collabtest1.8 alpine node3 Running Starting less than a second ago
29qyhlyzgicq46exfe3gg8xmf collabtest1.9 alpine node3 Running Running less than a second ago
7f68dmlz45s8rtp8y209g8urh collabtest1.10 alpine node3 Running Starting less than a second ago
Great !
Let's try something interesting:(!= label)
sudo docker service create --name collabtest1 --constraint 'node.labels.deployType != test' alpine ping d
ocker.com
c4mljs6rpequ1rfblw21e5xo3
master ==>sudo docker service ps collabtest1
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
ek23h7zhykxfqokqvkxhrf87a collabtest1.1 alpine node1 Running Running 44 seconds ago
So it picked up a node other than node3. IT WILL NEVER SCHEDULE AT NODE-3.
master ==>sudo docker service scale collabtest1=10
collabtest1 scaled to 10
master ==>sudo docker service ps collabtest1
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
ek23h7zhykxfqokqvkxhrf87a collabtest1.1 alpine node1 Running Running 58 seconds ago
6hmorpy0sn7kckqjsfrhepk0x collabtest1.2 alpine instance-1 Running Preparing 1 seconds ago
9un39v313japm9elresgkxpj1 collabtest1.3 alpine instance-1 Running Preparing 1 seconds ago
8ct24pxryogu5mox5kvx5kl4d collabtest1.4 alpine node1 Running Preparing 1 seconds ago
3cm7yte9urx4v02xw311klklf collabtest1.5 alpine instance-1 Running Preparing 1 seconds ago
cxfry283a9pev80ckjug0wt0j collabtest1.6 alpine node4 Running Preparing 1 seconds ago
9ivnmwiuirufhtmq41b6p4mz6 collabtest1.7 alpine node1 Running Preparing 1 seconds ago
84wnenzavhbflnqsn60v8gc6u collabtest1.8 alpine node4 Running Preparing 1 seconds ago
dkmq2exht6h8rh0ylt6to0np2 collabtest1.9 alpine node4 Running Preparing 1 seconds ago
67gk7lmubwt9b6ui0m9c25lq0 collabtest1.10 alpine node1 Running Preparing 1 seconds ago
master ==>
Now I will label the another worker node [node4] as deployType=test
master ==>sudo docker node update --label-add deployType=test node4
node4
Verifying:
master ==>sudo docker node inspect --format '{{ json .Spec.Labels}}' node4
{"deployType":"test"}
master ==>
I verified that node4 is not scheduled with this service:
master ==>sudo docker service ps collabtest1
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
ek23h7zhykxfqokqvkxhrf87a collabtest1.1 alpine node1 Running Running 5 minutes ago
6hmorpy0sn7kckqjsfrhepk0x collabtest1.2 alpine instance-1 Running Running 4 minutes ago
9un39v313japm9elresgkxpj1 collabtest1.3 alpine instance-1 Running Running 4 minutes ago
8ct24pxryogu5mox5kvx5kl4d collabtest1.4 alpine node1 Running Running 4 minutes ago
3cm7yte9urx4v02xw311klklf collabtest1.5 alpine instance-1 Running Running 4 minutes ago
cxfry283a9pev80ckjug0wt0j collabtest1.6 alpine node4 Running Running 4 minutes ago
9ivnmwiuirufhtmq41b6p4mz6 collabtest1.7 alpine node1 Running Running 4 minutes ago
84wnenzavhbflnqsn60v8gc6u collabtest1.8 alpine node4 Running Running 4 minutes ago
dkmq2exht6h8rh0ylt6to0np2 collabtest1.9 alpine node4 Running Running 4 minutes ago
67gk7lmubwt9b6ui0m9c25lq0 collabtest1.10 alpine node1 Running Running 4 minutes ago
I still see it using node4:
master ==>sudo docker service ps collabtest1
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
ek23h7zhykxfqokqvkxhrf87a collabtest1.1 alpine node1 Running Running 8 minutes ago
6hmorpy0sn7kckqjsfrhepk0x collabtest1.2 alpine instance-1 Running Running 7 minutes ago
9un39v313japm9elresgkxpj1 collabtest1.3 alpine instance-1 Running Running 7 minutes ago
8ct24pxryogu5mox5kvx5kl4d collabtest1.4 alpine node1 Running Running 7 minutes ago
3cm7yte9urx4v02xw311klklf collabtest1.5 alpine instance-1 Running Running 7 minutes ago
cxfry283a9pev80ckjug0wt0j collabtest1.6 alpine node4 Running Running 7 minutes ago
9ivnmwiuirufhtmq41b6p4mz6 collabtest1.7 alpine node1 Running Running 7 minutes ago
84wnenzavhbflnqsn60v8gc6u collabtest1.8 alpine node4 Running Running 7 minutes ago
dkmq2exht6h8rh0ylt6to0np2 collabtest1.9 alpine node4 Running Running 7 minutes ago
67gk7lmubwt9b6ui0m9c25lq0 collabtest1.10 alpine node1 Running Running 7 minutes ago
master ==>sudo docker service scale collabtest1=20
collabtest1 scaled to 20
master ==>sudo docker service ps collabtest1
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
ek23h7zhykxfqokqvkxhrf87a collabtest1.1 alpine node1 Running Running 8 minutes ago
6hmorpy0sn7kckqjsfrhepk0x collabtest1.2 alpine instance-1 Running Running 7 minutes ago
9un39v313japm9elresgkxpj1 collabtest1.3 alpine instance-1 Running Running 7 minutes ago
8ct24pxryogu5mox5kvx5kl4d collabtest1.4 alpine node1 Running Running 7 minutes ago
3cm7yte9urx4v02xw311klklf collabtest1.5 alpine instance-1 Running Running 7 minutes ago
cxfry283a9pev80ckjug0wt0j collabtest1.6 alpine node4 Running Running 7 minutes ago
9ivnmwiuirufhtmq41b6p4mz6 collabtest1.7 alpine node1 Running Running 7 minutes ago
84wnenzavhbflnqsn60v8gc6u collabtest1.8 alpine node4 Running Running 7 minutes ago
dkmq2exht6h8rh0ylt6to0np2 collabtest1.9 alpine node4 Running Running 7 minutes ago
67gk7lmubwt9b6ui0m9c25lq0 collabtest1.10 alpine node1 Running Running 7 minutes ago
ecdtr5xwx438m4ahqneih88gg collabtest1.11 alpine instance-1 Running Preparing 1 seconds ago
7arwmpiqtg5iz2r4tjlnjpuqf collabtest1.12 alpine instance-1 Running Preparing 1 seconds ago
b995usnx15zow499xf8yzxm6o collabtest1.13 alpine node1 Running Preparing 1 seconds ago
162xskbzxtg1p3mk7cud81hu0 collabtest1.14 alpine instance-1 Running Preparing 1 seconds ago
0sve29x41tkoeyeo5p9sz1g4s collabtest1.15 alpine node1 Running Preparing 1 seconds ago
5il7g7j53szvky5dfzp40bev5 collabtest1.16 alpine node1 Running Preparing 2 seconds ago
7jx8boo246lncep8cza7lyemx collabtest1.17 alpine node1 Running Preparing 1 seconds ago
48h433zkgg46fkx54vhe53f1r collabtest1.18 alpine instance-1 Running Preparing 2 seconds ago
ci9kgoww2rceaknylca8pdblb collabtest1.19 alpine instance-1 Running Preparing 1 seconds ago
48d74dypi8gixtqr8wtfwemdb collabtest1.20 alpine node1 Running Preparing 1 seconds ago
master ==>
The new service scaled number doesn't use the node4 but the earlier service still uses node4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment