Home > Enterprise >  Docker Swarm: no suitable node (max replicas per node limit exceed) why?
Docker Swarm: no suitable node (max replicas per node limit exceed) why?

Time:07-26

I have this dockr-compose.yml

version: '3.8'
services:
  mongo:
    image: mongo
    restart: always
    env_file:
      - ./.env
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_USERNAME}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}
    volumes:
      - mongo-db:/data/db
    ports:
      - "27017:27017"

  node-app:
    depends_on:
      - mongo
    image: USERNAME/PRIVATE_REPO_NAME:0.1
    env_file:
      - ./.env
    deploy:
      replicas: 2
      placement:
        max_replicas_per_node: 1
      update_config:
        parallelism: 1
        delay: 10s
      resources:
        limits:
          cpus: '0.50'
          memory: 512M
        reservations:
          cpus: '0.25'
          memory: 256M

  nginx:
    depends_on:
      - node-app
    image: nginx:stable-alpine
    ports:
      - "80:80"
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf

  mysql:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_USER: admin
      MYSQL_PASSWORD: password
      MYSQL_ALLOW_EMPTY_PASSWORD: 1
      MYSQL_DATABASE: db
    ports: 
      - 3306:3306
      - 33060:33060
    volumes:
      - mysql-db:/var/lib/mysql

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
    depends_on: 
      - mysql

  portainer:
    image: portainer/portainer-ce:latest
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./portainer-data:/data
    ports:
      - 9000:9000

  volumes:
    mongo-db:
    mysql-db:

and docker-compose-prod.yml

version: '3.8'
services:
  node-app:
    build:
      context: .
      target: production
    environment:
      - NODE_ENV=production
    command: npm start

Dockerfile

FROM node:14 as base

FROM base as production
WORKDIR /app
COPY package.json .
RUN npm install --only=production
COPY . .
EXPOSE 4000

FROM base as development
....

Nginx default.conf

server { # simple reverse-proxy
  listen       80;

  # pass requests for dynamic content to rails/turbogears/zope, et al
  location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://node-app:4000;
    proxy_redirect off;
  }
}

I build the image and push it to the private docker repo then on the VPS (1 vCPU and 1 GM RAM) I pull the image then run

docker stack deploy -c docker-compose.yml -c docker-compose-prod.yml nodestack --with-registry-auth

But I run docker stack ps nodestack I get

is7hybeurfgb   nodestack_adminer.1     adminer:latest                  docker-desktop   Running         Running about a minute ago
l92hsxrnpznh   nodestack_mongo.1       mongo:latest                    docker-desktop   Running         Preparing about a minute ago
2sg4x4lzk5uy   nodestack_mysql.1       mysql:latest                    docker-desktop   Running         Running 2 minutes ago
88vnttgk5grb   nodestack_nginx.1       nginx:stable-alpine             docker-desktop   Running         Running 2 minutes ago
7l5bm8tnjatv   nodestack_node-app.1    USERNAME/PRIVATE_REPO_NAME:0.1   docker-desktop   Running         Running 2 minutes ago
4xn3odusd265   nodestack_node-app.2    USERNAME/PRIVATE_REPO_NAME:0.1                    Running         Pending 2 minutes ago          "no suitable node (max replica…"
o38en2hwnikp   nodestack_portainer.1   portainer/portainer-ce:latest   docker-desktop   Running         Running about a minute ago

and it doesn't recreate the nodes with the new updates. Why do I get no suitable node (max replicas per node limit exceed) and how to fix it to keep running 2 replicas with only 1 node in each one?

CodePudding user response:

I think you're confusing a node in a swarm cluster with a NodeJS instance in a container. They have nothing to do with each other. From this output:

7l5bm8tnjatv   nodestack_node-app.1    USERNAME/PRIVATE_REPO_NAME:0.1   docker-desktop   Running         Running 2 minutes ago
4xn3odusd265   nodestack_node-app.2    USERNAME/PRIVATE_REPO_NAME:0.1                    Running         Pending 2 minutes ago          "no suitable node (max replica…"

It looks like you're running on docker-desktop, with a single node swarm cluster. You'll see that in docker node ls. To deploy multiple containers on your desktop, remove the constraint:

        max_replicas_per_node: 1

Or setup a cluster of multiple swarm nodes (VMs) and deploy to that cluster.

  • Related