#!/bin/bash
#***************************************************************#
# ScriptName: uk3sinit.sh
# Author: xhy
# Create Date: 2025-03-08 01:00
# Modify Author: xhy
# Modify Date: 2025-03-08 01:00
# Version: v1
#***************************************************************#

# Turn off and disable the firewalld.
systemctl disable ufw --now || true

# Modify related kernel parameters & Disable the swap.
cat > /etc/sysctl.d/k3s.conf << EOF
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.tcp_tw_recycle = 0
vm.swappiness = 0
vm.overcommit_memory = 1
vm.panic_on_oom = 0
net.ipv6.conf.all.disable_ipv6 = 1
EOF
sysctl -p /etc/sysctl.d/k3s.conf >&/dev/null
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
modprobe br_netfilter

# Add ipvs modules

cat > /etc/modules-load.d/ipvs.conf <<EOF
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack
EOF

systemctl restart systemd-modules-load.service

# Install rpm
apt-get -y install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat wget
