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
.
To deploy an application stack with service constraints:
Log in to the MKE web UI with administrator credentials.
Verify that the target node orchestrator is set to Swarm.
Click Shared Resources in the left-side navigation panel 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.
To verify service tasks deployed to labeled node:
In the left-side navigation panel, navigate to Shared Resources > Nodes. The details pane will display the full list of nodes.
Click the node with the
disk
label.In the details pane, click the Metrics tab to verify that WordPress containers are scheduled on the node.
In the left-side navigation panel, navigate to Shared Resources > Nodes.
Click any node that does not have the
disk
label.In the details pane, click the Metrics tab to verify that there are no WordPress containers scheduled on the node.