Skip to content

Commit

Permalink
Updated default kubelet reserved memory calculation to match the calc…
Browse files Browse the repository at this point in the history
…ulation used by amazon-eks-ami

The reserved memory calculation was changed in amazon-eks-ami to be based on pod density (11*maxPodsPerNode+255) instead
of total memory.
See https://github.com/awslabs/amazon-eks-ami/blob/21426e27e3845319dbca92e7df32e5c4b984a1d1/files/bootstrap.sh#L163

This commit introduces a new InstanceTypeInfo property to store MaxPodsPerNode and populates it using the data from
maxpods.go so that it will be available to use when calculing the default memory to reserve.

Because the image type specs (cpu, memory) come from an API call and the max number of pods per node comes from a file
in amaxon-eks-ami, there is a chance that an image type is returned by the API for which there is no corresponding
record in maxpods.go. To handle this, the original memory calculation remains as a fallback that will be used if max
pods per node is unknown.

Issue eksctl-io#2395
  • Loading branch information
brianpursley committed Jul 15, 2020
1 parent 9ac389a commit 9f0e214
Show file tree
Hide file tree
Showing 6 changed files with 1,316 additions and 825 deletions.
2 changes: 1 addition & 1 deletion pkg/cfn/builder/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func completeKubeletConfig(kubeletConfigAssetContent []byte, clusterDNS string)
"kubeReserved:\n" +
" cpu: 70m\n" +
" ephemeral-storage: 1Gi\n" +
" memory: 1843Mi\n"
" memory: 574Mi\n"
}

var _ = Describe("CloudFormation template builder API", func() {
Expand Down
25 changes: 15 additions & 10 deletions pkg/nodebootstrap/reserved.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ type InstanceTypeInfo struct {
Memory int64
// CPU count.
CPU int64
// Max pods per node.
MaxPodsPerNode int64
}

// NewInstanceTypeInfo creates a simple version of ec2.InstanceTypeInfo
Expand All @@ -80,6 +82,9 @@ func NewInstanceTypeInfo(ec2info *ec2.InstanceTypeInfo) InstanceTypeInfo {
if ec2info.VCpuInfo != nil {
i.CPU = aws.Int64Value(ec2info.VCpuInfo.DefaultVCpus)
}
if maxPodsPerNode, exists := maxPodsPerNodeType[*ec2info.InstanceType]; exists {
i.MaxPodsPerNode = int64(maxPodsPerNode)
}
return i
}

Expand All @@ -93,17 +98,17 @@ func (i InstanceTypeInfo) DefaultStorageToReserve() string {

// DefaultMemoryToReserve returns how much memory to reserve.
//
// See https://github.com/awslabs/amazon-eks-ami/blob/ff690788dfaf399e6919eebb59371ee923617df4/files/bootstrap.sh#L150-L181
// which takes it form https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-architecture#node_allocatable
//
// 255 Mi of memory for machines with less than 1024Mi of memory
// 25% of the first 4096Mi of memory
// 20% of the next 4096Mi of memory (up to 8192Mi)
// 10% of the next 8192Mi of memory (up to 16384Mi)
// 6% of the next 114688Mi of memory (up to 131072Mi)
// 2% of any memory above 131072Mi
// See https://github.com/awslabs/amazon-eks-ami/blob/21426e27e3845319dbca92e7df32e5c4b984a1d1/files/bootstrap.sh#L154-L165
func (i InstanceTypeInfo) DefaultMemoryToReserve() string {
mib := memProgression.calculate(i.Memory, minimumMemoryToReserve)
var mib int64
if i.MaxPodsPerNode > 0 {
mib = 11*i.MaxPodsPerNode + minimumMemoryToReserve
} else {
// As a fallback, if MaxPodsPerNode is 0, use the original calculation, which is a progressive calculation based on total memory.
// See https://github.com/awslabs/amazon-eks-ami/blob/ff690788dfaf399e6919eebb59371ee923617df4/files/bootstrap.sh#L150-L181
// which takes it from https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-architecture#node_allocatable
mib = memProgression.calculate(i.Memory, minimumMemoryToReserve)
}
return fmt.Sprintf("%dMi", mib)
}

Expand Down
Loading

0 comments on commit 9f0e214

Please sign in to comment.