Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Enable option to have K8s work with swap#87

Open
kishen-v wants to merge 1 commit into
ppc64le-cloud:masterfrom
kishen-v:select-swap
Open

Enable option to have K8s work with swap#87
kishen-v wants to merge 1 commit into
ppc64le-cloud:masterfrom
kishen-v:select-swap

Conversation

@kishen-v

Copy link
Copy Markdown
Contributor

This PR enables kubernetes to leverage swap memory, which is currently beta - https://kubernetes.io/blog/2023/08/24/swap-linux-beta/

Steps to use this feature:
Toggle swap_enabled var in groupvars/all to true. Initially the swap size is set to 4GB, which can be revisited later.


TASK [Toggle SElinux and swap settings on node] ***********************************

TASK [toggle-swap-selinux : Disable SWAP (1/2)] ***********************************
skipping: [10.20.183.50]
skipping: [10.20.183.221]

TASK [toggle-swap-selinux : Disable SWAP in fstab (2/2)] **************************
skipping: [10.20.183.50]
skipping: [10.20.183.221]

TASK [toggle-swap-selinux : Create a swapfile and enable swap] ********************
changed: [10.20.183.221]
changed: [10.20.183.50]

TASK [toggle-swap-selinux : Set SELinux to permissive mode] ***********************
skipping: [10.20.183.50]
skipping: [10.20.183.221]
[root@kishen-kubernetes-swapon-2 ~]# swapon -s
Filename				Type		Size		Used		Priority
/swapfile                               file		4191936		24832		-2
[root@kishen-kubernetes-swapon-2 ~]# kubectl get nodes
NAME                         STATUS   ROLES           AGE     VERSION
kishen-kubernetes-swapon-1   Ready    <none>          3m55s   v1.32.2
kishen-kubernetes-swapon-2   Ready    control-plane   4m7s    v1.32.2

@ppc64le-cloud-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kishen-v
Once this PR has been reviewed and has the lgtm label, please assign mkumatag for approval. For more information see the Kubernetes Code Review Process.

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

Details 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

@kishen-v

Copy link
Copy Markdown
Contributor Author

cc @Karthik-K-N

@ppc64le-cloud-bot ppc64le-cloud-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 21, 2025
@Karthik-K-N

Copy link
Copy Markdown

Thank you for adding this feature.

{% if (swap_enabled is defined) and swap_enabled %}
failSwapOn: false
featureGates:
NodeSwap: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this not beta yet? if yes - why in feature gate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @mkumatag,
I'd followed this guide: https://kubernetes.io/blog/2023/08/24/swap-linux-beta/

Plus we do not require the featureGates to be set, it seems to work okay without it.
Thanks!

swapon -s
when: swap_enabled

- name: Set SELinux to permissive mode

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why is this selinux here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The selinux changes had been here for a while:
https://github.com/ppc64le-cloud/k8s-ansible/blob/5416284ada67db1fe6dc7a2d25fabe96d4892c11/roles/disable-swap-selinux/tasks/main.yml

This file was renamed from disable-swap-selinux to toggle-swap-selinux to bring relevance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

toggling two different param which aren't related in one file doesn't make sense to me, we need to find some other way deal with these params.

@kishen-v kishen-v added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants