I have a jenkins pipeline where it build and runs various containers on a NUC server. This NUC is on a cluster (Swarm) with another NUC. I recently added a couple of raspberry Pis on my setup and on that cluster, so now I wonder if there is a way to command Jenknis to deploy on x86_x64 or armhf
devices.
I tried the -e constraint:node==<node_name>
solution I found on other questions, but i had no luck.
I tried the above command from one x86_x64
node pointing to another and from a x86_x64
node pointing to a armhf
node
I dont want to run those containers as a service and i dont care of any load balancer, I just want to run a container on a specific architecture ( x86_x64 or armhf
depending on what i want to deploy)
You cannot use constraints on containers, only on services.
That being said, using constraints on services seems a good way to go. You can learn more about services constraints in the official documentation . Here are a few example on how constraints can match node or Docker Engine labels:
# Node ID
node.id==2ivku8v2gvtg4
# Node hostname
node.hostname!=node-2
# Node role
node.role==manager
# Node labels
node.labels.security==high
# Docker Engine's labels
engine.labels.operatingsystem==ubuntu 14.04
If you want to match a specific hostname you need to use node.hostname==<hostname>
and not node==<hostname>
You will also want to update the restart_policy
key from your service definition deploy
policy to prevent from starting a new container once the first one terminates its process successfully.
Wrapping it all together you need something like that:
version: "3.7"
services:
myapp:
image: <my_image>
deploy:
placement:
constraints:
- node.labels.arch == x86_64
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
Of course, it is up to you to add the labels to each Swarm node. Ansible and its module docker-node are really well suited for this purpose. Here is an example playbook:
- hosts: swarm
tasks:
- name: Add label to node specifying architecture
docker_node:
hostname: "{{ inventory_hostname }}"
labels:
arch: "{{ ansible_architecture }}"
Your docker nodes would be labelled with the key arch
and one of the following values:
Why don't you want to use a service? Services is how we orchestrate things in Swarm. docker container ...
will only start/stop/inspect/manipulate things in on a single host. As you already have a swarm cluster set up, why not use a service?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.