Skip to content

CKS add-node can pick an SSH port a live node uses after a node is removed #14797

Open

Description

@bhouse-nexthop

problem

CKS add-node picks the new node's SSH port from the node count, not from the ports in use. After removing an added node that is not the last one, the next add-node picks a port a live node still uses, and the add fails on a rule conflict.

In KubernetesClusterAddWorker.validateAndSetupNode:

int startSshPortNumber = CLUSTER_NODES_DEFAULT_START_SSH_PORT + (int) kubernetesCluster.getTotalNodeCount() - kubernetesCluster.getEtcdNodeCount().intValue();
int sshStartPort = startSshPortNumber + nodeIndex;

Example, 1 control + 2 workers (2222-2224):

step node count port picked result
add A 3 → 4 2225 ok
add B 4 → 5 2226 ok
remove A 5 → 4 (2225 freed) ok
add C 4 2226 clash with B's rules

On an isolated network the firewall rule create fails (The range specified, 2226-2226, conflicts with rule ...). On a VPC tier the PF rule is saved without a conflict check, so two PF rules share the port.

versions

4.22 and main (same code). Any CKS cluster that uses add-node / remove-node with external VMs.

The steps to reproduce the bug

  1. Create a CKS cluster (1 control, 2 workers) on an isolated network.
  2. addNodesToKubernetesCluster with VM A, then with VM B.
  3. removeNodesFromKubernetesCluster with VM A.
  4. addNodesToKubernetesCluster with VM C: it fails on port 2226.

What to do about it?

Pick the lowest port from 2222 up that no rule on the cluster's public IP is using, so a gap left by a removed node is reused and live nodes' ports are never taken. Existing nodes keep their ports.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions