k8s¶
Kubernetes utilities.
Synopsis¶
Subcommands¶
port-forward- Port-forward to pods with auto-reconnecttail pods- Tail logs from Kubernetes pods
port-forward¶
Port-forward to a running pod from a deployment, statefulset, daemonset, or service. Automatically reconnects when the connection is lost or the pod terminates.
Synopsis¶
Flags¶
| Flag | Short | Description | Default |
|---|---|---|---|
--from-deploy |
-d |
Deployment name to port-forward to | |
--from-sts |
StatefulSet name to port-forward to | ||
--from-ds |
DaemonSet name to port-forward to | ||
--from-svc |
Service name to port-forward to | ||
--namespace |
-n |
Kubernetes namespace | current context |
--keepalive |
-k |
Keep trying to reconnect when connection is lost | true |
Note
Exactly one of --from-deploy, --from-sts, --from-ds, or --from-svc must be specified.
Port Format¶
Ports can be specified as:
local:remote- Forward local port to remote port (e.g.,8080:80)remote- Use same port for local and remote (e.g.,80)
Multiple ports can be forwarded simultaneously.
Examples¶
Port-forward from a deployment:
Port-forward from a StatefulSet:
Port-forward from a DaemonSet:
Port-forward from a Service:
Multiple ports:
Specific namespace:
Disable auto-reconnect:
Features¶
-
Auto-reconnect: Automatically finds a new pod and reconnects when:
- The current pod is deleted or crashes
- A deployment/statefulset rolls out new pods
- The connection is lost for any reason
-
Proactive monitoring: Checks pod status every 2 seconds and reconnects before the connection fails (no need to wait for traffic to discover dead connections)
-
Quick reconnect backoff: If connection is lost within 5 seconds, waits 1 second before reconnecting to avoid rapid reconnection loops
-
Shell completion: Tab completion for resource names and namespaces
Output¶
Port-forwarding to pod nginx-abc123-xyz (ports: 8080:80)
Forwarding from 127.0.0.1:8080 -> 80
Pod nginx-abc123-xyz is no longer running, triggering reconnect...
Connection lost quickly, waiting 1s before reconnecting...
Port-forwarding to pod nginx-def456-uvw (ports: 8080:80)
Forwarding from 127.0.0.1:8080 -> 80
Notes¶
- Requires
kubectlto be installed and configured - Press Ctrl+C to stop port-forwarding
- Works with any workload type that creates pods with selector labels
tail pods¶
Continuously tail logs from Kubernetes pods matching the specified criteria. Automatically discovers new pods and handles pod restarts.
Synopsis¶
Flags¶
| Flag | Short | Description | Default |
|---|---|---|---|
--from-deploy |
-d |
Filter pods by deployment name (can be repeated) | |
--labels |
-l |
Label selector (can be repeated, AND logic) | |
--names |
-n |
Pod name pattern filter (substring match, OR logic) | |
--namespace |
Kubernetes namespace | current context | |
--all-namespaces |
-A |
Search pods in all namespaces | false |
--max-pods |
Maximum pods to tail simultaneously | 10 |
|
--tail |
Number of lines to initially read | 20 |
|
--since |
Only return logs newer than duration (e.g., 5m, 1h) | ||
--interval |
Pod discovery poll interval in milliseconds | 500 |
Examples¶
Tail pods from a deployment:
Tail pods by label:
Tail pods by name pattern:
Tail from specific namespace:
Tail from all namespaces:
Only logs from last 5 minutes:
Multiple filters:
Output¶
[my-deployment-abc123] 2024-01-15T10:30:00Z INFO Starting server
[my-deployment-def456] 2024-01-15T10:30:01Z INFO Connection established
[my-deployment-abc123] 2024-01-15T10:30:02Z DEBUG Processing request
Features¶
- Auto-discovers new pods matching criteria
- Handles pod restarts automatically
- Prefixes each line with pod name
- Supports namespace/pod format with
-Aflag - Shell completion for deployments and namespaces
Notes¶
- Requires
kubectlto be installed and configured - Press Ctrl+C to stop tailing
- Maximum 10 pods by default (configurable with
--max-pods)