-
Notifications
You must be signed in to change notification settings - Fork 0
Calculate a resonable value for the --kube-reserved flag #44
Conversation
Kubernetes uses --kube-reserved to calculate the alocatable resources avalible on a node. This code uses the calucations documented by GKE here : https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-architecture to calculate appropriate values for these flags, for the current instance type.
func reservedMemory(instanceType *string) string { | ||
memory := InstanceMemory[*instanceType] | ||
reserved := 0.0 | ||
for i := 0; i < memory; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these if-else statement would be easier to read on as switch cases, specially if we'd use explicit ranges instead of relying on the previous missed branch.
pkg/node/node.go
Outdated
reserved += 0.02 | ||
} | ||
} | ||
if reserved == 0.0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this value come from? Couldn't find it on the GKE docs.
pkg/node/node.go
Outdated
reserved = 960.0 | ||
} | ||
return fmt.Sprintf("%.0fMi", reserved) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we're taking this into consideration:
GKE reserves an additional 100 MiB memory on each node for kubelet eviction
@@ -15,13 +15,14 @@ ExecStart=/usr/bin/kubelet \ | |||
--cni-bin-dir=/opt/cni/bin \ | |||
--cni-conf-dir=/etc/cni/net.d \ | |||
--container-runtime=docker \ | |||
--eviction-hard=memory.available<100Mi,nodefs.available<10%,nodefs.inodesFree<5% \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, got it! 😄
@@ -1,2 +1,4 @@ | |||
[Service] | |||
{{- if and .Node.ReservedCPU .Node.ReservedMemory }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if one of them is unavailable we're assuming the instance type is unknown and we won't configure any reservation. Cool! 😄 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep right ...
Kubernetes uses --kube-reserved to calculate the alocatable resources
avalible on a node.
This code uses the calucations documented by GKE
here : https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-architecture
to calculate appropriate values for these flags, for the current instance type.