07 ยท Prove the tuning¶
Goal: show that the advancedCompute settings in the NodeClass actually
reached the nodes, rather than taking the YAML's word for it.
maxPods: 48¶
The kubelet advertises how many pods a node can hold as capacity.pods:
kubectl get nodes -o custom-columns='NAME:.metadata.name,POOL:.metadata.labels.karpenter\.sh/nodepool,TYPE:.metadata.labels.node\.kubernetes\.io/instance-type,PODS:.status.capacity.pods'
From a test run of this guide, while the batch job from step 06 was running:
NAME POOL TYPE PODS
i-0123456789abc0001 spot-burst c7gd.2xlarge 48
i-0123456789abc0002 stable-static m6a.large 27
i-0123456789abc0003 stable-static m6a.large 27
i-0123456789abc0004 spot-burst c7gd.2xlarge 48
i-0123456789abc0005 system c6g.large 27
i-0123456789abc0006 system c6g.large 27
The 8-vCPU Spot nodes built from demo-default report 48: the NodeClass
setting reached the kubelet. The 2-vCPU m6a.large static nodes report 27,
the same as the built-in system nodes of the same size.
That's not a failure, it's the rule: maxPods is a maximum, not a target.
EKS applies the lowest of your value, its own per-instance-type value, and 110.
Smaller instances may fit fewer pods than you asked for; you can lower pod
density with maxPods, but never raise it above what Auto Mode allows for the
instance.
Spot nodes already gone?
The Spot nodes only exist while the batch job runs (about three minutes).
If you missed them, re-run the job (kubectl -n demo-nodepools delete job
report-batch, then kubectl apply -f manifests/31-burst-job.yaml) and run
the command again.
vm.max_map_count: 262144¶
vm.max_map_count is a kernel setting that isn't namespaced, so an ordinary,
unprivileged pod reading /proc/sys/vm/max_map_count sees the node's value.
The probe runs two pods: one on our pool, and a control on the built-in
general-purpose pool, which uses AWS's default NodeClass and none of our
tuning.
# Proves the NodeClass advancedCompute settings reached the node.
# vm.max_map_count is not namespaced, so an unprivileged pod reads the
# node's real value from /proc. Two pods: one on our stable-static pool,
# one on the built-in general-purpose pool as the control.
# Walkthrough: docs/07-prove-the-tuning.md
apiVersion: v1
kind: Pod
metadata:
name: tuning-probe
namespace: demo-nodepools
labels:
app: tuning-probe
spec:
restartPolicy: Never
nodeSelector:
workload-tier: stable
tolerations:
- key: workload-tier
operator: Equal
value: stable
effect: NoSchedule
containers:
- name: probe
image: public.ecr.aws/docker/library/busybox:1.36
command:
- sh
- -c
- echo "pool=stable-static node=$NODE_NAME vm.max_map_count=$(cat /proc/sys/vm/max_map_count)"
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
resources:
requests:
cpu: 10m
memory: 16Mi
limits:
memory: 16Mi
---
apiVersion: v1
kind: Pod
metadata:
name: tuning-probe-control
namespace: demo-nodepools
labels:
app: tuning-probe
spec:
restartPolicy: Never
nodeSelector:
karpenter.sh/nodepool: general-purpose # built-in pool, default NodeClass
containers:
- name: probe
image: public.ecr.aws/docker/library/busybox:1.36
command:
- sh
- -c
- echo "pool=general-purpose node=$NODE_NAME vm.max_map_count=$(cat /proc/sys/vm/max_map_count)"
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
resources:
requests:
cpu: 10m
memory: 16Mi
limits:
memory: 16Mi
The control pod needs a general-purpose node. If that pool has none, Auto
Mode launches one, which takes under a minute. Wait for both pods to finish:
kubectl -n demo-nodepools wait pod/tuning-probe pod/tuning-probe-control \
--for=jsonpath='{.status.phase}'=Succeeded --timeout=300s
kubectl -n demo-nodepools logs tuning-probe
kubectl -n demo-nodepools logs tuning-probe-control
pool=stable-static node=i-0123456789abc0007 vm.max_map_count=262144
pool=general-purpose node=i-0123456789abc0008 vm.max_map_count=1048576
tls: internal error on the control pod's logs?
Its node is seconds old and the kubelet's serving certificate isn't ready
yet. Wait 20 seconds and run the logs command again.
Our node reports 262144, the value from the NodeClass. The control reports the Auto Mode node's own default, 1048576: Bottlerocket's value, not the Linux kernel's 65530. Same cluster, same image, different infrastructure contract.
Notice the direction, though: the "tuned" node has a quarter of the limit of
the untuned one. That's the point of reading defaults before you replace them.
In production, set vm.max_map_count only to a value above what your nodes
already have.
Clean up the probes (the general-purpose node is consolidated away by Auto
Mode a minute or so after it's empty):
Optional: read the kubelet's live configuration¶
The kubelet exposes its running config through the API server's node proxy:
NODE=$(kubectl get nodes -l karpenter.sh/nodepool=stable-static -o jsonpath='{.items[0].metadata.name}')
kubectl get --raw "/api/v1/nodes/$NODE/proxy/configz" \
| jq '.kubeletconfig | {maxPods, evictionHard, containerLogMaxSize, containerLogMaxFiles}'
{
"maxPods": 27,
"evictionHard": {
"memory.available": "200Mi",
"nodefs.available": "10%"
},
"containerLogMaxSize": "20Mi",
"containerLogMaxFiles": 5
}
This is a static m6a.large node, so maxPods shows the clamped 27; the
eviction thresholds and log rotation from the NodeClass are live in the kubelet. This needs RBAC for the nodes/proxy subresource, which a cluster
admin has. If you get Forbidden, the capacity.pods check above is proof
enough.
Next: 08 Watch consolidation.