b4n is a terminal user interface (TUI) for the Kubernetes API, created mainly for learning the Rust programming language. It is heavily based on the k9s project and built using the kube-rs and ratatui crates.
The Cascadia Code font, or any other font with Nerd Font symbols, is required for proper display of the user interface in the terminal.
To build b4n ensure you have a recent Rust toolchain installed (1.88+ recommended). Clone the repository and navigate into the project directory:
git clone https://github.com/fioletoven/b4n.git
cd b4nThen compile the project in release mode for optimal performance:
cargo build --releaseThe resulting binary will be available at ./target/release/b4n.
The following features are currently supported:
- View and filter a list of Kubernetes resources.
- Create, read, update, and delete Kubernetes resources.
- View events for the highlighted resource.
- View logs for the highlighted pod or container.
- Open a shell session or attach to the highlighted container's main process.
- Enable port forwarding for the highlighted container.
- Mouse support in all views.
The following features are planned for future development:
- File transfer from/to a pod.
- Custom commands (simple plugin system to run external binaries).
- Describe Kubernetes resources.
| Action | Command | Comments |
|---|---|---|
| Attach to the container's main process | a |
Works only in containers view |
| Attach to the container's shell | s |
Works only in containers view |
| Copy YAML / logs / resources to clipboard | c |
Works only in YAML, logs and resources views |
| Create new resource | n |
|
| Decode highlighted secret | x |
|
| Delete selected resources | CTRL + d |
Displays a confirmation dialog |
| Enable / disable mouse support | CTRL + n |
Not available inside a shell session |
| Forward container's port | f |
Works only in containers view |
| Go back to namespaces; clear filter | ESC |
Also clears input in the filter widget |
| Navigate to the involved object | i |
Works only for events kind |
| Open / switch to edit mode | i |
Press ESC to exit, then ESC for save dialog |
| Open right mouse button menu | m |
Navigate using ↑ or ↓ |
| Pin active filter across resources | CTRL + p |
Also works in the filter dialog |
| Quit the application | CTRL + c |
No confirmation dialog |
| Reverse selection | CTRL + |
(CTRL + SPACE) |
| Select resource | |
(SPACE) |
| Show / hide log timestamps | t |
Works only in logs view |
| Show / hide port forwards | CTRL + f |
Displays all active port forwarding rules |
| Show command palette | :, > |
For example, entering :q↲ quits the application |
| Show events for the highlighted resource | e |
|
| Show filter / search input | / |
Filter operators: and &, or |, negation !, (, ) |
| Show footer messages history pane | h |
Also works with left mouse button click on the footer |
| Show logs for the pod or container | l |
Press p to display previous logs |
| Show namespaces selector | ← |
To select all rapidly press ← again |
| Show resources selector | → |
To select pods rapidly press → again |
| Show YAML for the highlighted resource | y |
|
| Sort column | ALT + [0-9] |
Also works with ALT + [underlined letter] |
The resources and port forwards views support advanced filtering with prefixes:
ns:- filter by namespace (e.g.,ns:kube-system)n:- filter by resource name (e.g.,n:nginx)a:- filter by annotations (e.g.,a:app.kubernetes.io/name=nginx)l:- filter by labels (e.g.,l:app=frontend)
Filters can be combined using logical operators: & (and), | (or), ! (negation), and parentheses ().
Example: ns:default & (l:app=web | l:app=api)
Note:
CTRL+pwill pin the active filter across resource changes
When viewing logs for a single container, you can fetch earlier log entries by pressing the ↑ (up arrow) key. This feature is only available when you are scrolled to the top of the currently displayed logs and there are additional log entries available before the first visible line.
Note: This functionality works only in single container logs view, not when viewing combined logs for all containers in a pod.
When mouse support is enabled, you can:
- Select text by clicking and dragging in YAML, logs, shell, and attach view
- Select whole words by double-clicking
- Select whole lines by triple-clicking
- Copy selected text to clipboard using standard key bindings
In edit mode, the following shortcuts are available:
CTRL+c- copy selected textCTRL+x- cut selected textCTRL+v- paste text from clipboardCTRL+a- select all textCTRL+d- delete current lineCTRL+z- undoCTRL+y- redoALT+↑- move current line upALT+↓- move current line down
Note: These shortcuts currently cannot be changed in the
key_bindingsconfiguration section
Configuration files are stored in the $HOME/.b4n directory. The directory structure is as follows:
.b4n/
├─ logs/
├─ themes/
│ └─ default.yaml
├─ config.yaml
└─ history.yaml
This directory contains application logs, with one log file generated per day.
This folder stores all TUI (Text User Interface) themes.
The default.yaml theme will be automatically generated by the application if it doesn't already exist.
You can place additional theme files here by copying them from the themes folder or creating your own.
This file contains configuration settings that control the behaviour of the b4n application.
Here is an example structure:
logs:
lines: 800
timestamps: true
mouse: true
theme: light
contexts:
test-cluster: '#43464f:#8aad81'
production: '#d8d8d8:#e1140a'
aliases:
daemonsets: ds,dms
namespace: nn
namespaces: ns,na,nam
services: svc
key_bindings:
action.name: list of key bindings for that action
command-palette.open: :, >, Shift+:, Shift+>
[...]logs.lines- The number of log lines to retrieve from the Kubernetes API for the selected container.logs.timestamps- Indicates whether timestamps are enabled by default for logs; this setting can still be toggled while viewing the logs.mouse- Indicates if mouse support should be enabled when the application starts. Mouse support can also be toggled while the app is running.theme- The name of the currently selected theme. This should match a file in thethemesdirectory (without the.yamlextension).contexts- (Optional) A map of context names to their corresponding colors. Useful for highlighting important Kubernetes clusters with distinct header colors.aliases- Command palette aliases.key_bindings- Defines custom key bindings for various application actions.
Example key bindings:Ctrl+C,Ctrl+Alt+A,F7,Z,Left,Enter.
Note: If
config.yamldoes not exist, the application will create it automatically with default values.
This file stores history for filters, search patterns, and the last selected resource for each Kubernetes context.
To remove history entries (either for a specific context or entirely), you can manually edit this file or even delete it.
History entries can also be deleted from the UI, just highlight one and press Ctrl+D to delete it.
