Created
March 1, 2018 20:47
-
-
Save dalehamel/3a6e52741e65b4daadc2bdd9b7f970eb to your computer and use it in GitHub Desktop.
exec into eks container
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
#!/bin/bash | |
POD_ID=$1 | |
NS_ID=$2 | |
CONTAINER_NAME=$3 | |
shift | |
shift | |
shift | |
container=$(kubectl get pod ${POD_ID} -n ${NS_ID} -o json | jq ".status.containerStatuses[] | select(.name == \"${CONTAINER_NAME}\") | .containerID" | sed -e 's/^"//' -e 's/"$//' | sed 's|docker://||g') | |
echo "Container ID is ${container}" | |
node=$(kubectl get pod ${POD_ID} -n ${NS_ID} -o json | jq '.spec.nodeName' | sed -e 's/^"//' -e 's/"$//') | |
echo "Private node is ${node}" | |
pubnode=$(kubectl get node ${node} -o json | jq '.status.addresses[] | select(.type == "ExternalDNS") | .address' | sed -e 's/^"//' -e 's/"$//') | |
echo "Public node address is ${pubnode}" | |
ssh -t -i ~/.ssh/terraform.pem ec2-user@${pubnode} docker exec -ti ${container} $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment