Thursday, 22 August 2019

Docker swarm Label and Constraint by Raj Gupta

We can create label in two way

1. Node labels  ----for this we need to run on master, we need access on master
2. Engine labels  ----we need to run on worker, so we don't required access of master.

If you want to create some service on only master then

[root@ip-172-31-83-166 ~]# docker service create --replicas=3 --constraint="node.role==manager" alpine ping 172.31.83.166
mr0nf8wjykhd8vhzzpexs20vl
overall progress: 3 out of 3 tasks
1/3: running   [==================================================>]
2/3: running   [==================================================>]
3/3: running   [==================================================>]
verify: Service converged
[root@ip-172-31-83-166 ~]#

--------------------------------------------------------------------------
and to create on only worker

[root@ip-172-31-83-166 ~]# docker service create --replicas=3 --constraint="node.role==worker" alpine ping 172.31.83.166
qixhwn2mje7guhqlcazl56bxt
overall progress: 3 out of 3 tasks
1/3: running   [==================================================>]
2/3: running   [==================================================>]
3/3: running   [==================================================>]
verify: Service converged
[root@ip-172-31-83-166 ~]#

--------------------------------------------------------------------------------------------------------------


In this way we can add label to node

[root@ip-172-31-83-166 ~]# docker node update --label-add="ssd=true" ip-172-31-81-43
ip-172-31-81-43
[root@ip-172-31-83-166 ~]#

In this way we can create service on only particular label node

[root@ip-172-31-83-166 ~]# docker service create --constraint="node.labels.ssd==true" --replicas=3 -d alpine 172.31.81.43
0a6ezsi9x2qhy7d523ctca0g8
[root@ip-172-31-83-166 ~]#



-----------------------------------------------------------------------------------------------

We can also create label on worker by using below

Run the below command on worker02

[root@ip-172-31-81-43 ~]# vi /etc/docker/daemon.json
[root@ip-172-31-81-43 ~]# cat /etc/docker/daemon.json
{
        "labels : ["name=raj"]
}
[root@ip-172-31-81-43 ~]# service docker restart

Now run the below command on master it will create on service on worker02 only

[root@ip-172-31-83-166 ~]# docker service create --constraint="engine.labels.name==raj" --replicas=3 -d alpine 172.31.81.43
mcvert6gvmw3u464ikhjwid2y
[root@ip-172-31-83-166 ~]#



1 comment:

  1. Hello everyone , here’s your opportunity for you to achieve your dreams of being a multi million dollar rich through trading , I once loss all I got through trading but was fortunate to come across a woman with great virtue and selfless heart (Mary ) i was introduce to her masterclass strategy while searching online which has revived me of all my losses and made me gain more and more . With her unique strategy you are entitled to daily signals and instant withdraw ,be rest assured of getting a refund of all your loss investment with any platform that has denied you in one way or the other in getting your money . Mrs Mary masterclass strategy is simply the best for beginners and those that are finding it difficult to succeed through trading she’ll help you with just a simple step . Email her ( maryshea03 @ Gmail .com) WhatsApp +1 562 384 7738 . Remember this is absolutely free!!!

    ReplyDelete