https://github.com/fioletoven/b4n
Terminal user interface (TUI) for Kubernetes API written in Rust
https://github.com/fioletoven/b4n
k8s k8s-cluster kube-rs kubernetes kubernetes-cli kubernetes-cluster ratatui rust
Last synced: about 2 months ago
JSON representation
Terminal user interface (TUI) for Kubernetes API written in Rust
- Host: GitHub
- URL: https://github.com/fioletoven/b4n
- Owner: fioletoven
- License: mit
- Created: 2024-12-30T22:11:56.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-04-27T21:26:24.000Z (2 months ago)
- Last Synced: 2026-04-27T23:20:48.540Z (2 months ago)
- Topics: k8s, k8s-cluster, kube-rs, kubernetes, kubernetes-cli, kubernetes-cluster, ratatui, rust
- Language: Rust
- Homepage:
- Size: 3.29 MB
- Stars: 73
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ratatui - b4n - A terminal-based tool for browsing Kubernetes resources. (💻 Apps / 👨💻 System Administration)
README
# b4n
`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](https://k9scli.io) and built using the [`kube-rs`](https://kube.rs) and [`ratatui`](https://ratatui.rs) crates.

## Prerequisites
The [Cascadia Code font](https://github.com/microsoft/cascadia-code), or any other font with [Nerd Font](https://www.nerdfonts.com/font-downloads) symbols, is required for proper display of the user interface in the terminal.
## Building
To build `b4n` ensure you have a recent Rust toolchain installed (1.88+ recommended). Clone the repository and navigate into the project directory:
```bash
git clone https://github.com/fioletoven/b4n.git
cd b4n
```
Then compile the project in release mode for optimal performance:
```bash
cargo build --release
```
The resulting binary will be available at `./target/release/b4n`.
## Features
### Currently Supported
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.
### Planned
The following features are planned for future development:
- File transfer from/to a pod.
- Custom commands (simple plugin system to run external binaries).
## Default Key Bindings
| 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 describe for the highlighted resource | `d` | |
| 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]` |
## Advanced Filtering
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` + `p` will pin the active filter across resource changes
## Logs View
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.
## Text Selection and Editing
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 text
- `CTRL` + `x` - cut selected text
- `CTRL` + `v` - paste text from clipboard
- `CTRL` + `a` - select all text
- `CTRL` + `d` - delete current line
- `CTRL` + `z` - undo
- `CTRL` + `y` - redo
- `ALT` + `↑` - move current line up
- `ALT` + `↓` - move current line down
> Note: These shortcuts currently cannot be changed in the `key_bindings` configuration section
## Configuration Files
Configuration files are stored in the `$HOME/.b4n` directory. The directory structure is as follows:
```
.b4n/
├─ logs/
├─ themes/
│ └─ default.yaml
├─ config.yaml
└─ history.yaml
```
### logs/
This directory contains application logs, with one log file generated per day.
### themes/
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.
### config.yaml
This file contains configuration settings that control the behaviour of the `b4n` application.
Here is an example structure:
```yaml
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+>
[...]
```
#### Configuration Options
- `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 the `themes` directory (without the `.yaml` extension).
- `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.yaml` does not exist, the application will create it automatically with default values.
### history.yaml
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.
## License
[MIT](./LICENSE)