Skip to content

Instantly share code, notes, and snippets.

@DazWilkin
Created August 6, 2018 19:24
Show Gist options
  • Save DazWilkin/77cbd3e72d0eea1e340a0036e16a84ec to your computer and use it in GitHub Desktop.
Save DazWilkin/77cbd3e72d0eea1e340a0036e16a84ec to your computer and use it in GitHub Desktop.
kubectl hacking
#!/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