From 80ceb53f6bfda1b15d11277f673914fe803f9932 Mon Sep 17 00:00:00 2001 From: Martin Montes Date: Sat, 11 May 2024 18:49:29 +0200 Subject: [PATCH] Added custom homelab configuration --- .../kubernetes-admin@homelab/config.yaml | 13 +++++ .k9s/config.yaml | 9 ++- k9s.sh | 55 +++++++++++++++---- 3 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 .k9s/clusters/homelab/kubernetes-admin@homelab/config.yaml diff --git a/.k9s/clusters/homelab/kubernetes-admin@homelab/config.yaml b/.k9s/clusters/homelab/kubernetes-admin@homelab/config.yaml new file mode 100644 index 0000000..7bad2c2 --- /dev/null +++ b/.k9s/clusters/homelab/kubernetes-admin@homelab/config.yaml @@ -0,0 +1,13 @@ +k9s: + cluster: homelab + skin: narsingh + namespace: + active: default + lockFavorites: false + favorites: + - default + view: + active: po + featureGates: + nodeShell: true + portForwardAddress: localhost diff --git a/.k9s/config.yaml b/.k9s/config.yaml index ec5792e..b87f5b5 100644 --- a/.k9s/config.yaml +++ b/.k9s/config.yaml @@ -1,3 +1,10 @@ k9s: ui: - skin: nord \ No newline at end of file + skin: nord + shellPod: + image: nicolaka/netshoot + namespace: default + limits: + cpu: 100m + memory: 100Mi + tty: true \ No newline at end of file diff --git a/k9s.sh b/k9s.sh index 9555fb5..48f2941 100755 --- a/k9s.sh +++ b/k9s.sh @@ -13,21 +13,46 @@ if [ -z $ARCH ]; then fi # yq +echo "Installing yq..." + YQ_VERSION=v4.43.1 YQ_URL=https://github.com/mikefarah/yq/releases/download/$YQ_VERSION/yq_linux_$ARCH -install_bin yq $YQ_URL + +if ! command -v yq &> /dev/null; then + install_bin yq $YQ_URL +else + echo "yq is already installed" +fi # k9s -echo "Installing k9s" +echo "🐶 Installing k9s..." -K9S_CONFIG=$USER_HOME/.config/k9s -if [ -d "$K9S_CONFIG" ]; then - echo "Deleting existing config" - rm -rf "$K9S_CONFIG" -fi -if [ -d "k9s" ]; then - echo "Deleting existing upstream repo" - rm -rf "k9s" +K9S_CONFIG=${XDG_CONFIG_HOME:="$USER_HOME/.config/k9s"} +K9S_CTX=${XDG_DATA_HOME:="$USER_HOME/.local/share/k9s"} + +function cleanup() { + if [ -d "$K9S_CONFIG" ]; then + echo "Deleting existing config at '$K9S_CONFIG'..." + rm -rf "$K9S_CONFIG" + fi + if [ -d "$K9S_CTX" ]; then + echo "Deleting existing contexts at '$K9S_CTX'..." + rm -rf "$K9S_CTX" + fi + if [ -d "k9s" ]; then + echo "Deleting existing 'k9s' folder..." + rm -rf "k9s" + fi +} + +if [ "$1" == "--force" -o "$1" == "-f" -o "$1" == "-y" ]; then + cleanup +else + read -p "Do you want to cleanup existing config @ '$K9S_CONFIG' and contexts @ '$K9S_CTX'? (y/n) " -n 1 + echo "" + if [[ $REPLY =~ ^[Yy]$ ]]; then + cleanup + fi fi K9S_VERSION=${K9S_VERSION:-v0.32.4} @@ -38,6 +63,9 @@ mkdir -p "$K9S_CONFIG" mkdir -p "$K9S_CONFIG/skins" touch "$K9S_CONFIG/plugins.yaml" +mkdir -p "$K9S_CTX" +mkdir -p "$K9S_CTX/clusters" + git clone https://github.com/derailed/k9s.git cp k9s/skins/* "$K9S_CONFIG/skins" rm -rf k9s @@ -60,4 +88,9 @@ done cp .k9s/config.yaml "$K9S_CONFIG/config.yaml" -chown -R "$USER:$USER" "$K9S_CONFIG" \ No newline at end of file +cp -r .k9s/clusters/* "$K9S_CTX/clusters" + +chown -R "$USER:$USER" "$K9S_CONFIG" +chown -R "$USER:$USER" "$K9S_CTX" + +echo "🐶 Done!"