Compare commits

..

No commits in common. "460cfe6254755a6ea40dbd671ed0f6a84af97abb" and "49d6d632234c1a35fb1e7a09abd23f905c2c523e" have entirely different histories.

4 changed files with 0 additions and 147 deletions

View File

@ -1,37 +0,0 @@
# my kubectl plugin scripts
To install
```
git https://git.rre.nu/jonas/kube-plugin.git "$HOME/kube-plugin"
export PATH=$PATH:$HOME/git/kube-plugin
```
Verify that the scripts are picked up in `kubectl`
```
kubectl plugin list
```
## kubectl-rsh
Creates a pod on the node and executes a shell on that node.
You need cluster admin rights and privileged pod execution rights
```
Usage:
kubectl rsh [nodeName]
```
### Variables
| Name | Default | Desciption |
|------|---------|------------|
| KUBECTL_RSH_IMAGE | docker.io/library/busybox | The image used by the pod creating the shell |
| KUBECTL_RSH_IMAGE_TAG | latest | Image tag to use |
| KUBECTL_RSH_NAMESPACE | default | Namespace to create the rsh pod in |
| KUBECTL_RSH_POD_CREATE_TIMEOUT | 3 | Minutes to wait before failing to create pod |
## kubectl-deprecated_api
Lists APIs flagged as deprecated
```
Usage:
kubectl deprecated-api
```

View File

@ -1,7 +0,0 @@
#!/usr/bin/env bash
if ! command -v prom2json > /dev/null; then
echo "You need prom2json to use this command"
exit 1
fi
kubectl get --raw /metrics | prom2json | jq -c '.[] | select(.name=="apiserver_requested_deprecated_apis").metrics[].labels' | column -t -s'{}[],"'

View File

@ -1,80 +0,0 @@
#!/usr/bin/env bash
set -aeou pipefail
SCRIPT_VERSION="0.1"
KUBECTL_RSH_IMAGE="${KUBECTL_RSH_IMAGE:-docker.io/library/busybox}"
KUBECTL_RSH_IMAGE_TAG="${KUBECTL_RSH_IMAGE_TAG:-latest}"
KUBECTL_RSH_NAMESPACE="${KUBECTL_RSH_NAMESPACE:-default}"
KUBECTL_RSH_POD_CREATE_TIMEOUT="${KUBECTL_RSH_POD_CREATE_TIMEOUT:-3}"
function print_help(){
cat << EOF
Creates a pod on the node and executes a shell on that node.
You need cluster admin rights and privileged pod execution rights
Usage:
kubectl rsh [nodeName]
EOF
}
if [[ "$1" == "version" ]];then
echo "$SCRIPT_VERSION"
exit 0
fi
if [[ "$1" == "--help" ]]; then
print_help
exit 0
fi
NODE="$1"
POD=$( kubectl create -n "$KUBECTL_RSH_NAMESPACE" -o name -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
generateName: rsh-node-
labels:
rre.nu/kubectl-plugin: rsh-node
spec:
nodeName: $NODE
containers:
- name: rsh-node
image: ${KUBECTL_RSH_IMAGE}:${KUBECTL_RSH_IMAGE_TAG}
imagePullPolicy: IfNotPresent
command: ["chroot", "/host"]
tty: true
stdin: true
stdinOnce: true
securityContext:
privileged: true
volumeMounts:
- name: host
mountPath: /host
volumes:
- name: host
hostPath:
path: /
hostNetwork: true
hostIPC: true
hostPID: true
restartPolicy: Never
tolerations:
- operator: "Exists"
EOF
)
echo "Creating $POD in $KUBECTL_RSH_NAMESPACE namespace"
function remove_pod(){
echo "Removing $POD in $KUBECTL_RSH_NAMESPACE namespace"
kubectl -n "$KUBECTL_RSH_NAMESPACE" delete "$POD" --wait=false
}
trap remove_pod EXIT
echo "Waiting for pod to be ready..."
kubectl wait -n "$KUBECTL_RSH_NAMESPACE" --for=condition=Ready --timeout "${KUBECTL_RSH_POD_CREATE_TIMEOUT}m" "$POD" >/dev/null
kubectl attach -n "$KUBECTL_RSH_NAMESPACE" -it "$POD"

View File

@ -1,23 +0,0 @@
#!/usr/bin/env bash
# If we are completing a flag, use Cobra's builtin completion system.
# To know if we are completing a flag we need the last argument starts with a `-` and does not contain an `=`
args=("$@")
lastArg=${args[((${#args[@]}-1))]}
if [[ "$lastArg" == -* ]]; then
if [[ "$lastArg" != *=* ]]; then
kubectl ns __complete "$@"
fi
else
# TODO Make sure we are not completing the value of a flag.
# TODO Only complete a single argument.
# Both are pretty hard to do in a shell script. The better way to do this would be to let
# Cobra do all the completions by using `cobra.ValidArgsFunction` in the program.
# But the below, although imperfect, is a nice example for plugins that don't use Cobra.
kubectl get nodes --no-headers -o custom-columns=":metadata.name"
# Turn off file completion. See the ShellCompDirective documentation within
# https://github.com/spf13/cobra/blob/main/shell_completions.md#completion-of-nouns
echo :4
fi