Skip to main content
Kubernetes Dashboard provides a built-in terminal for executing commands directly in running containers. This feature is invaluable for debugging, troubleshooting, and interactive exploration.

Overview

The Dashboard terminal uses WebSocket connections (via SockJS) to establish interactive shell sessions with your containers. This provides:
  • Interactive shell access (bash, sh, powershell, cmd)
  • Real-time command execution
  • Terminal resizing and scrolling
  • Multiple concurrent sessions
  • Secure communication over HTTPS
Shell access requires the container to have a shell binary installed. Common shells include bash, sh, powershell, and cmd.

Accessing the Terminal

There are multiple ways to open a shell session:
  1. Navigate to WorkloadsPods
  2. Click on a pod name
  3. Click the Exec button in the action bar
  4. Select the target container

Terminal Interface

The Dashboard terminal provides a full-featured shell environment:

Features

Interactive Shell

Full TTY support with command history and tab completion

Terminal Resize

Automatically adapts to browser window size

Copy/Paste

Standard clipboard operations for commands and output

Scrollback

Scroll through command history and output

Keyboard Shortcuts

  • Ctrl+C: Send interrupt signal (SIGINT)
  • Ctrl+D: Send EOF signal (exit shell)
  • Ctrl+L: Clear terminal screen
  • Arrow Up/Down: Navigate command history
  • Tab: Autocomplete commands and paths

Terminal Implementation

Dashboard implements terminal access using WebSockets and the Kubernetes exec API.

Session Management

Terminal sessions are managed via SockJS connections (modules/api/pkg/handler/terminal.go:49-69):

Message Protocol

The terminal uses a message-based protocol:

Shell Detection

Dashboard automatically detects available shells (modules/api/pkg/handler/terminal.go:271-305):
If no shell is specified, Dashboard tries shells in order: bash, sh, powershell, cmd.

Process Execution

The terminal establishes a SPDY connection to the Kubernetes API (modules/api/pkg/handler/terminal.go:216-255):

Common Use Cases

Debugging Application Issues

1

Open Shell

Execute into the problematic container
2

Inspect Environment

Check environment variables and configuration:
3

Test Connectivity

Verify network connectivity to dependencies:
4

Review Files

Check application logs and data:

Inspecting Container State

Common inspection commands:

Testing Configuration Changes

Test configuration before deploying:

Installing Debug Tools

Install troubleshooting utilities temporarily:
Temporary Changes Only: Changes made in a running container are lost when the container restarts. Update your container image for permanent changes.

Security Considerations

Shell access requires the pods/exec permission:
Verify permissions:
Terminal sessions should only be accessed over HTTPS to prevent command interception. The WebSocket connection inherits the HTTP(S) protocol.
Enable audit logging to track exec sessions:
Grant exec permissions only to trusted users and service accounts. Consider using Pod Security Policies or admission controllers to restrict exec access.

Troubleshooting

Check WebSocket connectivity: Ensure your network allows WebSocket connections and that no proxies are interfering.Verify pod status:
The pod must be in “Running” state.Check container status: Ensure the container is running and healthy:
Error: “Process exited” or connection immediately closes.Cause: The container doesn’t have a shell binary.Solution: Use a debug container or update your image:
Or use ephemeral debug containers (Kubernetes 1.23+):
Check for blocking commands: Some commands may block indefinitely. Press Ctrl+C to interrupt.Verify network connectivity: Test the WebSocket connection by closing and reopening the terminal.Check browser console: Look for JavaScript errors or WebSocket connection issues.
Check RBAC permissions:
Check pod security context: Some pods run as non-root users with restricted permissions. Use sudo if available, or exec as root:

Terminal Limitations

Be aware of Dashboard terminal limitations:
  • No file upload: Cannot upload files directly (use kubectl cp instead)
  • No session persistence: Sessions close when browser tab closes
  • No multiplexing: One terminal per browser tab
  • Limited scrollback: Browser memory constraints
For advanced terminal features, consider using:
  • kubectl exec: Full terminal features and file operations
  • k9s: Interactive Kubernetes CLI
  • Lens: Desktop Kubernetes IDE with built-in terminal

Best Practices

Prefer inspection over modification:
Make permanent changes via updated container images or ConfigMaps.
Keep notes of commands and findings for future reference and team collaboration.
Remove temporary files created during debugging:
For distroless or minimal images, use debug containers instead of modifying running containers:

Advanced Usage

Specifying Shell

Request a specific shell via URL parameter:
Supported shells:
  • bash: Bourne Again Shell
  • sh: POSIX shell
  • powershell: Windows PowerShell
  • cmd: Windows Command Prompt

Session Timeout

Sessions automatically close after 10 seconds if the WebSocket connection isn’t established (modules/api/pkg/handler/terminal.go:314-318):

Next Steps

Viewing Logs

Access container logs for debugging

Managing Resources

Learn about resource management