Created
August 6, 2018 19:24
-
-
Save DazWilkin/77cbd3e72d0eea1e340a0036e16a84ec to your computer and use it in GitHub Desktop.
kubectl hacking
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 | |
# Prerequisites | |
: "${PROJECT:?Expects PROJECT to be non-empty}" | |
: "${CONTEXT:?Expects CONTEXT to be non-empty}" | |
: "${NAMESPACE:?Expects NAMESPACE to be non-empty}" | |
NODE=$(\ | |
kubectl get nodes \ | |
--context=${CONTEXT} \ | |
--namespace=${NAMESPACE} \ | |
--output=jsonpath='{.items[0].metadata.name}'\ | |
) | |
FLAGS=() | |
FLAGS+=(--project=${PROJECT}) | |
for LABELS in \ | |
"component=ca" \ | |
"component=peer,org=org1,peer=0" \ | |
"component=orderer" | |
do | |
for MAPPING in $(\ | |
kubectl get service \ | |
--selector=${LABELS} \ | |
--context=${CONTEXT} \ | |
--namespace=${NAMESPACE} \ | |
--output=jsonpath='{range .items[0].spec.ports[*]}{.targetPort}{":localhost:"}{.nodePort}{" "}{end}'\ | |
) | |
do | |
FLAGS+=(--ssh-flag="-L ${MAPPING}") | |
done | |
done | |
gcloud compute ssh ${NODE} "${FLAGS[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment