Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix kube_reserved so it only controls kubeReservedCgroup #11367

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

rptaylor
Copy link
Contributor

@rptaylor rptaylor commented Jul 9, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:
I believe there may have been a misapprehension in the implementation of #9209

It introduced a new kube_reserved variable with a default value of false, and made all kubeReserved declarations conditional on it. I believe this was a mistake as the documentation makes it clear that you can set kubeReserved without kubeReservedCgroup, for the purposes of reserving resources without enforcing, which is the safest default behaviour.

This MR restores the previous behaviour - kubeReserved can/should always be defined and does not depend on or require the creation of separate cgroups, or running daemons in those cgroups, or configuring kubeReservedCgroup. The important primary purpose of this is to reduce the Node Allocatable resource amount to guarantee resources for k8s daemons purely on a scheduling basis, even if their cgroup config is not modified.

Which issue(s) this PR fixes:

Fixes #9692

Special notes for your reviewer:
Please see this comment
This is just what I have been trying to figure out for the last several days. Let's review carefully to make sure it's right.

Does this PR introduce a user-facing change?:

This restores the pre-9209 behaviour of reserving a small default amount of RAM and CPU to ensure stability of k8s daemons.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 9, 2024
@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 9, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @rptaylor. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@rptaylor
Copy link
Contributor Author

rptaylor commented Jul 9, 2024

I confirmed that after upgrading to Kubespray 2.21 with the default kube_reserved: false , these lines get removed from /etc/kubernetes/kubelet-config.yaml

kubeReserved:
  cpu: 100m
  memory: 256Mi

This demonstrates the problem, it causes the allocatable resources reported on a node to increase from (pre 2.21)

Allocatable:
  cpu:                15900m
  ephemeral-storage:  483172476948
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             61438100Ki
  pods:               110

to (post 2.21)

  Allocatable:
  cpu:                16
  ephemeral-storage:  483172476948
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             61700232Ki
  pods:               110

This means that pods can consume 100% of node resources, which would cause kubelet/containerd to crash or become unresponsive.

@rptaylor
Copy link
Contributor Author

rptaylor commented Jul 9, 2024

I applied this patch on a v2.21 cluster via ansible-playbook -b --become-user=root ~/ubernetes/kubespray/cluster.yml -t defaults,node --diff and it had the expected result, showing for each node that kubeReserved is restored:

--- before: /etc/kubernetes/kubelet-config.yaml
+++ after: /home/fedora/.ansible/tmp/ansible-local-8422569_ougct4/tmp4l2hqnen/kubelet-config.v1beta1.yaml.j2
@@ -27,6 +27,9 @@
 rotateCertificates: true
 clusterDNS:
 - 169.254.25.10
+kubeReserved:
+  cpu: 200m
+  memory: 512Mi
 resolvConf: "/etc/resolv.conf"
 eventRecordQPS: 5
 shutdownGracePeriod: 60s

Afterwards the nodeAllocatable reduced as expected.

@MrFreezeex
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 10, 2024
Copy link
Member

@MrFreezeex MrFreezeex left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation and the fix :D
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 10, 2024
@rptaylor
Copy link
Contributor Author

/assign ant31

@rptaylor
Copy link
Contributor Author

@ant31 @ErikJiang Can you please take a look and /approve ?

/assign ErikJiang

Copy link
Contributor

@mzaian mzaian left a comment

Choose a reason for hiding this comment

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

Hello @rptaylor

Thanks a lot for the fix and explaination.

/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MrFreezeex, mzaian, rptaylor

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 26, 2024
@k8s-ci-robot k8s-ci-robot merged commit 468c564 into kubernetes-sigs:master Jul 26, 2024
39 checks passed
bogd pushed a commit to bogd/kubespray that referenced this pull request Jul 26, 2024
@rptaylor rptaylor deleted the fix-kube-reserved branch August 2, 2024 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(Re-)Enable resource reservation by default for core components and host container runtime
6 participants