Skip to content

Instantly share code, notes, and snippets.

@dalehamel
Last active March 1, 2018 20:40
Show Gist options
  • Select an option

  • Save dalehamel/1d5277f700a047460450865177a00b0e to your computer and use it in GitHub Desktop.

Select an option

Save dalehamel/1d5277f700a047460450865177a00b0e to your computer and use it in GitHub Desktop.
eks container logs
#!/bin/bash
POD_ID=$1
NS_ID=$2
CONTAINER_NAME=$3
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 -i ~/.ssh/terraform.pem ec2-user@${pubnode} docker logs ${container}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment