Created
May 29, 2018 15:13
-
-
Save JeffreyVdb/db1ef6a7afe00a5c67af45024dc74bc6 to your computer and use it in GitHub Desktop.
kube-alias.zsh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
if (( $+commands[kubectl] )); then | |
source <(kubectl completion zsh) | |
fi | |
function env_to_secret() { | |
perl -MMIME::Base64 -ne '/^(.*?)=(.*)$/ && printf("$1: %s\n", encode_base64($2, ""))' | |
} | |
function kube_decode() { | |
for row in $(jq -c '.data | to_entries[]'); do | |
KEY=$(echo "${row}" | jq -r '.key') | |
DECODED=$(echo "${row}" | jq -r '.value' | base64 --decode) | |
echo "${KEY}=${DECODED}" | |
done | |
} | |
function krunit() { | |
local image_to_run="${1:-fedora}" | |
[[ $# -gt 0 ]] && shift | |
if [[ -z "$@" ]]; then | |
set -- bash | |
fi | |
kubectl run -it --rm --restart=Never \ | |
--image=${image_to_run} "maintenance-$(head /dev/urandom | tr -dc a-z | head -c 10)" -- "$@" | |
} | |
function kcrongetjob() { | |
local cronjob_name="$1" | |
local namespace="${2:-default}" | |
local _json | |
_json=$(kubectl -n $namespace get cronjob $cronjob_name -o json --export 2>&1) | |
if [ $? -eq 0 ]; then | |
echo "{ | |
\"apiVersion\": \"batch/v1\", | |
\"kind\": \"Job\", | |
\"metadata\": { | |
\"name\": \"$cronjob_name-$(head /dev/urandom | tr -dc a-z | head -c 10)\", | |
\"namespace\": \"$namespace\" | |
}, | |
\"spec\": " | |
jq --indent 2 .spec.jobTemplate.spec <<< "$_json" | perl -pe 's/^/ /g' | |
echo '}' | |
else | |
echo $_json | |
fi | |
} | |
alias k='kubectl' | |
alias kp='kubectl get pods' | |
alias kpr='kubectl get pods --field-selector=status.phase=Running' | |
alias kap='kubectl get pods --all-namespaces' | |
alias kl='kubectl logs' | |
alias kaf='kubectl apply -f' | |
alias kdel='kubectl delete' | |
alias ktp='kubectl top pods' | |
alias ktn='kubectl top nodes' | |
alias kcron='kubectl get cronjob' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment