• Stars
    star
    172
  • Rank 221,201 (Top 5 %)
  • Language
    Shell
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A kubectl plugin to access nodes or remote services using a SSH jump Pod

kubectl-plugin-ssh-jump

kubectl plugin

A kubectl plugin to access Kubernetes nodes or remote services using a SSH jump Pod

A jump host Pod is an intermediary Pod or an SSH gateway to Kubernetes node machines, through which a connection can be made to the node machines or remote services.

Here is an scenario where you want to connect to Kubernetes nodes or remote services, but you have to go through a jump host Pod, because of firewalling, access privileges. etc. There is a number of valid reasons why the jump hosts are needed...

CASE 1: SSH into Kubernetes nodes via SSH jump Pod

CASE 2: Connect to remote serivces via SSH local port forwarding. SSH local port forwarding allows to forward the traffic form local machine to SSH jump then SSH jump will forward the traffic to remote services (host:port)s.

[NOTE]

  • Kubectl versions >= 1.12.0 (Preferred)
    • As of Kubernetes 1.12, kubectl now allows adding external executables as subcommands. For more detail, see Extend kubectl with plugins
    • You can run the plugin with kubectl ssh-jump ...
  • Kubectl versions < 1.12.0
    • You still can run the plugin directly with kubectl-ssh-jump ...

Table of Content

Pre-requistes

This plugin needs the following programs:

  • ssh(1)
  • ssh-agent(1)
  • ssh-keygen(1)

Installation

Install through krew

This is a way to install kubectl-ssh-jump through krew. After installing krew by following this, you can install kubectl-ssh-jump like this:

$ kubectl krew install ssh-jump

Expected output would be like this:

Updated the local copy of plugin index.
Installing plugin: ssh-jump
CAVEATS:
\
 |  This plugin needs the following programs:
 |  * ssh(1)
 |  * ssh-agent(1)
 |
 |  Please follow the documentation: https://github.com/yokawasa/kubectl-plugin-ssh-jump
/
Installed plugin: ssh-jump

Once it's installed, run:

$ kubectl plugin list

The following kubectl-compatible plugins are available:

/Users/yoichi.kawasaki/.krew/bin/kubectl-krew
/Users/yoichi.kawasaki/.krew/bin/kubectl-ssh_jump

$ kubectl ssh-jump

Manual Installation

Install the plugin by copying the script in the $PATH of your shell.

# Get source
$ git clone https://github.com/yokawasa/kubectl-plugin-ssh-jump.git
$ cd kubectl-plugin-ssh-jump
$ chmod +x kubectl-ssh-jump
# Add kubeclt-ssh-jump to the install path.
$ sudo cp -p kubectl-ssh-jump /usr/local/bin

Once in the $PATH, run:

$ kubectl plugin list

The following kubectl-compatible plugins are available:
/usr/local/bin/kubectl-ssh-jump

$ kubectl ssh-jump

How to use

Usage

Usage: 
  kubectl ssh-jump <dest_node> [options]

Options:
  <dest_node>                     Destination node name or IP address
                                  dest_node must start from the following letters:
                                  ASCII letters 'a' through 'z' or 'A' through 'Z',
                                  the digits '0' through '9', or hyphen ('-').
                                  NOTE: Setting dest_node as 'jumphost' allows to
                                  ssh into SSH jump Pod as 'root' user
  -u, --user <sshuser>            SSH User name
  -i, --identity <identity_file>  Identity key file, or PEM(Privacy Enhanced Mail)
  -p, --pubkey <pub_key_file>     Public key file
  -P, --port <port>               SSH port for target node SSH server
                                  Defaults to 22
  -a, --args <args>               Args to exec in ssh session
  -n, --namespace <ns>            Namespace for jump pod
  --context <context>             Kubernetes context
  --pod-template <file>           Path to custom sshjump pod definition
  --skip-agent                    Skip automatically starting SSH agent and adding
                                  SSH Identity key into the agent before SSH login
                                  (=> You need to manage SSH agent by yourself)
  --cleanup-agent                 Clearning up SSH agent at the end
                                  The agent is NOT cleaned up in case that
                                  --skip-agent option is given
  --cleanup-jump                  Clearning up sshjump pod at the end
                                  Defaults to skip cleaning up sshjump pod
  -v, --verbose                   Run ssh in verbose mode (=ssh -vvv)
  -h, --help                      Show this message

Example:
  Scenario1 - You have private & public SSH key on your side
  $ kubectl ssh-jump -u myuser -i ~/.ssh/id_rsa -p ~/.ssh/id_rsa.pub hostname

  Scenario2 - You have .pem file but you don't have public key on your side
  $ kubectl ssh-jump -u ec2-user -i ~/.ssh/mykey.pem hostname

Option parameters Cache

username, identity, pubkey, port options are cached, therefore you can omit these options afterward. The options are stored in a file named $HOME/.kube/kubectlssh/options

$ cat $HOME/.kube/kubectlssh/options
sshuser=myuser
identity=/Users/yoichi.kawasaki/.ssh/id_rsa_k8s
pubkey=/Users/yoichi.kawasaki/.ssh/id_rsa_k8s.pub
port=22

SSH Agent (ssh-agent)

The plugin automatically check if there are any ssh-agents started running by the plugin, and starts ssh-agentif it doesn't find any ssh-agent running and adds SSH Identity key into the agent before SSH login. If the command find that ssh-agent is already running, it doesn't start a new agent, and re-use the agent. Add --cleanup-agent option if you want to kill the created agent at the end of command.

In addtion, add --skip-agent option if you want to skip automatic starting ssh-agent. This is actually a case where you already have ssh-agent managed or you want to manually start the agent.

Customize SSH jump pod

You can customize the sshjump pod created by kubectl ssh-jump by setting the --pod-template flag to the path to a pod template on disk. However, customized sshjump pods must be named sshjump and run in the current namespace or kubectl ssh-jump won't be able to find them.

You can also specify the namespace and context used by kubectl ssh-jump by setting the --namespace and --context flags respectively.

Examples

Show all node list. Simply executing kubectl ssh-jump gives you the list of destination nodes as well as command usage

$ kubectl ssh-jump

Usage: 
  kubectl ssh-jump <dest_node> [options]

...snip...

List of destination node...
Hostname                    Internal-IP
aks-nodepool1-18558189-0    10.240.0.4
...snip...

CASE 1: SSH into Kubernetes nodes via SSH jump Pod

1-1 - You have private & public SSH key on your side

Suppose you have private & public SSH key on your side and you want to SSH to a node named aks-nodepool1-18558189-0, execute the plugin with options like this:

  • usernaem: azureuser
  • identity:~/.ssh/id_rsa_k8s
  • pubkey:~/.ssh/id_rsa_k8s.pub)
$ kubectl ssh-jump aks-nodepool1-18558189-0 \
  -u azureuser -i ~/.ssh/id_rsa_k8s -p ~/.ssh/id_rsa_k8s.pub

[NOTE] you can try SSH into a node using node IP address (Internal-IP) instead of Hostname

As explained in usage secion, username, identity, pubkey options will be cached, therefore you can omit these options afterward.

$ kubectl ssh-jump aks-nodepool1-18558189-0

You can pass the commands to run in the destination node like this (Suppose that username, identity, pubkey options are cached):

echo "uname -a" | kubectl ssh-jump aks-nodepool1-18558189-0

(Output)
Linux aks-nodepool1-18558189-0 4.15.0-1035-azure #36~16.04.1-Ubuntu SMP Fri Nov 30 15:25:49 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

You can pass commands with --args or -a option

kubectl ssh-jump aks-nodepool1-18558189-0 --args "uname -a"

(Output)
Linux aks-nodepool1-18558189-0 4.15.0-1035-azure #36~16.04.1-Ubuntu SMP Fri Nov 30 15:25:49 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

You can clean up sshjump pod at the end of the command with --cleanup-jump option, otherwise, the sshjump pod stay running by default.

$ kubectl ssh-jump aks-nodepool1-18558189-0 \
  -u azureuser -i ~/.ssh/id_rsa_k8s -p ~/.ssh/id_rsa_k8s.pub \
  --cleanup-jump

You can clean up ssh-agent at the end of the command with --cleanup-agent option, otherwise, the ssh-agent process stay running once it's started.

$ kubectl ssh-jump aks-nodepool1-18558189-0 \
  -u azureuser -i ~/.ssh/id_rsa_k8s -p ~/.ssh/id_rsa_k8s.pub \
  --cleanup-agent

You can skip starting ssh-agent by giving --skip-agent. This is actually a case where you already have ssh-agent managed. Or you can start new ssh-agent and add an identity key to the ssh-agent like this:

# Start ssh-agent manually
$ eval `ssh-agent`
# Add an arbitrary private key, give the path of the key file as an argument to ssh-add
$ ssh-add ~/.ssh/id_rsa_k8s
# Then, run the plugin with --skip-agent
$ kubectl ssh-jump aks-nodepool1-18558189-0 \
  -u azureuser -i ~/.ssh/id_rsa_k8s -p ~/.ssh/id_rsa_k8s.pub \
  --skip-agent

# At the end, run this if you want to kill the current agent
$ ssh-agent -k
1-2 - You have .pem file but you don't have public key on your side

From v0.4.0, the plugin supports PEM (Privacy Enhanced Mail) scenario where you create key-pair but you only have .pem / private key (downloaded from AWS, for example) and you don't have the public key on your side.

Suppose you've already downloaded a pem file and you want to ssh to your EKS worker node (EC2) named ip-10-173-62-96.ap-northeast-1.compute.internal using the pem, execute the plugin with options like this:

  • usernaem: ec2-user
  • identity: ~/.ssh/mykey.pem
$ kubectl ssh-jump -u ec2-user -i ~/.ssh/mykey.pem ip-10-173-62-96.ap-northeast-1.compute.internal

CASE 2: Access remote serivces via SSH local port forwarding

SSH local port forwarding allows to forward the traffic form local machine to SSH jump then SSH jump will forward the traffic to remote services (host:port)s.

2-1 - Configuring SSH local port forwarding with --args or -a option

Suppose you have private & public SSH key on your side and you want to access a remote server (IP: 10.100.10.8) using 3389/TCP port which is not accessible directly but accessible via SSH jump, execute the plugin with options like this, at first:

  • identity:~/.ssh/id_rsa_k8s
  • pubkey:~/.ssh/id_rsa_k8s.pub)

The command below allows to forward the traffic form local machine (localhost:13200) to SSH jump then SSH jump will forward the traffic to the remote server (10.100.10.8:3389).

$ kubectl ssh-jump sshjump \
  -i ~/.ssh/id_rsa_k8s -p ~/.ssh/id_rsa_k8s.pub \
  -a "-L 13200:10.100.10.8:3389"
  • sshjump is the hostname for SSH jump Pod
  • The value for --arg or -a should be in this format: "-L local_port:remote_address:remote_port"

Now, you're ready to access to the remote server at port 13200 at local machine.

Useful Links

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/yokawasa/kubectl-plugin-ssh-jump

More Repositories

1

azure-functions-python-samples

Azure Functions Python Sample Codes. NOTE: The project, hosted in a repository, is no longer actively maintained by its creators or contributors. There won't be any further updates, bug fixes, or support from the original developers in the project.
Python
391
star
2

databricks-notebooks

Collection of Sample Databricks Spark Notebooks ( mostly for Azure Databricks )
Jupyter Notebook
80
star
3

envoy-proxy-demos

Set of Envoy Proxy feature demos (Envoy v2 API supported)
Python
76
star
4

action-setup-kube-tools

Github Action that setup Kubernetes tools (kubectl, kustomize, helm, kubeconform, conftest, yq, rancher, tilt, skaffold) very fast and cache them on the runner. Please [✩Star] if you're using it!
TypeScript
74
star
5

fluent-plugin-azure-loganalytics

Azure Log Analytics output plugin for Fluentd
Ruby
53
star
6

kubectl-plugin-socks5-proxy

This is a kubectl plugin that creates a local SOCKS5 proxy through which you can access to pods/services in a Kubernetes cluster. Please [✩Star] if you're using it!
Shell
52
star
7

logstash-output-azure_loganalytics

Azure Log Analytics output plugin for Logstash
Ruby
28
star
8

azure-container-labs

Azure Container Labs - AKS, ACR, ACI, Web App for Containers, etc under frequent update
Shell
27
star
9

action-sqlcheck

A GitHub Action that automatically identifies anti-patterns in SQL queries using sqlcheck when PR is requested. Please [✩Star] if you're using it!
Shell
24
star
10

scrapy-azuresearch-crawler-samples

Scrapy as a Web Crawler for Azure Search Samples
Python
21
star
11

mod_log_slow

Apache module for logging of slow requests handling
C
15
star
12

istio-sandbox

Istio sandbox
Shell
14
star
13

azure-shell

[Unofficial] interactive Azure CLI 2.0 command line interface
Python
13
star
14

kubectl-tips

Tips on Kubernetes cluster management using kubectl command
11
star
15

azure-search-ta

Azure Search Test Analyzer API Client Tool
Python
11
star
16

azure-serverless-video-analytics

Demo Application of Serverless Video Analytics Workflow using Azure Functions, Logic App, and other multiple Azure Services
JavaScript
11
star
17

code-server-azure-webapp

Visual Studio Code Server on Azure Web App for Containers
Shell
10
star
18

azure-log-analytics-data-collector

Azure Log Analytics Data Collector API Client libraries
Ruby
9
star
19

azure-ssh-config

A command to generate SSH config file from Azure ARM VM inventry in subscription
Python
9
star
20

vs_httpd

Very Simple HTTP Server that can deliver static files very fast.
C
8
star
21

vscode-translator-voice

VS Code extension for multi-language text translation and TTS (text-to-speech) using Azure Cognitive Services. Please [✩Star] if you're using it!
TypeScript
7
star
22

azure-k8s-daas-ticketmonster-demo

Ticket-Monster HA Cluster Demo using Azure Kubernetes Services (AKS) and Managed PostgreSQL
Shell
6
star
23

kube-configmap-exporter

Kubernetes ConfigMap Exporter
Shell
6
star
24

azure-log-analytics-data-collector-python

Azure Log Analytics Data Collector API Client for Python
Python
6
star
25

fluent-plugin-documentdb

Azure DocumentDB output plugin for Fluentd
Ruby
5
star
26

vscode-jwt-debugger

VS Code extension for decoding JWT tokens - VS Code version of jwt.io debugger
TypeScript
5
star
27

action-setup-ecctl

A GitHub action that install a specific version of ecctl (Elastic Cloud control tool) and cache it on the runner. Please [✩Star] if you're using it!
TypeScript
5
star
28

vscode-jaconv

VS Code extension that performs half-width (“Hankaku”) - full-width (“Zenkaku”) conversion for Japanese “kana” and ascii
TypeScript
5
star
29

awsping

A command line tools that reports median latency to AWS regions (a fork of gcping)
Go
4
star
30

TwitterEventHubFeed

Stream feed from Twitter to EventHub
Python
4
star
31

fluent-plugin-azurefunctions

Azure Functions (HTTP Trigger) output plugin for Fluentd
Ruby
4
star
32

software-design-github-actions-samples

「Software Design 2022年2月号 第2特集 GitHub Actionsで簡単・快適CI/CD」の公開サンプルコード
HCL
4
star
33

ci-demo-rails-app

Rails app for CI demo
Ruby
3
star
34

any

any files
C
3
star
35

facetag-services

[Alpha version] Full serverless face tagging services that allow you to build photo sharing services where you can find your registered persons among uploaded photos easily.
Python
3
star
36

logstash-output-documentdb

logstash-output-documentdb is a logstash plugin to output to Azure DocumentDB
Ruby
3
star
37

awk_httpd

GNU AWK HTTP Server Scripts
Awk
3
star
38

azure-containers-mean-stack-demo

MEAN Stack App Conatiner Demos using Azure Container related services and PaaS
Shell
3
star
39

docker-aws-shell

Docker image for aws-shell
3
star
40

mod_interval_limit

Apache module that provide rule-based interval counter limits of connections per client
C
3
star
41

azure-functions-labs

Archived: Azure Functions hands-on labs (Japanese Version)
C#
2
star
42

kinesis-consumer

Sample KCL 2.X consumer for AWS Kinesis streams. The consumer is configurable via environmental variables and can be containerized (dockerfile for it is provided), which can be run anywhere
Java
2
star
43

mysql-plugin-is-mallinfo

MySQL Information Schema plugin that provide information about statistics for dynamic memory allocation of mysqld.
Shell
2
star
44

mod_akismet

Apache module that enables you to detect spam comments before your application handler by Akismet anti-comment-spam service
C
2
star
45

fluent-plugin-azuresearch

Azure Search Output Plugin for Fluentd
Ruby
2
star
46

jsoncat

Pretty Simple JSON Formatter Command
Shell
2
star
47

dot-tools

A collection of utility tools that I use in my daily operations
Shell
2
star
48

mysql-plugin-is-locks

MySQL Information Schema plugin that provide information about table locks
Shell
2
star
49

azure-samples

Personal Azure Sample Code Repository
C#
2
star
50

aksworkshop

The Azure Kubernetes Workshop ( https://aksworkshop.io ) Japanease Version 日本語版
2
star
51

mysql-cipher-functions

MySQL UDFs that provide encryption/decryption functions.
Shell
2
star
52

decode2017

DI08 Azure Search session material used in Microsoft de:code 2017
C#
2
star
53

azure-webapps-logging-original-clientip

Step-by-step configuration guide - How to log the original Client IP in Azure Web Apps (IIS) by using F5 X-Forwarded-For ISAPI filter
Shell
2
star
54

terraform-state-backends

Terraform backends config for state management PoC project
Shell
1
star
55

mod_count_memcookie

Apache module for counting user page view with cookies and memcached
C
1
star
56

kinesis-bulk-loader

A Golang tool that put bulk messages in parallel to AWS Kinesis Data Stream
Go
1
star
57

azure-media-services-php-samples

Azure Media Services PHP Samples
PHP
1
star
58

kubernetes-client-go-samples

A collection of Kubernetes and Istio client-go samples
Go
1
star
59

azure-log-analytics-data-collector-php

Azure Log Analytics Data Collector API Client for PHP
PHP
1
star
60

logstash-output-azuresearch

Azure Search output plugin for Logstash
Ruby
1
star
61

ci-demo-django-app

Python
1
star
62

qna_luis_bot

QnA Bot Application using QnAMaker, LUIS, and Microsoft Bot Framework
C#
1
star
63

kinesis-get-shardid

A Golang tool that get a shard ID to be assigned in AWS Kinesis Data Stream from a partition key
Go
1
star
64

azure-search-qna-demo

Q and A Knowledge Base Search Application Demo using Azure Search
Shell
1
star
65

decode2016

This repository contains source codes used for Azure Search demonstration during de:code 2016 DEV-018 session
Shell
1
star
66

event-gateway-on-kubernetes-azure

How to guide on running Serverless.com's Event Gateway on Kubernetes on Azure
Shell
1
star
67

sqs-bulk-loader

A Golang tool that sends bulk messages in parallel to Amazon SQS
Go
1
star
68

angular4-quickstart

Angular 4 Apps Quickstart Configuration that deploys an app using angular-cli and Docker Container
Shell
1
star
69

github-sandbox

This is my personal GitHub sandbox repository, and its content is primarily based on past GitHub trainings I've done for GitHub newbies
1
star