diff --git a/cluster_connect.sh.tpl b/cluster_connect.sh.tpl index 387fcec..24e6f11 100644 --- a/cluster_connect.sh.tpl +++ b/cluster_connect.sh.tpl @@ -1,3 +1,18 @@ +# Calculate max pods +if [[ "${use_max_pods}" = "false" ]]; then + KUBELET_CONFIG=/etc/kubernetes/kubelet/kubelet-config.json + set +o pipefail + export CNI_VERSION=$(echo "${cni_version}" | sed 's/^v//') + export CNI_CUSTOM_NETWORKING_ENABLED=true + MAX_PODS=$(/etc/eks/max-pods-calculator.sh --instance-type-from-imds --cni-version $CNI_VERSION --cni-custom-networking-enabled{{if show-max-allowed}} --show-max-allowed{{end}}) + set -o pipefail + if [[ -n "$MAX_PODS" ]]; then + echo "$(jq ".maxPods=$MAX_PODS" $KUBELET_CONFIG)" > $KUBELET_CONFIG + else + echo "Not able to determine maxPods for instance. Not setting max pods for kubelet" + fi +fi + /etc/eks/bootstrap.sh ${cluster_name} \ --use-max-pods ${use_max_pods} \ --kubelet-extra-args '--node-labels=${node_labels} --register-with-taints=${node_taints} ${kubelet_extra_args}' \ diff --git a/node_group_advanced.tf b/node_group_advanced.tf index bc2d466..1cf8b60 100644 --- a/node_group_advanced.tf +++ b/node_group_advanced.tf @@ -120,7 +120,9 @@ resource "aws_launch_template" "quortex_launch_tpl" { ) : "${k}=${v}"] ) - use_max_pods = var.node_use_max_pods + use_max_pods = var.node_use_max_pods + cni_version = try(var.cluster_addons["vpc-cni"].version, "") + show_max_allowed = var.show_max_allowed } ) } diff --git a/variables.tf b/variables.tf index d50cb13..9ce16c7 100644 --- a/variables.tf +++ b/variables.tf @@ -210,6 +210,12 @@ variable "node_use_max_pods" { description = "Set to false to prevent EKS from setting --max-pods in Kubelet config. By default, EKS sets the maximum number of pods that can run on the node, based on the instance type. Disabling this can be useful when using a CNI other than the default, like Calico." } +variable "show_max_allowed" { + type = bool + default = true + description = "Set to false to prevent setting show_max_allowed on max-pods-calculator" +} + variable "instance_profile_name" { type = string description = "A name for the instance profile resource in AWS. Used only when node_groups_advanced is used."