Skip to content

node-ssm is a simple kubectl plugin that allows SSM connections to AWS EKS cluster Systems Manager managed nodes. Provided you have the local AWS CLI and session-manager-plugin installed.

License

VioletCranberry/kubectl-node-ssm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kubectl-node-ssm

Description

node-ssm is a straightforward kubectl plugin designed for establishing direct connections to EKS cluster nodes managed by AWS Systems Manager. It operates by utilizing the locally installed AWS CLI and session-manager-plugin. The plugin simplifies the process by automatically converting the provided EKS node name into its corresponding instance ID.

Install with Krew plugin manager

# see https://krew.sigs.k8s.io/
kubectl krew update
kubectl krew install node-ssm

Usage

❯ kubectl get nodes --no-headers | head -n 1            
ip-10-10-10-10.ec2.internal   Ready                      <none>   8d      v1.22.17-eks-48e63af
❯ kubectl node-ssm start-session --target ip-10-10-10-10.ec2.internal

Starting session with SessionId: <username>@<domain>-0480532656ed795d8
sh-4.2$ 

All global global command-line flags listed in kubectl options are supported, for example:

❯ kubectl config current-context
<my-current-context>
❯ kubectl get nodes --context <my-another-context> --no-headers | head -n 1
ip-20-20-20-20.ec2.internal   Ready   <none>   4d19h   v1.22.17-eks-48e63af
❯ kubectl node-ssm start-session --context <my-another-context> --target ip-20-20-20-20.ec2.internal 

Starting session with SessionId: <username>@<domain>-0dd10b4b84087dff4
sh-4.2$

SSM start-session parameters can be set with optional --session-params flag:

kubectl node-ssm start-session --target ip-30-30-30-30.ec2.internal --session-params '--reason=test' --session-params '--debug'
2023-04-10 00:54:45,509 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/2.11.0 Python/3.11.2 Darwin/22.3.0 source/arm64
2023-04-10 00:54:45,509 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['ssm', 'start-session', '--target', 'i-057750d42936e468a', '--reason=test', '--debug']
...

Build and install manually

go build -o kubectl-node_ssm \
  && sudo cp kubectl-node_ssm /usr/local/bin \
  && kubectl plugin list | grep node_ssm \
  && kubectl node-ssm --help
# rm -f /usr/local/bin/node_ssm

Requirements

  1. Installed AWS CLI and AWS session-manager-plugin
  2. Configured AWS Systems Manager Session Manager
  3. IAM Permissions to perform ec2:DescribeInstances

Logic

  1. Extract AWS_REGION and AWS_PROFILE from Config.Host and []ExecEnvVar array of current kubeconfig context.
  2. Create AWS session and resolve EKS node private-dns-name to instance ID using (*EC2) DescribeInstances API operation.
  3. Build aws ssm start-session --target <instance id> command with specified parameters and environment and execute it.

About

node-ssm is a simple kubectl plugin that allows SSM connections to AWS EKS cluster Systems Manager managed nodes. Provided you have the local AWS CLI and session-manager-plugin installed.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published