部署service到swarm集羣,指定task運行的節點?(節點自定義標籤)


如標題所示,如何將service中task,指定運行在具有某個特殊的節點上,比如,存儲特別大,有GPU的?

 

方法,非常的簡單。

 

1、節點增加標籤

 

首先,給特殊的主機增加label

 

[[email protected]01 ~]# docker node ls
ID                            HOSTNAME           STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
gxfkhuc95br6ltkhorpw1q4tq *   nccztsjb-node-01   Ready     Active         Reachable        20.10.17
8zjicf39fk28jn106symk1g5e     nccztsjb-node-02   Ready     Active                          20.10.17
7d59usghrgq05k0yh4lbykw5v     nccztsjb-node-04   Ready     Active         Reachable        20.10.17
wnd24l698iruhhp1xw0y3iyig     nccztsjb-node-05   Ready     Active         Leader           20.10.17
[[email protected]-node-01 ~]# docker node update --label-add store=large nccztsjb-node-04
nccztsjb-node-04
[[email protected]-node-01 ~]# 

 

 

2、部署service

 

此時,具有特殊資源的節點,已經增加好了標籤,接下來,就是關鍵點了,部署service

 

通過--constraint參數指定具體約束條件

 

docker service create \
  --name redis \
  --constraint node.labels.store==large \
  172.20.58.152/middleware/redis:3.0.6  

 

 

部署過程

[[email protected] ~]# docker service create \

> --name redis \

> --constraint node.labels.store==large \

> 172.20.58.152/middleware/redis:3.0.6

u2a9nm7byfnxv3t7lofgsc321

overall progress: 1 out of 1 tasks

1/1: running [==================================================>]

verify: Service converged

 

 

查看task的運行狀態

 

[[email protected]01 ~]# docker service ps redis
ID             NAME      IMAGE                                  NODE               DESIRED STATE   CURRENT STATE            ERROR     PORTS
rzwlggf8i37r   redis.1   172.20.58.152/middleware/redis:3.0.6   nccztsjb-node-04   Running         Running 42 seconds ago             
[[email protected]-node-01 ~]# 
[[email protected]-node-01 ~]# docker service inspect redis --pretty

ID:        u2a9nm7byfnxv3t7lofgsc321
Name:        redis
Service Mode:    Replicated
 Replicas:    1
Placement:
 Constraints:    [node.labels.store==large]
UpdateConfig:
 Parallelism:    1
 On failure:    pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Update order:      stop-first
RollbackConfig:
 Parallelism:    1
 On failure:    pause
 Monitoring Period: 5s
 Max failure ratio: 0
 Rollback order:    stop-first
ContainerSpec:
 Image:        172.20.58.152/middleware/redis:3.0.6@sha256:d161fc7de1183ed220e28cf5e4cc50f1b535d580f2c3503c0b4ae4f2d63c1b1f
 Init:        false
Resources:
Endpoint Mode:    vip

[[email protected]-node-01 ~]# 

 

 

Placement:

Constraints: [node.labels.store==large] # 執行部署的限制條件。

 

 

OK,這樣task就運行到這個節點了。

 

那別停,如果是多個副本呢?

 

[[email protected]01 ~]# docker service scale redis=2
redis scaled to 2
overall progress: 2 out of 2 tasks 
1/2: running   [==================================================>] 
2/2: running   [==================================================>] 
verify: Service converged 
[[email protected]-node-01 ~]# 

 

 

毫無疑問,多個副本,都是運行在這一個節點上的,因爲,只有一個節點,有這樣的標籤

 

[[email protected]01 ~]# docker service ps redis
ID             NAME      IMAGE                                  NODE               DESIRED STATE   CURRENT STATE            ERROR     PORTS
rzwlggf8i37r   redis.1   172.20.58.152/middleware/redis:3.0.6   nccztsjb-node-04   Running         Running 3 minutes ago              
shonptv3fcae   redis.2   172.20.58.152/middleware/redis:3.0.6   nccztsjb-node-04   Running         Running 18 seconds ago             
[[email protected]-node-01 ~]# 

 

 

到這裏應該結束了吧,沒有,後面還會介紹到,其他的約束該怎麼做?

 

比如:

  • 根據主機名
  • 根據主機的操作系統
  • 根據主機平臺
  • 根據主機的ID
  • 根據的CPU架構

 

這些,後面的文章中,我們會講到······

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章