在 Docker Swarm 模式中以服務形式執行連接器代理程式以取得高可用性

使用 Docker 的 Swarm 模式,在多台機器上運行最多 3 個容器的叢集,以確保 Satellite Connector 代理程式的高可用性。

若要設定「Satellite」連接器,您必須在 Satellite 服務的「管理員」權限。

  • Satellite 連接器會將所有連接到該連接器的代理視為平等。
  • TCP 會話會以輪詢方式分配給所有代理。
  • 根據 IBM Connector 的指引,為確保冗餘,請至少使用 3 個代理程式。 這使得「Satellite」連接器服務更加可靠,且增加代理程式數量無需額外付費。 在 Windows 系統上,這意味著需要使用多個 Windows 主機。
  • 如果您正在使用容器,請確保您的容器並非全都位於同一台 VM 或硬體上,因為這種配置不具備冗餘性。
  • 對於高頻寬的工作負載,IBM 建議至少部署 6 個代理程式,因為這樣能涵蓋更多主機並提供更高頻寬。
  • Satellite 每個 Connector 最多可支援 9 個代理,但 IBM 不建議採用此配置,因為容器和虛擬機器具有短暫性,且當某個容器消失而新容器正嘗試連線時,系統可能無法即時察覺此變化。 相反地,請預留至少 3 個空閒槽位,以便容器和虛擬機器能夠停止運作和啟動。
  1. 請在您的 Swarm 管理員系統上建立一個名為 connector-agent.yaml 的 Satellite 連接器代理程式編譯檔,並將以下內容複製到該檔案中。 如果您有多個環境,您可以建立多個組態檔案,並按環境命名。 例如,為生產建立 connector-agent-prod.yaml,為暫存建立 connector-agent-staging.yaml。 然後,在各個檔案中包含您要用於每個環境的 Connector ID。

    version: '3.9'
    services:
      agent:
        image: icr.io/ibm/satellite-connector/satellite-connector-agent:latest
        environment:
        - SATELLITE_CONNECTOR_ID=/satellite-connector-id
        - SATELLITE_CONNECTOR_IAM_APIKEY=/run/secrets/satellite-connector-iam-apikey
        - SATELLITE_CONNECTOR_TAGS={{.Node.Hostname}} # You also can add other details in this field. For example, SATELLITE_CONNECTOR_TAGS="Some text"
        deploy:
          replicas: 3
          restart_policy:
            condition: any
          update_config:
            parallelism: 2
            delay: 20s
            failure_action: rollback
            order: start-first
          resources:
            limits:
              cpus: '0.40'
              memory: 500M
            reservations:
              cpus: '0.04'
              memory: 200M
        configs:
          - source: satellite-connector-id
            uid: '1000'
            gid: '1000'
            mode: 0400
          - source: satellite-connector-region
            uid: '1000'     
            gid: '1000'     
            mode: 0400      
        secrets:
          - source: satellite-connector-iam-apikey
            uid: '1000'
            gid: '1000'
            mode: 0400
        logging:
          driver: "json-file"
          options:
            max-size: ${JSON_FILE_MAX_SIZE:-1m}
            max-file: ${JSON_FILE_MAX_FILE:-10}
    configs:
      satellite-connector-id:
        external: true
      satellite-connector-region:
        external: true
    secrets:
      satellite-connector-iam-apikey:
        external: true
    networks:
      default:
        external: true
        name: bridge
    
  2. 使用 Satellite 連接器 ID 建立 Docker 配置。

    printf <satellite connector id value> | docker config create satellite-connector-id -
    
  3. 使用 Satellite 連接器區域建立 Docker 配置。

    printf <satellite connector region value> | docker config create satellite-connector-region -
    
  4. 使用 IAM API 金鑰建立 Docker 密鑰。

    printf <Your IAM API key> | docker secret create satellite-connector-iam-apikey -
    

依預設,Swarm Compose 檔案會將 SATELLITE_CONNECTOR_TAGS 環境變數設為 Swarm 節點的主機名稱。 您可以調整此值,以符合您在撰寫檔案內的需求。 此外,依預設,抄本數目會設為 3。 您可以將此數目調整為較低值,但最多只支援 3 個抄本。

  1. 部署 Satellite 連接器代理程式服務。
    1. 請確定您已使用 ibmcloud cr login CLI 或使用 API 金鑰 docker login -u iamapikey -p <your apikey> icr.io 登入 IBM Cloud® Container Registry。
    2. 部署堆疊。
      docker stack deploy --compose-file satellite-connector-agent.yaml --with-registry-auth satellite_connector
      
  2. 驗證 Satellite 連接器代理程式服務是否在執行中。
    docker service ps satellite_connector_agent