Catégorie : swarm

  • Ajout de node dans swarm

    Ajout de node dans swarm

    Pour gérer un swarm, il faut, avant tout, obtenir le token…

    La syntax est :

    pi@pi4node001:~ $ docker swarm join-token
    "docker swarm join-token" requires exactly 1 argument.
    See 'docker swarm join-token --help'.
    
    Usage:  docker swarm join-token [OPTIONS] (worker|manager)
    
    Manage join tokens
    pi@pi4node001:~ $

    Donc quand on veut ajouter un node de type MANAGER :

    pi@pi4node001:~ $ docker swarm join-token manager
    To add a manager to this swarm, run the following command:
    
    docker swarm join --token SWMTKN-1-2kr5jo0trm2o9bvnypqlzizx1exxivfeitqzi9smnhv6gxsd0f-95rzv0a1mbp0f8k1xkg55176n 192.168.0.201:2377
    
    pi@pi4node001:~ $

    et pour un de type WORKER :

    pi@pi4node001:~ $ docker swarm join-token worker 
    To add a worker to this swarm, run the following command:
    
        docker swarm join --token SWMTKN-1-2kr5jo0trm2o9bvnypqlzizx1exxivfeitqzi9smnhv6gxsd0f-8agpq7585s28ppp6gu1ldkf2x 192.168.0.201:2377
    
    pi@pi4node001:~ $

    maintenant, il faut se connecter sur le node voulu et exécuter la commande ci-dessus (en fonction du rôle voulu).

    Voici un exemple de swarm :

    pi@pi4node001:~ $ docker node ls  
    ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
    ppyfmhdq6p4xpflqj17eay2cm *   pi4node001   Ready     Active         Leader           20.10.5
    pwsktgnu30hvtx5zkgsz4ay2v     pi4node002   Ready     Active                          20.10.5
    pi@pi4node001:~ $

    Pour ajouter 2 noeuds de type WORKER (notez les hostnames… ):

    sur pi4node004:

    pi@pi4node004:~ $ docker swarm join --token SWMTKN-1-2kr5jo0trm2o9bvnypqlzizx1exxivfeitqzi9smnhv6gxsd0f-8agpq7585s28ppp6gu1ldkf2x 192.168.0.201:2377
    This node joined a swarm as a worker.
    pi@pi4node004:~ $ 
    

    sur pi4node003:

    pi@pi4node003:~ $ docker swarm join --token SWMTKN-1-2kr5jo0trm2o9bvnypqlzizx1exxivfeitqzi9smnhv6gxsd0f-8agpq7585s28ppp6gu1ldkf2x 192.168.0.201:2377 
    This node joined a swarm as a worker. 
    pi@pi4node003:~ $

    Le résultat est :

    pi@pi4node001:~ $ docker node ls
    ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
    ppyfmhdq6p4xpflqj17eay2cm *   pi4node001   Ready     Active         Leader           20.10.5
    pwsktgnu30hvtx5zkgsz4ay2v     pi4node002   Ready     Active                          20.10.5
    ucelbnf80e6ledibr1qcy9znd     pi4node003   Ready     Active                          20.10.5
    awl41iytsw3me002o9gh6u96h     pi4node004   Ready     Active                          20.10.5
    pi@pi4node001:~ $ 
    

     

  • Article sans titre 48647

    Docker Swarm Visualizer – Interface Web

    [callout type= »tip » title= »Quick Win »]
    Déploie une interface web en une commande pour visualiser en temps réel l’état de ton cluster Docker Swarm.
    [/callout]

    Contexte

    Quand tu gères un cluster Docker Swarm multi-nœuds, il est essentiel d’avoir une vue d’ensemble de l’état des services et des conteneurs. Le Swarm Visualizer d’Alex Ellis fournit exactement ça.

    Installation

    [code lang= »bash » title= »deploy-visualizer.sh »]

    Vérifier l’état du cluster

    pi@pi4node001:~ $ docker node ls
    ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
    ppyfmhdq6p4xpflqj17eay2cm * pi4node001 Ready Active Leader 20.10.5
    pwsktgnu30hvtx5zkgsz4ay2v pi4node002 Ready Active 20.10.5
    zmt3lly41a9ultipey0p42oor pi4node003 Ready Active 20.10.5
    ushbeebwkt20orsg29uhy8420 pi4node004 Ready Active 20.10.5

    Déployer le visualizer

    docker service create
    –name viz
    –publish 8080:8080/tcp
    –constraint node.role==manager
    –mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock
    alexellis2/visualizer-arm:latest

    Vérifier le déploiement

    docker service ls
    ID NAME MODE REPLICAS IMAGE PORTS
    ki6uzmz4myuu viz replicated 1/1 alexellis2/visualizer-arm:latest *:8080->8080/tcp
    [/code]

    [callout type= »note » title= »Architecture ARM »]
    Utilise alexellis2/visualizer-arm:latest pour Raspberry Pi. Pour x86, utilise dockersamples/visualizer.
    [/callout]

    Accès

    Une fois déployé, accède à l’interface via: http://IP_MANAGER:8080

    L’interface affiche en temps réel:

    • 📊 Tous les nœuds du cluster
    • 🐳 Les conteneurs sur chaque nœud
    • 📈 L’état des services
    • 🔄 Les mises à jour en live

    Performance

    [metrics before= »K3s: ~800MB RAM » after= »Swarm: ~200MB RAM » improvement= »+75% plus léger »]

    [callout type= »success »]
    Docker Swarm est significativement moins gourmand en ressources que K3s, ce qui est idéal pour des clusters Raspberry Pi.
    [/callout]

    Configuration Avancée

    Persistence des Données

    Pour sauvegarder l’état du visualizer:

    [code lang= »bash » title= »visualizer-with-volume.sh »]
    docker service create
    –name viz
    –publish 8080:8080/tcp
    –constraint node.role==manager
    –mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock
    –mount type=volume,src=viz-data,dst=/data
    alexellis2/visualizer-arm:latest
    [/code]

    Mise à Jour

    [code lang= »bash » title= »update-visualizer.sh »]

    Mettre à jour l’image

    docker service update
    –image alexellis2/visualizer-arm:latest
    viz

    Vérifier le rollout

    docker service ps viz
    [/code]

    Troubleshooting

    [callout type= »warning » title= »Service ne démarre pas »]
    Symptôme: Le service ne démarre pas ou redémarre en boucle.

    Solutions:

    1. Vérifier que Docker socket est accessible: ls -la /var/run/docker.sock
    2. Vérifier les logs: docker service logs viz
    3. S’assurer que le port 8080 est libre: netstat -tulpn | grep 8080
      [/callout]

      🔗 Ressources

      [resources]
      [resource type= »github » url= »https://github.com/alexellis/docker-swarm-visualiser »]Swarm Visualizer – GitHub[/resource]
      [resource type= »doc » url= »https://docs.docker.com/engine/swarm/ »]Docker Swarm Documentation[/resource]
      [resource type= »blog » url= »https://blog.alexellis.io/docker-swarm-visualizer/ »]Blog Post – Alex Ellis[/resource]
      [/resources]


      Métadonnées WordPress

      Difficulté: ⭐ (Débutant) Niveau: Beginner Temps d’implémentation: 5 min Production Ready:Catégories: Docker, Swarm, SRE, Observability URL originale: https://you.arewel.com/visualisation-du-swarm/