Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Calculate a resonable value for the --kube-reserved flag #44

Merged
merged 4 commits into from
Sep 18, 2018
Merged

Conversation

errm
Copy link
Owner

@errm errm commented Sep 17, 2018

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.

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.
@errm errm requested a review from mtpereira September 18, 2018 08:28
func reservedMemory(instanceType *string) string {
memory := InstanceMemory[*instanceType]
reserved := 0.0
for i := 0; i < memory; i++ {
Copy link
Collaborator

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 {
Copy link
Collaborator

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)
}
Copy link
Collaborator

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% \
Copy link
Collaborator

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 }}
Copy link
Collaborator

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! 😄 👍

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep right ...

@errm errm merged commit e695b61 into master Sep 18, 2018
@errm errm deleted the kube-reserved branch September 18, 2018 15:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants