Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/Ramilito/kubectl.nvim

⎈ Streamline your Kubernetes management within Neovim—control and monitor your cluster seamlessly, all without leaving your coding environment.
https://github.com/Ramilito/kubectl.nvim

kubernetes neovim-plugin

Last synced: about 17 hours ago
JSON representation

⎈ Streamline your Kubernetes management within Neovim—control and monitor your cluster seamlessly, all without leaving your coding environment.

Awesome Lists containing this project

README

        


kubectl.nvim














Processes kubectl outputs to enable vim-like navigation in a buffer for your cluster.

## ✨ Features

Navigate your cluster in a buffer, using hierarchy where possible (backspace for up, enter for down) e.g. root -> deplyoment -> pod -> container

Colored output and smart highlighting

Floating windows for contextual stuff such as logs, description, containers..

Completion

Run custom commands e.g :Kubectl get endpoints

Change context using cmd :Kubectx context-name or the context view

Exec into containers
In the pod view, select a pod by pressing <cr> and then again <cr> on the container you want to exec into

Sort by headers
By moving the cursor to anywhere in a column and pressing gs

Tail logs

Diff view: :Kubectl diff (path)

Port forward

Aliases (fallback view)
A fallback view that directs custom resources and has basic functionality such desc, edit, del

Overview

Lineage
A plugin similar to kube-lineage
⚠️ This is a beta feature and not all bugs are sorted out

## ⚡️ Required Dependencies

- kubectl
- curl
- neovim >= 0.10

## ⚡️ Optional Dependencies

- [kubediff](https://github.com/Ramilito/kubediff) or
[DirDiff](https://github.com/will133/vim-dirdiff) (If you want to use the diff
feature)
- [Helm](https://helm.sh/docs/intro/install/) (for helm view)

## 📦 Installation

Install the plugin with your preferred package manager:

### [lazy.nvim](https://github.com/folke/lazy.nvim)

```lua
return {
{
"ramilito/kubectl.nvim",
config = function()
require("kubectl").setup()
end,
},
}
```

## ⌨️ Keymaps

We expose open, close and toggle to bind against:

#### Toggle

```lua
vim.keymap.set("n", "k", 'lua require("kubectl").toggle()', { noremap = true, silent = true })
```

#### Default Mappings

You can override the plugin's keymaps using the `` mappings:

Default Mappings

```lua
-- default mappings
local group = vim.api.nvim_create_augroup("kubectl_mappings", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
group = group,
pattern = "k8s_*",
callback = function(ev)
local k = vim.keymap.set
local opts = { buffer = ev.buf }

-- Global
k("n", "g?", "(kubectl.help)", opts) -- Help float
k("n", "gr", "(kubectl.refresh)", opts) -- Refresh view
k("n", "gs", "(kubectl.sort)", opts) -- Sort by column
k("n", "gD", "(kubectl.delete)", opts) -- Delete resource
k("n", "gd", "(kubectl.describe)", opts) -- Describe resource
k("n", "gy", "(kubectl.yaml)", opts) -- View yaml
k("n", "ge", "(kubectl.edit)", opts) -- Edit resource
k("n", "", "(kubectl.filter_label)", opts) -- Filter labels
k("n", "", "(kubectl.go_up)", opts) -- Go back to previous view
k("v", "", "(kubectl.filter_term)", opts) -- Filter selected text
k("n", "", "(kubectl.select)", opts) -- Resource select action (different on each view)
k("n", "", "(kubectl.tab)", opts) -- Tab completion (ascending, when applicable)
k("n", "", "(kubectl.shift_tab)", opts) -- Tab completion (descending, when applicable)
k("n", "", "(kubectl.quit)", opts) -- Close view (when applicable)
k("n", "gk", "(kubectl.kill)", opts) -- Pod/portforward kill
k("n", "", "(kubectl.toggle_headers)", opts) -- Toggle headers

-- Views
k("n", "", "(kubectl.alias_view)", opts) -- Aliases view
k("n", "", "(kubectl.contexts_view)", opts) -- Contexts view
k("n", "", "(kubectl.filter_view)", opts) -- Filter view
k("n", "", "(kubectl.namespace_view)", opts) -- Namespaces view
k("n", "gP", "(kubectl.portforwards_view)", opts) -- Portforwards view
k("n", "1", "(kubectl.view_deployments)", opts) -- Deployments view
k("n", "2", "(kubectl.view_pods)", opts) -- Pods view
k("n", "3", "(kubectl.view_configmaps)", opts) -- ConfigMaps view
k("n", "4", "(kubectl.view_secrets)", opts) -- Secrets view
k("n", "5", "(kubectl.view_services)", opts) -- Services view
k("n", "6", "(kubectl.view_ingresses)", opts) -- Ingresses view
k("n", "", "(kubectl.view_api_resources)", opts) -- API-Resources view
k("n", "", "(kubectl.view_clusterrolebinding)", opts) -- ClusterRoleBindings view
k("n", "", "(kubectl.view_crds)", opts) -- CRDs view
k("n", "", "(kubectl.view_cronjobs)", opts) -- CronJobs view
k("n", "", "(kubectl.view_daemonsets)", opts) -- DaemonSets view
k("n", "", "(kubectl.view_events)", opts) -- Events view
k("n", "", "(kubectl.view_helm)", opts) -- Helm view
k("n", "", "(kubectl.view_jobs)", opts) -- Jobs view
k("n", "", "(kubectl.view_nodes)", opts) -- Nodes view
k("n", "", "(kubectl.view_overview)", opts) -- Overview view
k("n", "", "(kubectl.view_pv)", opts) -- PersistentVolumes view
k("n", "", "(kubectl.view_pvc)", opts) -- PersistentVolumeClaims view
k("n", "", "(kubectl.view_sa)", opts) -- ServiceAccounts view
k("n", "", "(kubectl.view_top_nodes)", opts) -- Top view for nodes
k("n", "", "(kubectl.view_top_pods)", opts) -- Top view for pods

-- Deployment/DaemonSet actions
k("n", "grr", "(kubectl.rollout_restart)", opts) -- Rollout restart
k("n", "gss", "(kubectl.scale)", opts) -- Scale workload
k("n", "gi", "(kubectl.set_image)", opts) -- Set image (only if 1 container)

-- Pod/Container logs
k("n", "gl", "(kubectl.logs)", opts) -- Logs view
k("n", "gh", "(kubectl.history)", opts) -- Change logs --since= flag
k("n", "f", "(kubectl.follow)", opts) -- Follow logs
k("n", "gw", "(kubectl.wrap)", opts) -- Toggle wrap log lines
k("n", "gp", "(kubectl.prefix)", opts) -- Toggle container name prefix
k("n", "gt", "(kubectl.timestamps)", opts) -- Toggle timestamps prefix
k("n", "gpp", "(kubectl.previous_logs)", opts) -- Toggle show previous logs

-- Node actions
k("n", "gC", "(kubectl.cordon)", opts) -- Cordon node
k("n", "gU", "(kubectl.uncordon)", opts) -- Uncordon node
k("n", "gR", "(kubectl.drain)", opts) -- Drain node

-- Top actions
k("n", "gn", "(kubectl.top_nodes)", opts) -- Top nodes
k("n", "gp", "(kubectl.top_pods)", opts) -- Top pods

-- CronJob actions
k("n", "gss", "(kubectl.suspend_cronjob)", opts) -- Suspend CronJob
k("n", "gc", "(kubectl.create_job)", opts) -- Create Job from CronJob

k("n", "gp", "(kubectl.portforward)", opts) -- Pods/Services portforward
k("n", "gx", "(kubectl.browse)", opts) -- Ingress view
k("n", "gy", "(kubectl.yaml)", opts) -- Helm view
end,
})
```

#### Lazy Setup

For overriding the default mappings when using `lazy.nvim` [check out our wiki page.](https://github.com/Ramilito/kubectl.nvim/wiki/Lazy-setup)

## ⚙️ Configuration

### Setup

```lua
{
log_level = vim.log.levels.INFO,
auto_refresh = {
enabled = true,
interval = 300, -- milliseconds
},
diff = {
bin = "kubediff" -- or any other binary
},
kubectl_cmd = { cmd = "kubectl", env = {}, args = {}, persist_context_change = false },
terminal_cmd = nil, -- Exec will launch in a terminal if set, i.e. "ghostty -e"
namespace = "All",
namespace_fallback = {}, -- If you have limited access you can list all the namespaces here
hints = true,
context = true,
heartbeat = true,
lineage = {
enabled = false, -- This feature is in beta at the moment
},
logs = {
prefix = true,
timestamps = true,
since = "5m"
},
alias = {
apply_on_select_from_history = true,
max_history = 5,
},
filter = {
apply_on_select_from_history = true,
max_history = 10,
},
float_size = {
-- Almost fullscreen:
-- width = 1.0,
-- height = 0.95, -- Setting it to 1 will cause bottom to be cutoff by statuscolumn

-- For more context aware size:
width = 0.9,
height = 0.8,

-- Might need to tweak these to get it centered when float is smaller
col = 10,
row = 5,
},
obj_fresh = 5, -- highlight if creation newer than number (in minutes)
skew = {
enabled = true
log_level = vim.log.levels.INFO,
}
}
```

## 🎨 Colors

The plugin uses the following highlight groups:

Highlight Groups

| Name | Default | Color |
| ------------------- | ----------------------------- | ----------------------------------------------------------------------------------------- |
| KubectlHeader | `{ fg = "#569CD6" }` | |
| KubectlWarning | `{ fg = "#D19A66" }` | |
| KubectlError | `{ fg = "#D16969" }` | |
| KubectlInfo | `{ fg = "#608B4E" }` | |
| KubectlDebug | `{ fg = "#DCDCAA" }` | |
| KubectlSuccess | `{ fg = "#4EC9B0" }` | |
| KubectlPending | `{ fg = "#C586C0" }` | |
| KubectlDeprecated | `{ fg = "#D4A5A5" }` | |
| KubectlExperimental | `{ fg = "#CE9178" }` | |
| KubectlNote | `{ fg = "#9CDCFE" }` | |
| KubectlGray | `{ fg = "#666666" }` | |
| KubectlPselect | `{ bg = "#3e4451" }` | |
| KubectlPmatch | `{ link = "KubectlWarning" }` | |
| KubectlUnderline | `{ underline = true }` | - |

## 🚀 Performance

### Startup

The setup function only adds ~1ms to startup.
We use kubectl proxy and curl to reduce latency.

### Efficient Resource Monitoring

We leverage the Kubernetes Informer to efficiently monitor resource updates.

By using the `resourceVersion`, we avoid fetching all resources in each loop.

Instead, the Informer provides only the changes, significantly reducing overhead and improving performance.

## ⚠️ Versioning

As we advance to `v1.0.0`, our primary goal is to maintain the stability of the
plugin and minimize any breaking changes. We are committed to providing a
reliable and consistent user experience.

## 💪🏼 Motivation

This plugins main purpose is to browse the kubernetes state using vim like
navigation and keys, similar to oil.nvim for file browsing.