Kubernetes toolbox

Export namespace and non namespace objects

ROOT=${HOME}/clusterstate
while read -r resource
do
    echo "  scanning resource '${resource}'"
    while read -r namespace item x
    do
        mkdir -p "${ROOT}/${namespace}/${resource}"
        echo "    exporting item '${namespace} ${item}'"
        kubectl get "$resource" -n "$namespace" "$item" -o yaml > "${ROOT}/${namespace}/${resource}/$item.yaml" &
    done < <(kubectl get "$resource" --all-namespaces 2>&1  | tail -n +2)
done < <(kubectl api-resources --namespaced=true 2>/dev/null | grep -v "events" | tail -n +2 | awk '{print $1}')

wait

Install yq

BINARY=yq_linux_arm64
LATEST=$(wget -qO- https://api.github.com/repos/mikefarah/yq/releases/latest 2>/dev/null | grep browser_download_url | grep $BINARY\"\$|awk '{print $NF}' )
sudo wget -q $LATEST -O /usr/bin/yq && sudo chmod +x /usr/bin/yq

Extract 'last aplied configuration from deployment etc.'

 kubectl get deployment nginx-deployment -o json | jq -r '.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration"' | yq r -P - > deployment_cleaned.yaml

Install k0sctl

VER=$(curl -s https://api.github.com/repos/k0sproject/k0sctl/releases/latest|grep tag_name | cut -d '"' -f 4)
echo $VER
### For 64-bit ###
wget https://github.com/k0sproject/k0sctl/releases/download/${VER}/k0sctl-linux-x64 -O k0sctl

###For ARM64 ###
wget https://github.com/k0sproject/k0sctl/releases/download/${VER}/k0sctl-linux-arm64 -O k0sctl
chmod +x k0sctl
yes | cp -vr k0sctl /usr/local/bin/
### Bash ###
sh -c 'k0sctl completion >/etc/bash_completion.d/k0sctl'