kubectl ssh provides a kubectl exec-like interface, but executes via SSH to the underlying node.
- Resolves targets like
kubectl exec:POD,TYPE/NAME, or-f/--filename. - SSHes to the node hosting the selected pod.
- Executes container commands via
crictl exec. - Supports
--nodeto run directly on the node (skip container execution path).
kubectl ssh (POD | TYPE/NAME) [-c CONTAINER] [flags] [-- COMMAND [args...]]If no command is provided, it opens an interactive shell.
# Pod target
kubectl ssh mypod -n default -- /bin/sh -lc 'echo hello'
# Workload targets
kubectl ssh deploy/mydeploy -n default -- /bin/sh -lc 'echo hello'
kubectl ssh svc/myservice -n default -- /bin/sh -lc 'echo hello'
# Node mode
kubectl ssh mypod -n default --node -- hostname
kubectl ssh node/mynode -- hostname
# Login user override (otherwise SSH config/default user is used)
kubectl ssh -l myuser mypod -n default -- /bin/sh -lc 'echo hello'
# Interactive shell (no command)
kubectl ssh mypod -n defaultOn your local machine:
sshkubectl
On target nodes:
crictlwithexecsupport is required- If your login user cannot run CRI operations directly, passwordless
sudoforcrictlis needed
go build -o kubectl-ssh .Run directly via Nix (no install step):
nix run github:pbar1/kubectl-ssh -- --helpOr build locally and place kubectl-ssh on your PATH:
go build -o kubectl-ssh .scripts/test-live.shOptional interactive checks:
scripts/test-live.sh --interactive