差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

兩邊的前次修訂版 前次修改
下次修改
前次修改
tech:docker_swarm [2025/09/26 15:07] – [安裝與部署] jonathantech:docker_swarm [2025/11/19 11:49] (目前版本) – [使用 portainer 進行 Web 統一控管] jonathan
行 23: 行 23:
   * 當 Agent 安裝成功後, 回到 WebUI 輸入主控點的 Name (Exp. Portainer-186) 與 address (Exp. 192.168.1.186:9001), 然後點下 Connect 按鈕就可以建立完成   * 當 Agent 安裝成功後, 回到 WebUI 輸入主控點的 Name (Exp. Portainer-186) 與 address (Exp. 192.168.1.186:9001), 然後點下 Connect 按鈕就可以建立完成
   * 回到 Home 在 Environments 清單就可以看到 Portainer-186 , 點下去就可以開始管理這個 Swarm cluster \\ {{:tech:螢幕擷取畫面_2025-09-23_155253.png?1024|}}   * 回到 Home 在 Environments 清單就可以看到 Portainer-186 , 點下去就可以開始管理這個 Swarm cluster \\ {{:tech:螢幕擷取畫面_2025-09-23_155253.png?1024|}}
 +  * 當每台 swarm node 重新啟動後 Portainer 管理介面點選出現 Failure Unable to retrieve system info: Unable to find an agent on any manager node 這異常訊息時, 可以重啟所有的 Portainer Agent 來解決<cli>
 +portainer-161:~# docker service update --force portainer_agent
 +portainer_agent
 +overall progress: 1 out of 1 tasks
 +aeaia7g7xz3w: running   [==================================================>]
 +verify: Service portainer_agent converged
 +</cli>
  
-===== 建立 watchtower 統一在主控點進行管理 ===== +===== 建立 shepherd 統一在主控點進行管理 ===== 
-  * 希望可以透過 Discord 進行通知 +  * stack yaml <file>
-    * 將 Discord 的 Webhook URL 以建立 Secrets 方式處理, 在主控點執行<cli> +
-echo 'discord://yPGy1FR1w_kxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxWGzQrB@1382930065779593256' | docker secret create watchtower_discord_url - +
-</cli>或是在 Portainer Web UI 直接新增 \\ {{:tech:螢幕擷取畫面_2025-09-23_184116.png?1024|}} +
-    * 使用 Configs 來存放通知訊息的設定內容 template  Exp. 🚀 Swarm Service Updated Service: portainer_portainer Image: portainer/portainer-ce Version: 2.19.4 -> 2.19.5 <cli> +
-vi watchtower_template.tpl</cli><file> +
-{{- if .Entries -}} +
-{{- range .Entries -}} +
-**Service:** `{{.Service.Name}}` +
-**Image:** `{{.Service.ImageName}}` +
-**Version:** `{{.OldImage.Tag}}` -> `{{.NewImage.Tag}}` +
---- +
-{{- end -}} +
-{{- else -}} +
-*No new updates found.* +
-{{- end -}} +
-</file>在主控點執行<cli> +
-docker config create watchtower_notification_template watchtower_template.tpl +
-</cli>或是在 Portainer Web UI 直接新增 \\ {{:tech:螢幕擷取畫面_2025-09-23_184844.png?1024|}} +
-    * 建立 watchtower 的 Swarm Stack <cli> +
-vi watchtower-stack.yml</cli><file>+
 services: services:
-  watchtower+  shepherd
-    image: containrrr/watchtower +    image: containrrr/shepherd:latest
-    volumes: +
-      - "/var/run/docker.sock:/var/run/docker.sock" +
-    environment: +
-      TZ: Asia/Taipei +
-      WATCHTOWER_SCHEDULE: "0 0 * * * *" +
-      WATCHTOWER_CLEANUP: "true" +
-      WATCHTOWER_NOTIFICATIONS: shoutrrr +
-      WATCHTOWER_NOTIFICATION_URL_FILE: /run/secrets/watchtower_discord_url +
-      WATCHTOWER_NOTIFICATIONS_LEVEL: info +
-      WATCHTOWER_NOTIFICATION_TITLE: "🚀 Swarm Service Updated" +
-      WATCHTOWER_NOTIFICATION_TEMPLATE_FILE: /run/configs/watchtower_notification_template +
-    secrets: +
-      - watchtower_discord_url +
-    configs: +
-      - source: watchtower_notification_template +
-        target: /run/configs/watchtower_notification_template +
-    command--scope swarm+
     deploy:     deploy:
-      mode: global+      mode: replicated 
 +      replicas: 1
       placement:       placement:
         constraints:         constraints:
行 73: 行 44:
       restart_policy:       restart_policy:
         condition: on-failure         condition: on-failure
-secrets+        delay10s 
-  watchtower_discord_url+        max_attempts3         
-    externaltrue +    environment
-configs: +      - TZ=Asia/Taipei 
-  watchtower_notification_template: +      - SLEEP_TIME=8h  # 每8小時檢查一次,減少速率限制觸發(Go Duration 格式) 
-    external: true +      # - WITH_REGISTRY_AUTH=true  # 啟用註冊庫驗證 
-</file>在主控點執<cli> +      # - REGISTRY_USER_FILE=/run/secrets/dockerhub_user 
-docker stack deploy -c watchtower-stack.yml watchtower +      # - REGISTRY_PASSWORD_FILE=/run/secrets/dockerhub_token 
-</cli>或是在 Portainer Web UI 直接新增 \\ {{:tech:螢幕擷取畫面_2025-09-23_185335.png?1024|}}+      - ROLLBACK_ON_FAILURE=true  # 更新失敗時自動回滾 
 +      - UPDATE_OPTIONS=--update-delay=1m --update-parallelism=1 --update-failure-action=rollback  # 添加延遲和並限制,避免順序錯誤 
 +      IGNORELIST_SERVICES=cleanup-scheduler_cleanup-scheduler 
 +      - NO_PROXY=localhost,127.0.0.1,/var/run/docker.sock 
 +    volumes: 
 +      type: bind 
 +        source: /var/run/docker.sock 
 +        target: /var/run/docker.sock 
 +</file>
 ===== FAQ ===== ===== FAQ =====
 ==== 1. 移除特定 Worker host 方式 Exp. immich-237 ==== ==== 1. 移除特定 Worker host 方式 Exp. immich-237 ====
行 118: 行 97:
 q4fxgqgi2sp42wntxynks3wqf     swarm-226       Ready     Active         Reachable        28.3.3 q4fxgqgi2sp42wntxynks3wqf     swarm-226       Ready     Active         Reachable        28.3.3
 </cli> </cli>
 +
 +==== 3. 建立 nfs volume 的作法 ====
 +  - 先在 NFS Server 建立分享目錄與權限設定 參考 - [[tech/nfs]]
 +  - NFS Volume 的指定方式如下 Exp. NFS Serer: 192.168.1.159 , 分享目錄: /swarmdata/mystack/nfs-data <file>
 +volumes:
 +  mystack_nfs-data:
 +    driver: local
 +    driver_opts:
 +      type: nfs
 +      o: "addr=192.168.1.159,rw,noatime,rsize=8192,wsize=8192,tcp,timeo=14,nfsvers=4"
 +      device: ":/swarmdata/mystack/nfs-data"
 +</file>
 +<note important>
 +  * 啟動 stack 時**不會**如同本地 volume 自動建立出目錄, 必須要在 NFS Server 先建立好指定的目錄 Exp.<cli>mkdir -p /swarmdata/mystack/nfs-data</cli>
 +  * 如想要修改 NFS Volume 定義
 +    - 要將 stack 移除 Exp. <cli>docker stack rm mystack</cli>
 +    - 進入 swarm **每個 node 移除 volume** Exp.<cli>docker volume rm mystack_nfs-data</cli>
 +    - 重新部署 stack Exp. <cli>docker stack deploy -c mystack.yml mystack</cli>
 +    - 檢查新建立的 Volume 內容 Exp. <cli>docker volume inspect mystack_nfs-data</cli>
 +</note>
  
 {{tag>docker k8s}} {{tag>docker k8s}}
  
  • tech/docker_swarm.1758870473.txt.gz
  • 上一次變更: 2025/09/26 15:07
  • jonathan