Last active
December 2, 2020 01:05
-
-
Save anguslees/c3d93be157df0798f3f2e897efc9d138 to your computer and use it in GitHub Desktop.
"cloud-native" ssh replacement :P
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
#!/bin/sh | |
# | |
# The access this gives you is rather terrifing. Use sparingly. | |
# | |
set -e -x | |
node=$1 | |
trap "kubectl delete pod nodesh-$node" EXIT | |
kubectl create -f - <<EOF | |
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: nodesh-$node | |
spec: | |
nodeName: $node | |
restartPolicy: Never | |
hostPID: true | |
hostIPC: true | |
hostNetwork: true | |
containers: | |
- name: shell | |
image: anguslees/myshell:latest | |
stdin: true | |
tty: true | |
stdinOnce: true | |
securityContext: {privileged: true} | |
volumeMounts: | |
- name: root | |
mountPath: "/target" | |
readOnly: true | |
- name: docksock | |
mountPath: "/var/run/docker.sock" | |
readOnly: true | |
volumes: | |
- name: root | |
hostPath: | |
path: / | |
type: Directory | |
- name: docksock | |
hostPath: | |
path: "/var/run/docker.sock" | |
EOF | |
# --pod-running-timeout doesn't seem to work reliably | |
while ! kubectl logs -c shell nodesh-$node >/dev/null 2>&1; do | |
sleep 1 | |
done | |
kubectl attach nodesh-$node -c shell -ti --pod-running-timeout=10m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment