diff --git a/packages/@aws-cdk/aws-eks/lib/cluster.ts b/packages/@aws-cdk/aws-eks/lib/cluster.ts index c578b90fa388b..3b6f6fa9be348 100644 --- a/packages/@aws-cdk/aws-eks/lib/cluster.ts +++ b/packages/@aws-cdk/aws-eks/lib/cluster.ts @@ -1637,6 +1637,16 @@ export interface BootstrapOptions { */ readonly dockerConfigJson?: string; + /** + + * Overrides the IP address to use for DNS queries within the + * cluster. + * + * @default - 10.100.0.10 or 172.20.0.10 based on the IP + * address of the primary interface. + */ + readonly dnsClusterIp?: string; + /** * Extra arguments to add to the kubelet. Useful for adding labels or taints. * diff --git a/packages/@aws-cdk/aws-eks/lib/user-data.ts b/packages/@aws-cdk/aws-eks/lib/user-data.ts index 3b8d997535771..c6f30d215a9c0 100644 --- a/packages/@aws-cdk/aws-eks/lib/user-data.ts +++ b/packages/@aws-cdk/aws-eks/lib/user-data.ts @@ -27,6 +27,10 @@ export function renderAmazonLinuxUserData(clusterName: string, autoScalingGroup: extraArgs.push(`--docker-config-json '${options.dockerConfigJson}'`); } + if (options.dnsClusterIp) { + extraArgs.push(`--dns-cluster-ip ${options.dnsClusterIp}`); + } + if (options.additionalArgs) { extraArgs.push(options.additionalArgs); } diff --git a/packages/@aws-cdk/aws-eks/test/test.user-data.ts b/packages/@aws-cdk/aws-eks/test/test.user-data.ts index 044d1ff55f7ca..e796e5fd19ee4 100644 --- a/packages/@aws-cdk/aws-eks/test/test.user-data.ts +++ b/packages/@aws-cdk/aws-eks/test/test.user-data.ts @@ -66,6 +66,20 @@ export = { test.done(); }, + '--dns-cluster-ip'(test: Test) { + // GIVEN + const { asg, stack } = newFixtures(); + + // WHEN + const userData = stack.resolve(renderAmazonLinuxUserData('my-cluster-name', asg, { + dnsClusterIp: '192.0.2.53', + })); + + // THEN + test.deepEqual(userData[1], '/etc/eks/bootstrap.sh my-cluster-name --kubelet-extra-args "--node-labels lifecycle=OnDemand" --use-max-pods true --dns-cluster-ip 192.0.2.53'); + test.done(); + }, + '--docker-config-json'(test: Test) { // GIVEN const { asg } = newFixtures();