Skip to content

Instantly share code, notes, and snippets.

@mgoodness
Last active May 28, 2019 15:44
Show Gist options
  • Save mgoodness/9e1c90d7b8fe14f04422bd0f44da9aed to your computer and use it in GitHub Desktop.
Save mgoodness/9e1c90d7b8fe14f04422bd0f44da9aed to your computer and use it in GitHub Desktop.

Revisions

  1. mgoodness revised this gist Jan 28, 2019. 1 changed file with 23 additions and 17 deletions.
    40 changes: 23 additions & 17 deletions kube-ssh.sh
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,28 @@
    kube-ssh() {
    while getopts ":u:" opt; do
    case "$opt" in
    u)
    username="${OPTARG}"
    ;;
    \?)
    echo "Invalid option: -${OPTARG}" >&2
    exit 1
    ;;
    :)
    echo "Option -${OPTARG} requires an argument." >&2
    ;;
    esac
    done
    #!/usr/bin/env bash

    shift "$((OPTIND-1))"
    while getopts ":u:" opt; do
    case "$opt" in
    u)
    username="${OPTARG}"
    ;;
    \?)
    echo "Invalid option: -${OPTARG}" >&2
    return 1
    ;;
    :)
    echo "Option -${OPTARG} requires an argument." >&2
    return 1
    ;;
    esac
    done

    shift "$((OPTIND-1))"

    if [[ -z $1 ]]; then
    echo "Node name required." >&2
    return 1
    else
    ip="$(kubectl get nodes $1 -o go-template='{{range .status.addresses}}{{if eq .type "InternalIP"}}{{print .address}}{{end}}{{end}}')"

    ssh "${username}@$ip"
    }
    fi
  2. mgoodness created this gist Jan 24, 2019.
    22 changes: 22 additions & 0 deletions kube-ssh.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    kube-ssh() {
    while getopts ":u:" opt; do
    case "$opt" in
    u)
    username="${OPTARG}"
    ;;
    \?)
    echo "Invalid option: -${OPTARG}" >&2
    exit 1
    ;;
    :)
    echo "Option -${OPTARG} requires an argument." >&2
    ;;
    esac
    done

    shift "$((OPTIND-1))"

    ip="$(kubectl get nodes $1 -o go-template='{{range .status.addresses}}{{if eq .type "InternalIP"}}{{print .address}}{{end}}{{end}}')"

    ssh "${username}@$ip"
    }