Skip to content

Commit e24e3c0

Browse files
committed
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
1 parent 47ff542 commit e24e3c0

6 files changed

+89
-1
lines changed

99-kubelet-config.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: machineconfiguration.openshift.io/v1
2+
kind: KubeletConfig
3+
metadata:
4+
name: swap-config
5+
spec:
6+
machineConfigPoolSelector:
7+
matchLabels:
8+
pools.operator.machineconfiguration.openshift.io/master: ""
9+
kubeletConfig:
10+
failSwapOn: false
11+
memorySwap:
12+
swapBehavior: UnlimitedSwap
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: machineconfiguration.openshift.io/v1
2+
kind: MachineConfig
3+
metadata:
4+
labels:
5+
machineconfiguration.openshift.io/role: master
6+
name: 99-kernel-swapcount-arg
7+
spec:
8+
config:
9+
ignition:
10+
version: 3.4.0
11+
kernelArguments:
12+
- swapaccount=1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: machineconfiguration.openshift.io/v1
2+
kind: MachineConfig
3+
metadata:
4+
labels:
5+
machineconfiguration.openshift.io/role: master
6+
name: 99-openshift-machineconfig-master-swap-service
7+
spec:
8+
config:
9+
ignition:
10+
version: 3.4.0
11+
systemd:
12+
units:
13+
- contents: |
14+
[Unit]
15+
Description=Create 4GB swap partition
16+
Before=var-crc-swapfile1.swap
17+
18+
[Service]
19+
Type=oneshot
20+
RemainAfterExit=yes
21+
ExecStart=/usr/bin/mkdir -p /var/crc
22+
ExecStart=/usr/bin/fallocate -l 4096m /var/crc/swapfile1
23+
ExecStart=/usr/bin/chmod 600 /var/crc/swapfile1
24+
ExecStart=/usr/sbin/mkswap /var/crc/swapfile1
25+
26+
[Install]
27+
WantedBy=multi-user.target
28+
enabled: false
29+
name: swap-partition.service
30+
- contents: |
31+
[Unit]
32+
Description=Turn on the swap
33+
34+
[Swap]
35+
What=/var/crc/swapfile1
36+
37+
[Install]
38+
WantedBy=multi-user.target
39+
enabled: false
40+
name: var-crc-swapfile1.swap
41+
networkd: {}
42+
passwd: {}
43+
storage: {}
44+
osImageURL: ""

99_feature-gate.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: config.openshift.io/v1
2+
kind: FeatureGate
3+
metadata:
4+
name: cluster
5+
spec:
6+
customNoUpgrade:
7+
enabled:
8+
- NodeSwap
9+
- BuildCSIVolumes
10+
featureSet: CustomNoUpgrade
11+
status:
12+
featureGates: null

createdisk.sh

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ if [ ${BUNDLE_TYPE} != "microshift" ]; then
5151

5252
# Stop the kubelet service so it will not reprovision the pods
5353
${SSH} core@${VM_IP} -- sudo systemctl stop kubelet
54+
# Enable swap partition and swap service
55+
${SSH} core@${VM_IP} -- sudo systemctl enable swap-partition.service
56+
${SSH} core@${VM_IP} -- sudo systemctl enable var-crc-swapfile1.swap
5457
fi
5558

5659
# Enable the system and user level podman.socket service for API V2

snc.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ INSTALL_DIR=crc-tmp-install-data
2626
SNC_PRODUCT_NAME=${SNC_PRODUCT_NAME:-crc}
2727
SNC_CLUSTER_MEMORY=${SNC_CLUSTER_MEMORY:-14336}
2828
SNC_CLUSTER_CPUS=${SNC_CLUSTER_CPUS:-6}
29-
CRC_VM_DISK_SIZE=${CRC_VM_DISK_SIZE:-31}
29+
CRC_VM_DISK_SIZE=${CRC_VM_DISK_SIZE:-35}
3030
BASE_DOMAIN=${CRC_BASE_DOMAIN:-testing}
3131
CRC_PV_DIR="/mnt/pv-data"
3232
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/
147147
cp 99_master-chronyd-mask.yaml $INSTALL_DIR/openshift/
148148
# Add dummy network unit file
149149
cp 99-openshift-machineconfig-master-dummy-networks.yaml $INSTALL_DIR/openshift/
150+
cp 99-openshift-machineconfig-master-swap-count.yaml $INSTALL_DIR/openshift/
151+
cp 99-openshift-machineconfig-master-swap-service.yaml $INSTALL_DIR/openshift/
152+
cp 99-kubelet-config.yaml $INSTALL_DIR/openshift/
153+
cp 99_feature-gate.yaml $INSTALL_DIR/openshift/
154+
150155
# Add kubelet config resource to make change in kubelet
151156
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
152157
# Add codeReadyContainer as invoker to identify it with telemeter

0 commit comments

Comments
 (0)