Environment
cat /proc/version
Linux version 3.10.0-957.21.3.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Tue Jun 18 16:35:19 UTC 2019
root@10.101.1.30 ~$ cat /etc/redhat-releace
CentOS Linux release 7.5.1804 (Core)
cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
Installation
# Install k8s via rke2
curl -sfL https://get.rke2.io | sh -
# Enable rke2-server to start at boot
systemctl enable rke2-server.service
# Start rke2-server; it may take some time to initialize
systemctl start rke2-server.service
Check rke2-server Status
systemctl status rke2-server.service
A status of "running" indicates successful startup, as shown below:
● rke2-server.service - Rancher Kubernetes Engine v2 (server)
Loaded: loaded (/usr/lib/systemd/system/rke2-server.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2023-07-05 14:41:59 CST; 43s ago
Verify RKE2 Functionality
/var/lib/rancher/rke2/bin/kubectl \
--kubeconfig /etc/rancher/rke2/rke2.yaml get nodes
Output showing a node with status "Ready" confirms the Kubernetes setup is complete
NAME STATUS ROLES AGE VERSION
node2 Ready control-plane,etcd,master 7m48s v1.25.11+rke2r1
Validate Pod Health in the Cluster
/var/lib/rancher/rke2/bin/kubectl \
--kubeconfig /etc/rancher/rke2/rke2.yaml get pods --all-namespaces
Copy Scripts and Kubernetes Configuration (Opsional)
The file /etc/rancher/rke2/rke2.yaml holds credentials needed to connect to the Kubernetes cluster. It should be securely stored for future use with kubectl.
cp /var/lib/rancher/rke2/bin/kubectl /usr/local/bin/kubectl
cp /etc/rancher/rke2/rke2.yaml .kube/config
# After copying, these commands can be simplified assuming /usr/local/bin is in PATH
kubectl get nodes
kubectl get pods --all-namespaces
Complete Uninstallation
The contents of rke2-uninstalll.sh are as follows:
#!/bin/sh
set -ex
# ensure execution as root
if [ ! $(id -u) -eq 0 ]; then
echo "$(basename "${0}"): must be run as root" >&2
exit 1
fi
# verify if target directory is on its own mount point
check_target_mountpoint() {
mountpoint -q "$1"
}
# verify if target directory is read-only
check_target_ro() {
touch "$1"/.rke2-ro-test && rm -rf "$1"/.rke2-ro-test
test $? -ne 0
}
. /etc/os-release
if [ -r /etc/redhat-release ] || [ -r /etc/centos-release ] || [ -r /etc/oracle-release ]; then
# For RedHat/Oracle systems, determine installation method (yum or tar).
# Yum method assumes installation root under /usr
# Tar method assumes installation root under /usr/local
if rpm -q rke2-common >/dev/null 2>&1; then
: "${INSTALL_RKE2_ROOT:="/usr"}"
else
: "${INSTALL_RKE2_ROOT:="/usr/local"}"
fi
elif [ "${ID_LIKE%%[ ]*}" = "suse" ]; then
if rpm -q rke2-common >/dev/null 2>&1; then
: "${INSTALL_RKE2_ROOT:="/usr"}"
if [ -x /usr/sbin/transactional-update ]; then
transactional_update="transactional-update -c --no-selfupdate -d run"
fi
elif check_target_mountpoint "/usr/local" || check_target_ro "/usr/local"; then
# if /usr/local is mounted or read-only, assume installation in /opt/rke2
: "${INSTALL_RKE2_ROOT:="/opt/rke2"}"
else
: "${INSTALL_RKE2_ROOT:="/usr/local"}"
fi
else
: "${INSTALL_RKE2_ROOT:="/usr/local"}"
fi
uninstall_killall()
{
_killall="$(dirname "$0")/rke2-killall.sh"
if [ -e "${_killall}" ]; then
eval "${_killall}"
fi
}
uninstall_disable_services()
{
if command -v systemctl >/dev/null 2>&1; then
systemctl disable rke2-server || true
systemctl disable rke2-agent || true
systemctl reset-failed rke2-server || true
systemctl reset-failed rke2-agent || true
systemctl daemon-reload
fi
}
uninstall_remove_files()
{
if [ -r /etc/redhat-release ] || [ -r /etc/centos-release ] || [ -r /etc/oracle-release ]; then
yum remove -y "rke2-*"
rm -f /etc/yum.repos.d/rancher-rke2*.repo
fi
if [ "${ID_LIKE%%[ ]*}" = "suse" ]; then
if rpm -q rke2-common >/dev/null 2>&1; then
# rke2 rpm detected
uninstall_cmd="zypper remove -y rke2-server rke2-agent rke2-common rke2-selinux"
if [ "${TRANSACTIONAL_UPDATE=false}" != "true" ] && [ -x /usr/sbin/transactional-update ]; then
uninstall_cmd="transactional-update -c --no-selfupdate -d run $uninstall_cmd"
fi
$uninstall_cmd
rm -f /etc/zypp/repos.d/rancher-rke2*.repo
fi
fi
$transactional_update find "${INSTALL_RKE2_ROOT}/lib/systemd/system" -name rke2-*.service -type f -delete
$transactional_update find "${INSTALL_RKE2_ROOT}/lib/systemd/system" -name rke2-*.env -type f -delete
find /etc/systemd/system -name rke2-*.service -type f -delete
$transactional_update rm -f "${INSTALL_RKE2_ROOT}/bin/rke2"
$transactional_update rm -f "${INSTALL_RKE2_ROOT}/bin/rke2-killall.sh"
$transactional_update rm -rf "${INSTALL_RKE2_ROOT}/share/rke2"
rm -rf /etc/rancher/rke2
rm -rf /etc/rancher/node
rm -d /etc/rancher || true
rm -rf /etc/cni
rm -rf /opt/cni/bin
rm -rf /var/lib/kubelet
rm -rf /var/lib/rancher/rke2
rm -d /var/lib/rancher || true
if type fapolicyd >/dev/null 2>&1; then
if [ -f /etc/fapolicyd/rules.d/80-rke2.rules ]; then
rm -f /etc/fapolicyd/rules.d/80-rke2.rules
fi
fagenrules --load
systemctl restart fapolicyd
fi
}
uninstall_remove_self()
{
$transactional_update rm -f "${INSTALL_RKE2_ROOT}/bin/rke2-uninstall.sh"
}
uninstall_remove_policy()
{
semodule -r rke2 || true
}
uninstall_killall
trap uninstall_remove_self EXIT
uninstall_disable_services
uninstall_remove_files
uninstall_remove_policy
sudo rm -rf ~/.kube/
References
Setting up High Availability RKE2 Kubernetes Clusters for Rancher