Use instance requirements to get a wider set of instance types by default

This commit is contained in:
Ole Markus With 2021-12-22 13:44:36 +01:00
parent abcab2b327
commit 655d63cec1
3 changed files with 73 additions and 41 deletions

View File

@ -110,6 +110,12 @@ spec:
manager: Karpenter
maxSize: 2
minSize: 2
mixedInstancesPolicy:
instanceRequirements:
cpu:
min: "2"
memory:
min: 2G
nodeLabels:
kops.k8s.io/instancegroup: nodes
role: Node

View File

@ -876,6 +876,24 @@ func setupKarpenterNodes(opt *NewClusterOptions, cluster *api.Cluster, zoneToSub
HTTPTokens: fi.String("required"),
}
// Karpenter thinks all clusters run VPC CNI and schedules thinking Node Capacity is constrainted by number of ENIs.
// cpuMin is the reasonable lower limit for a Kubernetes Node
// Generally, it also avoids instances Karpenter thinks it can only schedule 4 Pods on.
cpuMin := resource.MustParse("2")
memoryMin := resource.MustParse(("2G"))
g.Spec.MixedInstancesPolicy = &api.MixedInstancesPolicySpec{
InstanceRequirements: &api.InstanceRequirementsSpec{
CPU: &api.MinMaxSpec{
Min: &cpuMin,
},
Memory: &api.MinMaxSpec{
Min: &memoryMin,
},
},
}
return []*api.InstanceGroup{g}, nil
}

View File

@ -822,6 +822,13 @@ func karpenterInstanceTypes(cloud awsup.AWSCloud, ig kops.InstanceGroupSpec) ([]
ir := &ec2.InstanceRequirementsRequest{
VCpuCount: &ec2.VCpuCountRangeRequest{},
MemoryMiB: &ec2.MemoryMiBRequest{},
BurstablePerformance: fi.String("included"),
}
cpu := instanceRequirements.CPU
if cpu != nil {
if cpu.Max != nil {
cpuMax, _ := instanceRequirements.CPU.Max.AsInt64()
ir.VCpuCount.Max = &cpuMax
}
cpu := instanceRequirements.CPU
if cpu != nil {
@ -876,5 +883,6 @@ func karpenterInstanceTypes(cloud awsup.AWSCloud, ig kops.InstanceGroupSpec) ([]
return types, nil
}
}
}
return []string{ig.MachineType}, nil
}