Interacting with kubernetes looks too much like this:
# does not actually work
kubectl get po
| detect columns --guess
| update AGE {|po|
$po.AGE
| str replace 's' 'sec'
| str replace 'm' 'min'
| str replace 'h' 'hour'
| str replace 'd' 'day'
| into datetime
}
| sort-by AGEI wish i could just kubectl get po | sort-by age and leverage the power of nushell. Don't you?
Nuke re-implements some of kubectl commands.
It talks directly with the kube-apiserver to retrieve structured objects and typed data, so we can run things like:
nuke get po -o wide | where node in (
(nuke top no | sort-by memory -r | first 3).name
) # gets the pods running on the most overloaded nodes- Nuke does not aim to reimplement all of kubectl. It focuses on the commands that wuould benefit from nushell's structured data.
- Nuke tries to mimick kubectl syntax to recreate a familiar environment. No need to learn a new tool.
- Nuke uses your kubeconfig as configuration. No additional setup is required.
- Nuke tries to adhere to kubectl semantics, integrating it with richer data.
| Nuke Command | kubectl Equivalent |
|---|---|
| nuke get | kubectl get |
| nuke http-get | kubectl get --raw |
| nuke api-resources | kubectl api-resources |
| nuke api-versions | kubectl api-versions |
| nuke rollout status | kubectl rollout status |
| nuke rollout history | kubectl rollout history |
| nuke top | kubectl top |
| nuke config | kubectl config |
- Reads your kubeconfig
- Authenticates against the API server
- Performs HTTP requests directly
- Applies resource-specific formatter
- Returns structured Nushell data
If no formatter is implemented, a default formatter is used.
Nuke authenticates with the Kubernetes API server using the credentials defined in your kubeconfig, following a precedence model similar to kubectl.
- Bearer token authentication
- Bearer tokenfile authentication
- client certificate (mTLS)
- client certificatefile (mTLS)
- basic auth
- exec-plugins
If configured in the kubeconfig, Nuke also supports Kubernetes impersonation via the as and as-groups user fields.
Cluster TLS settings are also taken from kubeconfig, as well as the insecure-skip-tls-verify option.
# Clone this repository into one of your NU_LIB_DIRS:
let nuke_basedir = ([($env.NU_LIB_DIRS | first) nuke] | path join)
git clone git@github.com:lassoColombo/nuke.git $nuke_basedir
# Verify installation:
use nuke
nuke api-resourcescurl— used for HTTP communication with the API server
Commands that retrieve objects support three formats:
| Format | Description |
|---|---|
| compact | minimal view (Default for lists). |
| wide | extended attributes (Default for single objects). |
| full | the complete object from the API |
Nuke is currently under active development, so not all resources have a dedicated formatter yet.
When a specific formatter isn’t available, Nuke automatically falls back to the default formatter.
You can override formatters or implement new ones using environment variables:
NUKE_RESOURCE_FORMATTERSNUKE_ROLLOUTSTATUS_FORMATTERSNUKE_ROLLOUTHISTORY_FORMATTERSNUKE_METRIC_FORMATTERS
Example:
# NUKE_RESOURCE_FORMATTERS, NUKE_ROLLOUTSTATUS_FORMATTERS and NUKE_METRIC_FORMATTERS all adhere to the following interface:
$env.NUKE_RESOURCE_FORMATTERS = {
apps: { # api group (see `nuke api-versions | select group name version` for the full list)
v1: { # api version
deployments: { # resource name
| output?: string = compact | # either compact or wide
#
# your formatter takes in input the whole object from the kube-apiserver and must return
# a formatted object as a nushell record
let obj = $in
let res = {
name: $obj.metadata.name
namespace: $obj.metadata.namespace
}
if $output == compact {
return ($res
| insert containers ($obj.spec.template.spec.containers | length)
)
}
$res
| insert containers $obj.spec.template.spec.containers
}
}
}
}
# NUKE_ROLLOUTHISTORY_FORMATTERS adhere to the following interface:
$env.NUKE_ROLLOUTHISTORY_FORMATTERS = {
apps: { # same structure as above
v1: {
deployments: {
|
owner: record, # the owner object (eg: the whole deployment/daemonset)
parents: list, # all RS items in the namespace (eg: repicasets for deployments, controllerrevisions for the others)
revision: int, # if set, return only this revision
output?: string = compact # either compact or wide
|
# your formatting logic here
}
}
}
}The http-get method performs an authenticated request to the kube API-server and returns the result as structured data without performing any additional parsing.
The request url can be specified as a string or as a record as expected by url-join.
# get pods
nuke http-get api/v1/namespaces/<namespace>/pods
# get pods by label
nuke http-get {
path: api/v1/namespaces/<namespace>/pods
params: [
{key: labelSelector, value: 'my-label in (my-value-1, my-value-2)'}
]
}
# get aggregated api discovery
nuke http-get apis -H {
Accept: "application/json;v=v2;g=apidiscovery.k8s.io;as=APIGroupDiscoveryList"
}Nuke provides utilities to manage your kubectl configuration, and to help you switch context swiftly.
Context switching takes inspiration from kubectx and kubens:
nuke config switch-namespace monitoring # explicit switch
nuke config switch-context # interactive switch - triggers input listNuke provides structured access to your kubeconfig data:
nuke config # returns the kubeconfig
nuke config path # get the path to the current detected kubeconfig
nuke config get-contexts # get all the contexts
nuke config get-contexts --current # get the current context
nuke config get-current-namespace # get the current namespace
nuke config get-clusters --current # get the current cluster
nuke config get-users --context k8s-001 # get the user of context k8s-001
nuke config get-cluster --context k8s-qa # get the cluster of context k8s-qa- Improve coverage of built-in resource formatters
- Implement
nuke describecommand - Implement
--revisionflag for rollout command - Additional authentication methods
- Exec plugins
- Watch functionality
Contributions, bug reports, and feature requests are welcome.
Before opening an issue or pull request, please read: CONTRIBUTING.md The contributing guide includes:
- Development setup
- How to reproduce bugs
- KIND cluster configuration
- Metrics server setup
- Formatter development guidelines
