Deploy a service with constraints¶
The following example procedure deploys a service with a constraint that
ensures that the service only runs on nodes with SSD storage
node.labels.disk == ssd
.
Log in to the MKE web UI with administrator credentials.
Click Shared Resources in the navigation menu to expand the selections.
Click Stacks. The details pane will display the full list of stacks.
Click the Create Stack button to open the Create Application page.
Under 1. Configure Application, enter “wordpress” into the Name field .
Under ORCHESTRATOR NODE, select Swarm Services.
Under 2. Add Application File, paste the following stack file in the docker-compose.yml editor:
version: "3.1" services: db: image: mysql:5.7 deploy: placement: constraints: - node.labels.disk == ssd restart_policy: condition: on-failure networks: - wordpress-net environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest deploy: replicas: 1 placement: constraints: - node.labels.disk == ssd restart_policy: condition: on-failure max_attempts: 3 networks: - wordpress-net ports: - "8000:80" environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress networks: wordpress-net:
Click Create to deploy the stack.
Click Done once the stack deployment completes to return to the stacks list which now features your newly created stack.
In the navigation menu, click Nodes. The details pane will display the full list of nodes.
Click the node with the
disk
label.In the details pane, click the Inspect Resource drop-down menu and select Containers.
Dismiss the filter and navigate to the Nodes page.
Click any node that does not have the
disk
label.In the details pane, click the Inspect Resource drop-down menu and select Containers. Dismiss the filter since there are no WordPress containers scheduled on the node.