Compare commits

...

5 Commits

Author SHA1 Message Date
Jonas Forsberg
beaa8fff5b added backup.sh 2022-09-30 10:59:55 +02:00
Jonas Forsberg
60584cbc68 removed virtctl, fixed stern 2022-09-30 10:51:55 +02:00
Jonas Forsberg
bb0f3ffc7b changed default work computer 2022-09-27 11:34:17 +02:00
Jonas Forsberg
6fed8d09b5 added delay 2022-09-27 11:02:05 +02:00
Jonas Forsberg
086435d6a7
added k8s_apps 2022-09-02 16:34:14 +02:00
5 changed files with 70 additions and 22 deletions

View File

@ -37,7 +37,7 @@ fi
# shellcheck disable=1090 # shellcheck disable=1090
[[ -d "$HOME/.rbenv/bin" ]] && export PATH="$HOME/.rbenv/bin:$PATH" && eval "$(rbenv init -)" [[ -d "$HOME/.rbenv/bin" ]] && export PATH="$HOME/.rbenv/bin:$PATH" && eval "$(rbenv init -)"
[[ "$(hostname)" != "exsilio" ]] && export PS1_COLOR_HOSTNAME="\[\033[0;33m\]" [[ "$(hostname)" != "pingue" ]] && export PS1_COLOR_HOSTNAME="\[\033[0;33m\]"
#exit with no error #exit with no error
/bin/true /bin/true

View File

@ -8,3 +8,4 @@ Categories=Network
Type=Application Type=Application
StartupNotify=false StartupNotify=false
X-GNOME-Autostart-enabled=true X-GNOME-Autostart-enabled=true
X-GNOME-Autostart-Delay=10

View File

@ -79,3 +79,51 @@ function k8s_neuvector_cve_db_version(){
function k8s_node_taints(){ function k8s_node_taints(){
kubectl get nodes -o json | jq '.items[].spec.taints' kubectl get nodes -o json | jq '.items[].spec.taints'
} }
function k8s_apps(){
# parameters,
# stop = Set all deployments & statefultsets to replica=0
# start = set all deployments & statefulsets to replica=1
# show = show status of all deployments & statefulsets
CHOICE="$1"
if [[ ! "start stop show" =~ (" "|^)"$CHOICE"(" "|$) ]]; then
echo "no parameter given"
return 1
fi
local USER_PROJECT_IDS=(p-c5fcj p-q8pbm)
local OK='\e[32m\u2714\e[0m'
local NOT_OK='\u274c'
printf "%-22s %s\n" "namespace" "application"
printf -- '-%.0s' {1..34}
printf "\n"
for PROJECT in "${USER_PROJECT_IDS[@]}"; do
for NS in $(kubectl get namespaces --selector=field.cattle.io/projectId="$PROJECT" --template "{{range .items}}{{.metadata.name}}{{\"\n\"}}{{end}}"); do
for DEPLOYMENT in $(kubectl --namespace "$NS" get deployments --template "{{range .items}}{{.metadata.name}}{{\"\n\"}}{{end}}"); do
if [[ "$CHOICE" == "stop" ]];then
kubectl --namespace "$NS" scale deployment "$DEPLOYMENT" --replicas=0 > /dev/null
elif [[ "$CHOICE" == "start" ]];then
kubectl --namespace "$NS" scale deployment "$DEPLOYMENT" --replicas=1 > /dev/null
fi
if [[ $(kubectl --namespace "$NS" get deployments "$DEPLOYMENT" -o jsonpath='{.spec.replicas}') == "0" ]];then
echo -n -e "$NOT_OK "
else
echo -n -e "$OK "
fi
printf "%-20s %s\n" "$NS" "$DEPLOYMENT"
done
for STATEFULSET in $(kubectl --namespace "$NS" get statefulsets --template "{{range .items}}{{.metadata.name}}{{\"\n\"}}{{end}}"); do
if [[ "$CHOICE" == "stop" ]];then
kubectl --namespace "$NS" scale statefulset "$STATEFULSET" --replicas=0 > /dev/null
elif [[ "$CHOICE" == "start" ]];then
kubectl --namespace "$NS" scale statefulset "$STATEFULSET" --replicas=1 > /dev/null
fi
if [[ $(kubectl --namespace "$NS" get statefulsets "$STATEFULSET" -o jsonpath='{.spec.replicas}') == "0" ]];then
echo -n -e "$NOT_OK "
else
echo -n -e "$OK "
fi
printf "%-20s %s\n" "$NS" "$STATEFULSET"
done
done
done
}

View File

@ -1,15 +1,14 @@
function upgrade_tools(){ function upgrade_tools(){
new_log "Install client tools" echo "Install/Upgrade client tools"
echo "- kubectl" echo "- kubectl"
echo "- helm" echo "- helm"
echo "- stern" echo "- stern"
echo "- virtctl"
if asktobreak; then if asktobreak; then
return return
fi fi
set +e
echo "---- kubectl ----" echo "---- kubectl ----"
local CURRENT_PWD="$(pwd)"
cd $HOME/bin cd $HOME/bin
if [[ -f kubectl ]]; then if [[ -f kubectl ]]; then
KUBECTL_CURRENT=$(./kubectl version --client 2> /dev/null| sed -n 's/.* GitVersion:"\(v[0-9]*\.[0-9]*\.[0-9]*\)".*/\1/p') KUBECTL_CURRENT=$(./kubectl version --client 2> /dev/null| sed -n 's/.* GitVersion:"\(v[0-9]*\.[0-9]*\.[0-9]*\)".*/\1/p')
@ -52,25 +51,10 @@ function upgrade_tools(){
echo "Latest stable version: $STERN_STABLE" echo "Latest stable version: $STERN_STABLE"
if [[ "$STERN_CURRENT" != "$STERN_STABLE" ]]; then if [[ "$STERN_CURRENT" != "$STERN_STABLE" ]]; then
echo "updating to $STERN_STABLE" echo "updating to $STERN_STABLE"
curl -LO https://github.com/stern/stern/releases/download/$STERN_STABLE/stern_${STERN_STABLE:1}_linux_amd64.tar.gz curl -LO https://github.com/stern/stern/releases/download/$STERN_STABLE/stern_${STERN_STABLE:1}_linux_amd64.tar.gz
tar xvzf stern_${STERN_STABLE:1}_linux_amd64.tar.gz --strip-components=1 stern_${STERN_STABLE:1}_linux_amd64/stern tar xvzf stern_${STERN_STABLE:1}_linux_amd64.tar.gz stern
rm stern_${STERN_STABLE:1}_linux_amd64.tar.gz rm stern_${STERN_STABLE:1}_linux_amd64.tar.gz
fi fi
echo "" echo ""
echo "---- virtctl ----" cd "$CURRENT_PWD"
if [[ -f stern ]]; then
VIRTCTL_CURRENT="$(./virtctl version --client 2> /dev/null| sed -n 's/.*GitVersion:"\(v[0-9]*\.[0-9]*\.[0-9]*\)".*/\1/p')"
else
VIRTCTL_CURRENT="N/A"
fi
VIRTCTL_STABLE="$(curl -Ls https://github.com/kubevirt/kubevirt/releases | egrep 'href="/kubevirt/kubevirt/releases/tag/v[0-9]+.[0-9]+.[0-9]+*\"' | head -n 1 | sed -n 's/.*tag\/\(v.*\)" data.*/\1/p')"
echo "Installed version: $VIRTCTL_CURRENT"
echo "Latest stable version: $VIRTCTL_STABLE"
if [[ "$VIRTCTL_CURRENT" != "$VIRTCTL_STABLE" ]]; then
echo "updating to $VIRTCTL_STABLE"
curl -Lo virtctl https://github.com/kubevirt/kubevirt/releases/download/$VIRTCTL_STABLE/virtctl-$VIRTCTL_STABLE-linux-amd64
chmod +x ./virtctl
fi
echo ""
set -e
} }

15
bin/backup.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
set -aeou pipefail
RESTIC=/usr/bin/restic
# some helpers and error handling:
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
# shellcheck disable=SC1090
source "${HOME}"/.restic/restic.env
$RESTIC backup \
--exclude-file="$HOME"/.restic/excludes.txt \
--files-from="$HOME"/.restic/includes.txt \
--verbose