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:

  1. Log in to the MKE web UI with administrator credentials.

  2. Verify that the target node orchestrator is set to Swarm.

  3. Click Shared Resources in the left-side navigation panel to expand the selections.

  4. Click Stacks. The details pane will display the full list of stacks.

  5. Click the Create Stack button to open the Create Application page.

  6. Under 1. Configure Application, enter “wordpress” into the Name field .

  7. Under ORCHESTRATOR NODE, select Swarm Services.

  8. 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:
    
  9. Click Create to deploy the stack.

  10. 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:

  1. In the left-side navigation panel, navigate to Shared Resources > Nodes. The details pane will display the full list of nodes.

  2. Click the node with the disk label.

  3. In the details pane, click the Metrics tab to verify that WordPress containers are scheduled on the node.

  4. In the left-side navigation panel, navigate to Shared Resources > Nodes.

  5. Click any node that does not have the disk label.

  6. In the details pane, click the Metrics tab to verify that there are no WordPress containers scheduled on the node.