salt.modules.swarm

Docker Swarm Module using Docker's Python SDK

codeauthor:Tyler Jones <jonestyler806@gmail.com>

New in version 2018.3.0.

The Docker Swarm Module is used to manage and create Docker Swarms.

Dependencies

  • Docker installed on the host
  • Docker python sdk >= 2.5.1

Docker Python SDK

pip install -U docker

More information: https://docker-py.readthedocs.io/en/stable/

salt.modules.swarm.joinswarm(remote_addr=<type 'int'>, listen_addr=<type 'int'>, token=<type 'str'>)

Join a Swarm Worker to the cluster

remote_addr
The manager node you want to connect to for the swarm
listen_addr
Listen address used for inter-manager communication if the node gets promoted to manager, as well as determining the networking interface used for the VXLAN Tunnel Endpoint (VTEP)
token
Either the manager join token or the worker join token. You can get the worker or manager token via salt '*' swarm.swarm_tokens

CLI Example:

salt '*' swarm.joinswarm remote_addr=192.168.50.10 listen_addr='0.0.0.0'             token='SWMTKN-1-64tux2g0701r84ofq93zppcih0pe081akq45owe9ts61f30x4t-06trjugdu7x2z47j938s54il'
salt.modules.swarm.leave_swarm(force=<type 'bool'>)

Force the minion to leave the swarm

force
Will force the minion/worker/manager to leave the swarm

CLI Example:

salt '*' swarm.leave_swarm force=False
salt.modules.swarm.node_ls(server=<type 'str'>)

Displays Information about Swarm Nodes with passing in the server

server
The minion/server name

CLI Example:

salt '*' swarm.node_ls server=minion1
salt.modules.swarm.remove_node(node_id=<type 'str'>, force=<type 'bool'>)

Remove a node from a swarm and the target needs to be a swarm manager

node_id
The node id from the return of swarm.node_ls
force
Forcefully remove the node/minion from the service

CLI Example:

salt '*' swarm.remove_node node_id=z4gjbe9rwmqahc2a91snvolm5 force=false
salt.modules.swarm.remove_service(service=<type 'str'>)

Remove Swarm Service

service
The name of the service

CLI Example:

salt '*' swarm.remove_service service=Test_Service
salt.modules.swarm.service_create(image=<type 'str'>, name=<type 'str'>, command=<type 'str'>, hostname=<type 'str'>, replicas=<type 'int'>, target_port=<type 'int'>, published_port=<type 'int'>)

Create Docker Swarm Service Create

image
The docker image
name
Is the service name
command
The docker command to run in the container at launch
hostname
The hostname of the containers
replicas
How many replicas you want running in the swarm
target_port
The target port on the container
published_port
port thats published on the host/os

CLI Example:

salt '*' swarm.service_create image=httpd name=Test_Service             command=None hostname=salthttpd replicas=6 target_port=80 published_port=80
salt.modules.swarm.swarm_init(advertise_addr=<type 'str'>, listen_addr=<type 'int'>, force_new_cluster=<type 'bool'>)

Initalize Docker on Minion as a Swarm Manager

advertise_addr
The ip of the manager
listen_addr
Listen address used for inter-manager communication, as well as determining the networking interface used for the VXLAN Tunnel Endpoint (VTEP). This can either be an address/port combination in the form 192.168.1.1:4567, or an interface followed by a port number, like eth0:4567
force_new_cluster
Force a new cluster if True is passed

CLI Example:

salt '*' swarm.swarm_init advertise_addr='192.168.50.10' listen_addr='0.0.0.0' force_new_cluster=False
salt.modules.swarm.swarm_service_info(service_name=<type 'str'>)

Swarm Service Information

service_name
The name of the service that you want information on about the service

CLI Example:

salt '*' swarm.swarm_service_info service_name=Test_Service
salt.modules.swarm.swarm_tokens()

Get the Docker Swarm Manager or Worker join tokens

CLI Example:

salt '*' swarm.swarm_tokens
salt.modules.swarm.update_node(availability=<type 'str'>, node_name=<type 'str'>, role=<type 'str'>, node_id=<type 'str'>, version=<type 'int'>)

Updates docker swarm nodes/needs to target a manager node/minion

availability
Drain or Active
node_name
minion/node
role
role of manager or worker
node_id
The Id and that can be obtained via swarm.node_ls
version
Is obtained by swarm.node_ls

CLI Example:

salt '*' docker_util.update_node availability=drain node_name=minion2             role=worker node_id=3k9x7t8m4pel9c0nqr3iajnzp version=19