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.

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

  2. Click Shared Resources in the navigation menu to expand the selections.

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

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

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

  6. Under ORCHESTRATOR NODE, select Swarm Services.

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

  9. Click Done once the stack deployment completes to return to the stacks list which now features your newly created stack.

  10. In the navigation menu, click Nodes. The details pane will display the full list of nodes.

  11. Click the node with the disk label.

  12. In the details pane, click the Inspect Resource drop-down menu and select Containers.

  13. Dismiss the filter and navigate to the Nodes page.

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

  15. 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.