An open API service indexing awesome lists of open source software.

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 1 month ago
JSON representation

Terminal user interface (TUI) for Kubernetes API written in Rust

Awesome Lists containing this project

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.

![b4n demo](assets/b4n.gif?raw=true "b4n")

## 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 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 in the highlighted container.
- Enable port forwarding for the highlighted container.

### Planned

The following features are planned for future development:

- Describe Kubernetes resources.

## Default Key Bindings

| Action | Command | Comments |
|:------------------------------------------|:----------------|:------------------------------------------------------------|
| 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 the edit mode | `i` | Press `Esc` to exit, then `Esc` for save dialog |
| Open right mouse button menu | `m` | Navigate using `↑` or `↓` |
| Quit the application | `CTRL` + `c` | |
| 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 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` quickly press `←` again |
| Show resources selector | `→` | To select the first item quickly press `→` again |
| Show YAML for the highlighted resource | `y` | |
| Sort column | `ALT` + `[0-9]` | Also works `ALT` + `[underlined letter]` |

## 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
namespaces: ns
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 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`.

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)