From 2a8f9539ab481282b840d6f9450f23385a68163e Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Fri, 15 Mar 2024 12:27:41 +0530 Subject: [PATCH] Enable swap on the node After switching to OVN-K we observed increase in memory resource and one way to tackle it to have swap enabled on the node. This PR is try to do following. - Enable only `NodeSwap` feature gate instead complete Tech preview features. - https://docs.openshift.com/container-platform/4.15/rest_api/config_apis/featuregate-config-openshift-io-v1.html - Add `swapaccount=1` to kernel argument which is required for the swap - https://docs.openshift.com/container-platform/4.15/nodes/nodes/nodes-nodes-managing.html#nodes-nodes-swap-memory_nodes-nodes-managing - Add swap feature to kubelet config - Add systemd unit file to create swap and enable it - Extend the disk size by 4GB because that much of space used for swap --- 99-kubelet-config.yaml | 12 +++++ ...shift-machineconfig-master-swap-count.yaml | 12 +++++ ...ift-machineconfig-master-swap-service.yaml | 44 +++++++++++++++++++ 99_feature-gate.yaml | 12 +++++ snc.sh | 7 ++- 5 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 99-kubelet-config.yaml create mode 100644 99-openshift-machineconfig-master-swap-count.yaml create mode 100644 99-openshift-machineconfig-master-swap-service.yaml create mode 100644 99_feature-gate.yaml diff --git a/99-kubelet-config.yaml b/99-kubelet-config.yaml new file mode 100644 index 00000000..f4fe291c --- /dev/null +++ b/99-kubelet-config.yaml @@ -0,0 +1,12 @@ +apiVersion: machineconfiguration.openshift.io/v1 +kind: KubeletConfig +metadata: + name: swap-config +spec: + machineConfigPoolSelector: + matchLabels: + pools.operator.machineconfiguration.openshift.io/master: "" + kubeletConfig: + failSwapOn: false + memorySwap: + swapBehavior: UnlimitedSwap diff --git a/99-openshift-machineconfig-master-swap-count.yaml b/99-openshift-machineconfig-master-swap-count.yaml new file mode 100644 index 00000000..7832ab4e --- /dev/null +++ b/99-openshift-machineconfig-master-swap-count.yaml @@ -0,0 +1,12 @@ +apiVersion: machineconfiguration.openshift.io/v1 +kind: MachineConfig +metadata: + labels: + machineconfiguration.openshift.io/role: master + name: 99-kernel-swapcount-arg +spec: + config: + ignition: + version: 3.4.0 + kernelArguments: + - swapaccount=1 diff --git a/99-openshift-machineconfig-master-swap-service.yaml b/99-openshift-machineconfig-master-swap-service.yaml new file mode 100644 index 00000000..b5c53fe4 --- /dev/null +++ b/99-openshift-machineconfig-master-swap-service.yaml @@ -0,0 +1,44 @@ +apiVersion: machineconfiguration.openshift.io/v1 +kind: MachineConfig +metadata: + labels: + machineconfiguration.openshift.io/role: master + name: 99-openshift-machineconfig-master-swap-service +spec: + config: + ignition: + version: 3.4.0 + systemd: + units: + - contents: | + [Unit] + Description=Create 4GB swap partition + Before=var-crc-swapfile1.swap + + [Service] + Type=oneshot + RemainAfterExit=yes + ExecStart=/usr/bin/mkdir -p /var/crc + ExecStart=/usr/bin/fallocate -l 4096m /var/crc/swapfile1 + ExecStart=/usr/bin/chmod 600 /var/crc/swapfile1 + ExecStart=/usr/sbin/mkswap /var/crc/swapfile1 + + [Install] + WantedBy=multi-user.target + enabled: false + name: swap-partition.service + - contents: | + [Unit] + Description=Turn on the swap + + [Swap] + What=/var/crc/swapfile1 + + [Install] + WantedBy=multi-user.target + enabled: false + name: var-crc-swapfile1.swap + networkd: {} + passwd: {} + storage: {} + osImageURL: "" diff --git a/99_feature-gate.yaml b/99_feature-gate.yaml new file mode 100644 index 00000000..73e12721 --- /dev/null +++ b/99_feature-gate.yaml @@ -0,0 +1,12 @@ +apiVersion: config.openshift.io/v1 +kind: FeatureGate +metadata: + name: cluster +spec: + customNoUpgrade: + enabled: + - NodeSwap + - BuildCSIVolumes + featureSet: CustomNoUpgrade +status: + featureGates: null diff --git a/snc.sh b/snc.sh index 6eede5ad..47098c5c 100755 --- a/snc.sh +++ b/snc.sh @@ -26,7 +26,7 @@ INSTALL_DIR=crc-tmp-install-data SNC_PRODUCT_NAME=${SNC_PRODUCT_NAME:-crc} SNC_CLUSTER_MEMORY=${SNC_CLUSTER_MEMORY:-14336} SNC_CLUSTER_CPUS=${SNC_CLUSTER_CPUS:-6} -CRC_VM_DISK_SIZE=${CRC_VM_DISK_SIZE:-31} +CRC_VM_DISK_SIZE=${CRC_VM_DISK_SIZE:-35} BASE_DOMAIN=${CRC_BASE_DOMAIN:-testing} CRC_PV_DIR="/mnt/pv-data" SSH="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i id_ecdsa_crc" @@ -147,6 +147,11 @@ cp cluster-network-03-config.yaml ${INSTALL_DIR}/manifests/ cp 99_master-chronyd-mask.yaml $INSTALL_DIR/openshift/ # Add dummy network unit file cp 99-openshift-machineconfig-master-dummy-networks.yaml $INSTALL_DIR/openshift/ +cp 99-openshift-machineconfig-master-swap-count.yaml $INSTALL_DIR/openshift/ +cp 99-openshift-machineconfig-master-swap-service.yaml $INSTALL_DIR/openshift/ +cp 99-kubelet-config.yaml $INSTALL_DIR/openshift/ +cp 99_feature-gate.yaml $INSTALL_DIR/openshift/ + # Add kubelet config resource to make change in kubelet DYNAMIC_DATA=$(base64 -w0 node-sizing-enabled.env) envsubst < 99_master-node-sizing-enabled-env.yaml.in > $INSTALL_DIR/openshift/99_master-node-sizing-enabled-env.yaml # Add codeReadyContainer as invoker to identify it with telemeter