diff --git a/examples/v1beta1/minValues-family.yaml b/examples/v1beta1/minValues-family.yaml new file mode 100644 index 000000000000..30a54e737f89 --- /dev/null +++ b/examples/v1beta1/minValues-family.yaml @@ -0,0 +1,52 @@ +# This example will use spot instance type for all provisioned instances +# and enforces minValues to instance families which means at least that number of unique instance +# families is required by the scheduler for the NodeClaim creation. +--- +apiVersion: karpenter.sh/v1beta1 +kind: NodePool +metadata: + name: spot + annotations: + kubernetes.io/description: "NodePool for provisioning spot capacity" +spec: + template: + spec: + requirements: + - key: karpenter.sh/capacity-type + operator: In + values: ["spot"] + - key: kubernetes.io/arch + operator: In + values: ["amd64"] + - key: kubernetes.io/os + operator: In + values: ["linux"] + - key: karpenter.k8s.aws/instance-category + operator: In + values: ["c", "m", "r"] + - key: karpenter.k8s.aws/instance-family + operator: Exists + minValues: 5 + - key: karpenter.k8s.aws/instance-generation + operator: Gt + values: ["2"] + nodeClassRef: + apiVersion: karpenter.k8s.aws/v1beta1 + kind: EC2NodeClass + name: default +--- +apiVersion: karpenter.k8s.aws/v1beta1 +kind: EC2NodeClass +metadata: + name: default + annotations: + kubernetes.io/description: "General purpose EC2NodeClass for running Amazon Linux 2 nodes" +spec: + amiFamily: AL2 # Amazon Linux 2 + role: "KarpenterNodeRole-${CLUSTER_NAME}" # replace with your cluster name + subnetSelectorTerms: + - tags: + karpenter.sh/discovery: "${CLUSTER_NAME}" # replace with your cluster name + securityGroupSelectorTerms: + - tags: + karpenter.sh/discovery: "${CLUSTER_NAME}" # replace with your cluster name \ No newline at end of file diff --git a/examples/v1beta1/minValues-multiple-keys.yaml b/examples/v1beta1/minValues-multiple-keys.yaml new file mode 100644 index 000000000000..1fa780147d8b --- /dev/null +++ b/examples/v1beta1/minValues-multiple-keys.yaml @@ -0,0 +1,56 @@ +# This example will use spot instance type for all provisioned instances and enforces minValues to various keys where it is defined i.e +# at least 2 unique instance families from [c,m,r], 5 unique instance families [eg: "m5","m5d","m5dn","c5","c5d","c4" etc], 2 unique instance types [eg: "c5.2xlarge","c4.xlarge" etc] are required by the scheduler for the NodeClaim creation. +# This ensures minimum flexiblity required to schedule pods into spot nodes. +--- +apiVersion: karpenter.sh/v1beta1 +kind: NodePool +metadata: + name: spot + annotations: + kubernetes.io/description: "NodePool for provisioning spot capacity" +spec: + template: + spec: + requirements: + - key: karpenter.sh/capacity-type + operator: In + values: ["spot"] + - key: kubernetes.io/arch + operator: In + values: ["amd64"] + - key: kubernetes.io/os + operator: In + values: ["linux"] + - key: karpenter.k8s.aws/instance-category + operator: In + values: ["c", "m", "r"] + minValues: 2 + - key: karpenter.k8s.aws/instance-family + operator: Exists + minValues: 5 + - key: node.kubernetes.io/instance-type + operator: Exists + minValues: 2 + - key: karpenter.k8s.aws/instance-generation + operator: Gt + values: ["2"] + nodeClassRef: + apiVersion: karpenter.k8s.aws/v1beta1 + kind: EC2NodeClass + name: default +--- +apiVersion: karpenter.k8s.aws/v1beta1 +kind: EC2NodeClass +metadata: + name: default + annotations: + kubernetes.io/description: "General purpose EC2NodeClass for running Amazon Linux 2 nodes" +spec: + amiFamily: AL2 # Amazon Linux 2 + role: "KarpenterNodeRole-${CLUSTER_NAME}" # replace with your cluster name + subnetSelectorTerms: + - tags: + karpenter.sh/discovery: "${CLUSTER_NAME}" # replace with your cluster name + securityGroupSelectorTerms: + - tags: + karpenter.sh/discovery: "${CLUSTER_NAME}" # replace with your cluster name \ No newline at end of file diff --git a/website/content/en/docs/concepts/nodepools.md b/website/content/en/docs/concepts/nodepools.md index 93efff341595..f890569adea3 100644 --- a/website/content/en/docs/concepts/nodepools.md +++ b/website/content/en/docs/concepts/nodepools.md @@ -71,6 +71,12 @@ spec: - key: "karpenter.k8s.aws/instance-category" operator: In values: ["c", "m", "r"] + # minValues here enforces the scheduler to consider at least that number of unique instance-category to schedule the pods. + minValues: 2 + - key: "karpenter.k8s.aws/instance-family" + operator: In + values: ["m5","m5d","c5","c5d","c4","r4"] + minValues: 5 - key: "karpenter.k8s.aws/instance-cpu" operator: In values: ["4", "8", "16", "32"] @@ -224,6 +230,69 @@ Karpenter prioritizes Spot offerings if the NodePool allows Spot and on-demand i Karpenter also allows `karpenter.sh/capacity-type` to be used as a topology key for enforcing topology-spread. +Along with the combination of [key,operator,values] in the requirements, Karpenter also supports `minValues` in the NodePool requirements block, allowing the scheduler to be aware of user-specified flexibility minimums while scheduling pods to a cluster. If Karpenter cannot meet this minimum flexibility for each key when scheduling a pod, it will fail the scheduling loop for that NodePool, either falling back to another NodePool which meets the pod requirements or failing scheduling the pod altogether. + +For example, the below spec will use spot instance type for all provisioned instances and enforces `minValues` to various keys where it is defined +i.e at least 2 unique instance families from [c,m,r], 5 unique instance families [eg: "m5","m5d","r4","c5","c5d","c4" etc], 10 unique instance types [eg: "c5.2xlarge","c4.xlarge" etc] is required for scheduling the pods. + +```yaml +spec: + template: + spec: + requirements: + - key: kubernetes.io/arch + operator: In + values: ["amd64"] + - key: kubernetes.io/os + operator: In + values: ["linux"] + - key: karpenter.k8s.aws/instance-category + operator: In + values: ["c", "m", "r"] + minValues: 2 + - key: karpenter.k8s.aws/instance-family + operator: Exists + minValues: 5 + - key: node.kubernetes.io/instance-type + operator: Exists + minValues: 10 + - key: karpenter.k8s.aws/instance-generation + operator: Gt + values: ["2"] +``` + +Note that `minValues` can be used with multiple operators and multiple requirements. And if the `minValues` are defined with multiple operators for the same requirement key, scheduler considers the max of all the `minValues` for that requirement. For example, the below spec requires scheduler to consider at least 5 instance-family to schedule the pods. + +```yaml +spec: + template: + spec: + requirements: + - key: kubernetes.io/arch + operator: In + values: ["amd64"] + - key: kubernetes.io/os + operator: In + values: ["linux"] + - key: karpenter.k8s.aws/instance-category + operator: In + values: ["c", "m", "r"] + minValues: 2 + - key: karpenter.k8s.aws/instance-family + operator: Exists + minValues: 5 + - key: karpenter.k8s.aws/instance-family + operator: In + values: ["m5","m5d","c5","c5d","c4","r4"] + minValues: 3 + - key: node.kubernetes.io/instance-type + operator: Exists + minValues: 10 + - key: karpenter.k8s.aws/instance-generation + operator: Gt + values: ["2"] +``` + {{% alert title="Recommended" color="primary" %}} Karpenter allows you to be extremely flexible with your NodePools by only constraining your instance types in ways that are absolutely necessary for your cluster. By default, Karpenter will enforce that you specify the `spec.template.spec.requirements` field, but will not enforce that you specify any requirements within the field. If you choose to specify `requirements: []`, this means that you will completely flexible to _all_ instance types that your cloud provider supports. diff --git a/website/content/en/preview/concepts/nodepools.md b/website/content/en/preview/concepts/nodepools.md index d524445f6133..8964c5dd4781 100644 --- a/website/content/en/preview/concepts/nodepools.md +++ b/website/content/en/preview/concepts/nodepools.md @@ -71,6 +71,12 @@ spec: - key: "karpenter.k8s.aws/instance-category" operator: In values: ["c", "m", "r"] + # minValues here enforces the scheduler to consider at least that number of unique instance-category to schedule the pods. + minValues: 2 + - key: "karpenter.k8s.aws/instance-family" + operator: In + values: ["m5","m5d","c5","c5d","c4","r4"] + minValues: 5 - key: "karpenter.k8s.aws/instance-cpu" operator: In values: ["4", "8", "16", "32"] @@ -224,6 +230,69 @@ Karpenter prioritizes Spot offerings if the NodePool allows Spot and on-demand i Karpenter also allows `karpenter.sh/capacity-type` to be used as a topology key for enforcing topology-spread. +Along with the combination of [key,operator,values] in the requirements, Karpenter also supports `minValues` in the NodePool requirements block, allowing the scheduler to be aware of user-specified flexibility minimums while scheduling pods to a cluster. If Karpenter cannot meet this minimum flexibility for each key when scheduling a pod, it will fail the scheduling loop for that NodePool, either falling back to another NodePool which meets the pod requirements or failing scheduling the pod altogether. + +For example, the below spec will use spot instance type for all provisioned instances and enforces `minValues` to various keys where it is defined +i.e at least 2 unique instance families from [c,m,r], 5 unique instance families [eg: "m5","m5d","r4","c5","c5d","c4" etc], 10 unique instance types [eg: "c5.2xlarge","c4.xlarge" etc] is required for scheduling the pods. + +```yaml +spec: + template: + spec: + requirements: + - key: kubernetes.io/arch + operator: In + values: ["amd64"] + - key: kubernetes.io/os + operator: In + values: ["linux"] + - key: karpenter.k8s.aws/instance-category + operator: In + values: ["c", "m", "r"] + minValues: 2 + - key: karpenter.k8s.aws/instance-family + operator: Exists + minValues: 5 + - key: node.kubernetes.io/instance-type + operator: Exists + minValues: 10 + - key: karpenter.k8s.aws/instance-generation + operator: Gt + values: ["2"] +``` + +Note that `minValues` can be used with multiple operators and multiple requirements. And if the `minValues` are defined with multiple operators for the same requirement key, scheduler considers the max of all the `minValues` for that requirement. For example, the below spec requires scheduler to consider at least 5 instance-family to schedule the pods. + +```yaml +spec: + template: + spec: + requirements: + - key: kubernetes.io/arch + operator: In + values: ["amd64"] + - key: kubernetes.io/os + operator: In + values: ["linux"] + - key: karpenter.k8s.aws/instance-category + operator: In + values: ["c", "m", "r"] + minValues: 2 + - key: karpenter.k8s.aws/instance-family + operator: Exists + minValues: 5 + - key: karpenter.k8s.aws/instance-family + operator: In + values: ["m5","m5d","c5","c5d","c4","r4"] + minValues: 3 + - key: node.kubernetes.io/instance-type + operator: Exists + minValues: 10 + - key: karpenter.k8s.aws/instance-generation + operator: Gt + values: ["2"] +``` + {{% alert title="Recommended" color="primary" %}} Karpenter allows you to be extremely flexible with your NodePools by only constraining your instance types in ways that are absolutely necessary for your cluster. By default, Karpenter will enforce that you specify the `spec.template.spec.requirements` field, but will not enforce that you specify any requirements within the field. If you choose to specify `requirements: []`, this means that you will completely flexible to _all_ instance types that your cloud provider supports. diff --git a/website/content/en/v0.35/concepts/nodepools.md b/website/content/en/v0.35/concepts/nodepools.md index cb85d5988475..9937cd29a095 100644 --- a/website/content/en/v0.35/concepts/nodepools.md +++ b/website/content/en/v0.35/concepts/nodepools.md @@ -71,6 +71,12 @@ spec: - key: "karpenter.k8s.aws/instance-category" operator: In values: ["c", "m", "r"] + # minValues here enforces the scheduler to consider at least that number of unique instance-category to schedule the pods. + minValues: 2 + - key: "karpenter.k8s.aws/instance-family" + operator: In + values: ["m5","m5d","c5","c5d","c4","r4"] + minValues: 5 - key: "karpenter.k8s.aws/instance-cpu" operator: In values: ["4", "8", "16", "32"] @@ -224,6 +230,69 @@ Karpenter prioritizes Spot offerings if the NodePool allows Spot and on-demand i Karpenter also allows `karpenter.sh/capacity-type` to be used as a topology key for enforcing topology-spread. +Along with the combination of [key,operator,values] in the requirements, Karpenter also supports `minValues` in the NodePool requirements block, allowing the scheduler to be aware of user-specified flexibility minimums while scheduling pods to a cluster. If Karpenter cannot meet this minimum flexibility for each key when scheduling a pod, it will fail the scheduling loop for that NodePool, either falling back to another NodePool which meets the pod requirements or failing scheduling the pod altogether. + +For example, the below spec will use spot instance type for all provisioned instances and enforces `minValues` to various keys where it is defined +i.e at least 2 unique instance families from [c,m,r], 5 unique instance families [eg: "m5","m5d","r4","c5","c5d","c4" etc], 10 unique instance types [eg: "c5.2xlarge","c4.xlarge" etc] is required for scheduling the pods. + +```yaml +spec: + template: + spec: + requirements: + - key: kubernetes.io/arch + operator: In + values: ["amd64"] + - key: kubernetes.io/os + operator: In + values: ["linux"] + - key: karpenter.k8s.aws/instance-category + operator: In + values: ["c", "m", "r"] + minValues: 2 + - key: karpenter.k8s.aws/instance-family + operator: Exists + minValues: 5 + - key: node.kubernetes.io/instance-type + operator: Exists + minValues: 10 + - key: karpenter.k8s.aws/instance-generation + operator: Gt + values: ["2"] +``` + +Note that `minValues` can be used with multiple operators and multiple requirements. And if the `minValues` are defined with multiple operators for the same requirement key, scheduler considers the max of all the `minValues` for that requirement. For example, the below spec requires scheduler to consider at least 5 instance-family to schedule the pods. + +```yaml +spec: + template: + spec: + requirements: + - key: kubernetes.io/arch + operator: In + values: ["amd64"] + - key: kubernetes.io/os + operator: In + values: ["linux"] + - key: karpenter.k8s.aws/instance-category + operator: In + values: ["c", "m", "r"] + minValues: 2 + - key: karpenter.k8s.aws/instance-family + operator: Exists + minValues: 5 + - key: karpenter.k8s.aws/instance-family + operator: In + values: ["m5","m5d","c5","c5d","c4","r4"] + minValues: 3 + - key: node.kubernetes.io/instance-type + operator: Exists + minValues: 10 + - key: karpenter.k8s.aws/instance-generation + operator: Gt + values: ["2"] +``` + {{% alert title="Recommended" color="primary" %}} Karpenter allows you to be extremely flexible with your NodePools by only constraining your instance types in ways that are absolutely necessary for your cluster. By default, Karpenter will enforce that you specify the `spec.template.spec.requirements` field, but will not enforce that you specify any requirements within the field. If you choose to specify `requirements: []`, this means that you will completely flexible to _all_ instance types that your cloud provider supports.