Created
January 25, 2021 11:50
-
-
Save strund3r/18b7a9c81fe8edce33dbe2cdf27edf61 to your computer and use it in GitHub Desktop.
k8s shell functions
This file contains 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
help-k8s-decrypt-secret() { | |
echo "" | |
echo "Usage" | |
echo " k8s-decrypt-secret [options] <secret> <namespace>" | |
echo "" | |
echo "Options:" | |
echo " <secret> kubernetes secret" | |
echo " <namespace> kubernetes namespace" | |
echo " -v verbose output (show kubectl command)" | |
echo " -h show this help" | |
} | |
k8s-decrypt-secret() { | |
if (( "$#" == 0 )); then | |
help-k8s-decrypt-secret | |
fi | |
while getopts ":vh" opt; do | |
case $opt in | |
v) | |
if (( "$#" == 1 )) | |
then | |
echo "usage error: secret and namespace required" >&2 | |
elif (( "$#" == 2 )) | |
then | |
echo "usage error: namespace required" >&2 | |
elif (( "$#" == 3 )) | |
then | |
echo "" | |
echo "kubectl get secret "$2" -o json -n "$3" | jq '.data | map_values(@base64d)'" | |
echo "" | |
kubectl get secret "$2" -o json -n "$3" | jq '.data | map_values(@base64d)' >&2 | |
fi | |
exit | |
;; | |
h) | |
help-k8s-decrypt-secret | |
exit | |
;; | |
\?) | |
echo "invalid option: -$OPTARG" >&2 | |
exit | |
;; | |
esac | |
done | |
if (( "$#" == 1 )) | |
then | |
echo "usage error: namespace required" >&2 | |
elif (( "$#" == 2 )) | |
then | |
kubectl get secret "$1" -o json -n "$2" | jq '.data | map_values(@base64d)' >&2 | |
fi | |
} |
This file contains 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
help-k8s-events-pod() { | |
echo "" | |
echo "Usage" | |
echo " k8s-events-pod [options] <namespace> <pod-name>" | |
echo "" | |
echo "Options:" | |
echo " <namespace> kubernetes namespace (optional)" | |
echo " <pod-name> kubernetes pod name" | |
echo " -v verbose output (show kubectl command)" | |
echo " -h show this help" | |
} | |
k8s-events-pod() { | |
if (( "$#" == 0 )); then | |
help-k8s-events-pod | |
fi | |
while getopts ":vh" opt; do | |
case $opt in | |
v) | |
if (( "$#" == 1 )) | |
then | |
echo "usage error: pod name required" >&2 | |
elif (( "$#" == 2 )) | |
then | |
echo "" | |
echo "kubectl get events --all-namespaces --field-selector involvedObject.name='$2' --sort-by='.metadata.creationTimestamp'" | |
echo "" | |
kubectl get events --all-namespaces --field-selector involvedObject.name="$2" --sort-by='.metadata.creationTimestamp' >&2 | |
elif (( "$#" == 3 )) | |
then | |
echo "" | |
echo "kubectl get events --namespace $2 --field-selector involvedObject.name='$3' --sort-by='.metadata.creationTimestamp'" | |
echo "" | |
kubectl get events --namespace "$2" --field-selector involvedObject.name="$3" --sort-by='.metadata.creationTimestamp' >&2 | |
fi | |
exit | |
;; | |
h) | |
help-k8s-events-pod | |
exit | |
;; | |
\?) | |
echo "invalid option: -$OPTARG" >&2 | |
exit | |
;; | |
esac | |
done | |
if (( "$#" == 1 )) | |
then | |
kubectl get events --all-namespaces --field-selector involvedObject.name="$1" --sort-by='.metadata.creationTimestamp' >&2 | |
elif (( "$#" == 2 )) | |
then | |
kubectl get events --namespace "$1" --field-selector involvedObject.name="$2" --sort-by='.metadata.creationTimestamp' >&2 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment