2021-11-29 08:07:17 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-03-11 18:38:32 +00:00
|
|
|
source .utils
|
2021-11-29 08:07:17 +00:00
|
|
|
|
2022-03-11 18:38:32 +00:00
|
|
|
NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)"
|
|
|
|
set -e
|
|
|
|
NAMESPACE=${NAMESPACE:-default}
|
2021-11-29 08:07:17 +00:00
|
|
|
POD="shell"
|
2024-02-15 12:23:54 +00:00
|
|
|
IMAGE="digitalocean/doks-debug"
|
|
|
|
CMD="bash"
|
2021-11-29 08:07:17 +00:00
|
|
|
|
|
|
|
print_usage() {
|
2022-03-11 18:38:32 +00:00
|
|
|
blue "kube-shell - create a new pod and exec into it's shell"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo " "
|
2022-03-11 18:38:32 +00:00
|
|
|
underline "Usage:"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo "kube-shell [options]"
|
|
|
|
echo " "
|
2022-03-11 18:38:32 +00:00
|
|
|
underline "Options:"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo "-h, --help show this help text"
|
|
|
|
echo "-n, --namespace the namespace the pod should launch in"
|
|
|
|
echo "-p, --pod the name of the pod to get logs for (default: shell)"
|
2024-02-15 12:23:54 +00:00
|
|
|
echo "-i, --image the image to use for the shell container (default: digitalocean/doks-debug)"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo "-c, --command the initial command to execute in the container (default: sh)"
|
|
|
|
}
|
|
|
|
|
|
|
|
while test $# -gt 0; do
|
|
|
|
case "$1" in
|
|
|
|
-n|--namespace)
|
|
|
|
shift
|
|
|
|
NAMESPACE=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-p|--pod)
|
|
|
|
shift
|
|
|
|
POD=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-i|--image)
|
|
|
|
shift
|
|
|
|
IMAGE=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-c|--command)
|
|
|
|
shift
|
|
|
|
CMD=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
print_usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-12-15 10:46:43 +00:00
|
|
|
NAMESPACE=${NAMESPACE:-default}
|
2021-11-29 08:07:17 +00:00
|
|
|
|
2024-02-15 12:23:54 +00:00
|
|
|
OVERRIDES='{
|
|
|
|
"spec": {
|
|
|
|
"securityContext": {"runAsGroup": 1000,"runAsNonRoot": true,"runAsUser": 1000,"seccompProfile": {"type": "RuntimeDefault"}},
|
|
|
|
"containers": [
|
|
|
|
{
|
|
|
|
"name":"'$POD'","image":"'$IMAGE'", "command": ["'$CMD'"],
|
|
|
|
"stdin": true,"stdinOnce": true,"tty": true,
|
|
|
|
"securityContext": {"allowPrivilegeEscalation": false,"capabilities": {"drop": ["ALL"]},"privileged": false,"runAsGroup": 1000,"runAsNonRoot": true,"runAsUser": 1000,"seccompProfile": {"type": "RuntimeDefault"}}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
kubectl run -it --namespace $NAMESPACE $POD --image $IMAGE --restart Never --overrides "${OVERRIDES}" --rm -- $CMD
|