0 0 Share PDF

Workaround for link nodes in collection in UCP 3.0.0

Issue

In UCP 3.0.0, you can select a Kubernetes namespace in the Namespace list view in the UI and click Link Nodes in Collection. This will let you choose a UCP collection; any workloads that are deployed in this namespace will be restricted to running on nodes that are in the given UCP collection.

However, there is a known issue in UCP 3.0.0 that prevents node labels from being properly synchronized between Docker Swarm and Kubernetes; because of this issue, workloads in a linked namespace will not be able to find their nodes and therefore will not be able to start.

Resolution

If you have linked a collection's nodes to a namespace using the Link Nodes in Collection button and you are finding that workloads in that namespace are not starting, you can fix the problem by performing the following steps:

  1. Download an admin client bundle in UCP and load it.

  2. Run the following bash script:

    #!/bin/sh
    
    for node in $(docker node ls -q); do
        hostname=$(docker node inspect $node --format '{{.Description.Hostname}}' | tr '[:upper:]' '[:lower:]')
        keys=$(docker node inspect $node --format '{{range $key, $value := .Spec.Labels}}{{$key}} {{end}}')
        for key in $keys; do
            if echo $key | grep -q "^com.docker.ucp.collection"; then
                value=$(docker node inspect $node --format "{{index .Spec.Labels \"$key\"}}")
                echo "Setting Kubernetes node $hostname label $key=$value"
                kubectl label nodes $hostname $key=$value
            fi
        done
    done
    

This script manually syncs the node labels between Swarm and Kubernetes. You must re-run this script any time you add a new node or any time you change a node's collection.