Skip to content

Instantly share code, notes, and snippets.

@dalehamel
Created March 1, 2018 20:47
Show Gist options
  • Save dalehamel/3a6e52741e65b4daadc2bdd9b7f970eb to your computer and use it in GitHub Desktop.
Save dalehamel/3a6e52741e65b4daadc2bdd9b7f970eb to your computer and use it in GitHub Desktop.
exec into eks container
#!/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