A kubectl plugin that creates an SSH tunnel to your Kubernetes API server and forwards traffic through it.
- Automatically detects the current Kubernetes context
- Creates an SSH tunnel to the API server
- Executes kubectl commands through the tunnel
- Cleans up the tunnel when done
-
Clone the repository:
git clone https://github.com/yourusername/kubectl-tunnel.git cd kubectl-tunnel -
Build the plugin:
go build -o kubectl-tunnel ./cmd/kubectl-tunnel
-
Make it executable:
chmod +x kubectl-tunnel
-
Move it to a directory in your PATH:
sudo mv kubectl-tunnel /usr/local/bin/kubectl-tunnel
go install github.com/yourusername/kubectl-tunnel/cmd/kubectl-tunnel@latest# Basic usage
kubectl tunnel get pods
# With any kubectl command
kubectl tunnel get nodes
kubectl tunnel get pods -n kube-system
kubectl tunnel apply -f deployment.yaml
# Keep the tunnel open without running a command
kubectl tunnel
# This will give you a KUBECONFIG export. Use this in another terminal for any k8s access. The
# tunnel is removed when you terminate the kubectl tunnel process.- Reads your current kubeconfig
- Extracts the API server URL from the current context
- Creates an SSH tunnel from 127.0.0.2: to the API server
- Creates a temporary kubeconfig using the local tunnel
- Executes the specified kubectl command through the tunnel
- Cleans up the tunnel when done
- Go 1.21 or later
- kubectl installed and configured
- SSH access to the Kubernetes API server
- Proper SSH configuration in ~/.ssh/config for the API server
This plugin does not accept config parameters for SSH access. These can be provided via your ~/.ssh/config file. The hostname will be taken from the CurrentContext in your kubeconfig file.
To build and test changes:
# Build
make build
# Run tests
make test
# Install to $GOPATH/bin
make install