fix(eks): join EKS Auto Mode instances to the API server at its VPC address (#9786)

The NodeConfig an EKS Auto Mode instance joins with named the cluster's
endpoint as DescribeCluster returns it, the one Floci publishes for
clients outside the VPC (the Docker host's port, or localhost), which an
instance in the VPC can't reach, so a kubelet image's node never joined.

It now names the API server's address in the cluster's VPC, the cluster
node's address in its subnet on port 6443, which k3s names in its
serving certificate as it does every --node-ip, as an EKS private
endpoint answers inside the VPC. A cluster node without a subnet address
keeps the published endpoint.
This commit is contained in:
mrfelek authored and GitHub committed 2026-11-29 21:11:58 -04:00
1 parent 13c6f0a419
commit cf40caafa2
5 files changed
+56 -8

No files matched your search

+6 -3
View File
@@ -497,9 +497,12 @@ launches nodes on AWS. Floci checks every 10 seconds.
every joined instance (see [Node metadata](#node-metadata-and-aws-outcome-alignment)), and pods are scheduled to
it but don't start.
- **Node.** The instance joins the cluster through its EKS bootstrap user data (a nodeadm `NodeConfig`), as any
instance does. Its kubelet flags (`--node-labels`, `--register-with-taints`) register the node with its pool's
labels and taints, so no pod the taints keep off lands there first; Floci's own Ready node for a joined instance
honours those flags too. The labels are: `karpenter.sh/nodepool`,
instance does. Its `apiServerEndpoint` is the API server's address in the cluster's VPC (the cluster node's
address in its subnet, port 6443), as an EKS private endpoint answers inside the VPC: the endpoint
`DescribeCluster` returns is the one Floci publishes for clients outside it, which the instance can't reach. Its
kubelet flags (`--node-labels`, `--register-with-taints`) register the node with its pool's labels and taints,
so no pod the taints keep off lands there first; Floci's own Ready node for a joined instance honours those flags
too. The labels are: `karpenter.sh/nodepool`,
`eks.amazonaws.com/compute-type: auto`, `node.kubernetes.io/instance-type`, `karpenter.sh/capacity-type`, and the
`eks.amazonaws.com/instance-*` category, generation, family, size, CPU and memory labels. The node is named by its
instance ID (`i-0123456789abcdef0`), as are its `kubernetes.io/hostname` label, as AWS names Auto Mode's nodes; its
@@ -452,7 +452,9 @@ public class EksAutoModeCompute implements EksAutoModeCleanup {
return;
}
String profileArn = instanceProfile(cluster, region, launch.pool().nodeClass(), role).getArn();
String userData = nodeConfig(cluster, launch);
// The instance joins over the cluster's VPC, where the endpoint published on the host isn't reachable.
String userData = nodeConfig(cluster, launch,
clusterManager.vpcApiServerEndpoint(cluster).orElse(cluster.getEndpoint()));
Reservation reservation = ec2.runInstances(region, imageId, launch.instanceType().instanceType, 1, 1, null,
ids(nodeClass.path("securityGroupSelectorTerms")), subnet, UUID.randomUUID().toString(),
tags(cluster, launch.pool()), userData, profileArn, null, null, 0, null, null, null,
@@ -1005,9 +1007,10 @@ public class EksAutoModeCompute implements EksAutoModeCleanup {
/**
* nodeadm's {@code NodeConfig} for the cluster, the user data an instance joins it with, its kubelet registering
* the node under the instance ID with its pool's labels and taints, so a pod the pool's taints keep off never
* lands there first.
* lands there first. Its {@code apiServerEndpoint} is the one given, the API server's address in the cluster's
* VPC when it has one.
*/
static String nodeConfig(Cluster cluster, Launch launch) {
static String nodeConfig(Cluster cluster, Launch launch, String apiServerEndpoint) {
StringBuilder yaml = new StringBuilder("""
apiVersion: node.eks.aws/v1alpha1
kind: NodeConfig
@@ -1015,8 +1018,8 @@ public class EksAutoModeCompute implements EksAutoModeCleanup {
cluster:
""");
yaml.append(" name: ").append(cluster.getName()).append('\n');
if (cluster.getEndpoint() != null) {
yaml.append(" apiServerEndpoint: ").append(cluster.getEndpoint()).append('\n');
if (apiServerEndpoint != null) {
yaml.append(" apiServerEndpoint: ").append(apiServerEndpoint).append('\n');
}
if (cluster.getCertificateAuthority() != null && cluster.getCertificateAuthority().getData() != null) {
yaml.append(" certificateAuthority: ").append(cluster.getCertificateAuthority().getData()).append('\n');
@@ -4451,6 +4451,18 @@ public class EksClusterManager
? regionResolver.getDefaultRegion() : "us-east-1"); // partition-literal: fallback for instance region
}
/**
* The API server's address in the cluster's VPC, as an EKS private endpoint answers inside it: the node's address
* in its subnet, which its serving certificate names, on the API server's port. Empty for a node without one.
*/
Optional<String> vpcApiServerEndpoint(Cluster cluster) {
String address = cluster.getNodePrivateIp();
if (address == null || address.isBlank()) {
return Optional.empty();
}
return Optional.of("https://" + address + ":" + K3S_API_SERVER_PORT);
}
String deriveInstanceNodeProviderId(Instance instance, String region) {
String safeRegion = resolveInstanceRegion(instance, region);
String az = (instance != null && instance.getPlacement() != null
@@ -116,6 +116,25 @@ class EksAutoModeComputeTest {
anyString(), anyBoolean(), any(), any(), any(), anyBoolean(), any(), any())).thenReturn(reservation);
}
/**
* The instance joins the API server at its address in the cluster's VPC, where the endpoint published on the
* host isn't reachable, as an EKS private endpoint answers inside the VPC.
*/
@Test
void anInstanceJoinsTheApiServerAtItsVpcAddress() {
Cluster cluster = cluster("prod");
when(clusterManager.vpcApiServerEndpoint(cluster)).thenReturn(Optional.of("https://10.0.1.10:6443"));
compute.reconcile(cluster, REGION);
ArgumentCaptor<String> userData = ArgumentCaptor.forClass(String.class);
verify(ec2).runInstances(eq(REGION), anyString(), anyString(), anyInt(), anyInt(), any(), anyList(),
anyString(), anyString(), anyList(), userData.capture(), anyString(), any(), any(), anyInt(), any(),
any(), any(), anyString(), anyBoolean(), any(), any(), any(), anyBoolean(), any(), any());
assertEquals(List.of(" apiServerEndpoint: https://10.0.1.10:6443"), userData.getValue().lines()
.filter(line -> line.contains("apiServerEndpoint")).toList());
}
@Test
void anUnschedulablePodGetsAnInstanceOfItsPoolInTheNodeClassesSubnetWithItsProfileTagsAndBootstrap() {
Cluster cluster = cluster("prod");
@@ -5701,6 +5701,17 @@ class EksClusterManagerTest {
return c;
}
/** The API server's VPC address is the node's address in its subnet, on the API server's port. */
@Test
void theApiServersVpcEndpointIsTheNodesSubnetAddress() {
Cluster cluster = new Cluster();
assertEquals(Optional.empty(), manager.vpcApiServerEndpoint(cluster));
cluster.setNodePrivateIp(" ");
assertEquals(Optional.empty(), manager.vpcApiServerEndpoint(cluster));
cluster.setNodePrivateIp("10.0.1.10");
assertEquals(Optional.of("https://10.0.1.10:6443"), manager.vpcApiServerEndpoint(cluster));
}
@Test
void deriveInstanceNodeNameAndProviderId() {
Instance inst = createInstance("i-0123456789abcdef0", "us-east-1b", null, null, null);