A simplistic Kubernetes dashboard implemented with 50 lines of Bash code.
____ ____ ____ |┻┳
||k |||1 |||s || __ |┳┻
||__|||__|||__|| The world's simplest Kubernetes dashboard (•.• |┻┳
|/__\|/__\|/__\| \⊃|┳┻
|┻┳
A minimalistic Kubernetes dashboard allowing you to observe any resource type in any namespace (or across all namespaces) in real-time.
It's implemented as a Bash script with 50 lines of code.
k1s is not a full-featured production-grade Kubernetes dashboard (for such a use case, it would be better to use a real programming language, like Go).
Instead, it's an experiment of how far you can go with building something useful with Bash with as little code and as few dependencies as possible.
With a lot of highly condensed Bash scripting. This article contains a line-by-line explanation of the code.
brew install weibeld/core/k1s
Download the k1s
script, make it executable, and move it to any directory in your PATH
. For example:
{
wget https://raw.githubusercontent.com/weibeld/k1s/master/k1s
chmod +x k1s
mv k1s /usr/local/bin
}
The k1s
script depends on the following additional tools being installed on your system:
jq
# macOS brew install jq # Linux sudo apt-get install jq
watch
# macOS brew install watch # Linux (installed by default)
curl
# macOS (installed by default) # Linux sudo apt-get install curl
kubectl
# macOS brew install kubernetes-cli # Linux # See https://kubernetes.io/docs/tasks/tools/install-kubectl/
The k1s
script is run directly on your local machine. It has the following command-line interface:
k1s [namespace] [resource-type]
Both arguments are optional. The default values are:
namespace
: defaultresource-type
: pods
You can run multiple instances of the k1s
script simultaneously.
To exit the dashboard, type Ctrl-C.
Observe Pods in the default
namespace:
k1s
Observe Pods in the kube-system
namespace:
k1s kube-system
Observe Deployments in the default
namespace:
k1s "" deployments
Observe Deployments in the kube-system
namespace:
k1s kube-system deployments
Observe Deployments across all namespaces:
k1s - deployments
Observe ClusterRoles (non-namespaced resource):
k1s - clusterroles
You can specify the desired resource type in any of the name variants accepted by Kubernetes. In general, this includes:
- The plural form
- The singular form
- The shortname (if available)
Furthermore, the capitalisation of the plural and singular forms doesn't matter.
For example, all the following invocations are equivalent:
k1s default replicasets
k1s default replicaset
k1s default rs
k1s default ReplicaSets
k1s default ReplicaSet
You can find out the shortnames of all Kubernetes resources that have one with
kubectl api-resources
.
You can specify -
for the namespace
argument to list the specified resource type across all namespaces of the cluster.
For example, the following displays the Deployments from all the namespaces:
k1s - deployments
In the same way, you can list non-namespaced resources (such as Namespaces, ClusterRoles, PersistentVolumes, etc.).
For example:
k1s - persistentvolumes
You can find out all the non-namespaced resources with
kubectl api-resources --namespaced=false
.
A suitable example application of k1s is observing the scalings and rolling updates of a Deployment:
Note how during the rolling update you can observe the ReplicaSets that the Deployment creates and manages, and how the replica count of the Deployment always stays within a certain range.
You can influence this range with the
maxSurge
andmaxUnavailable
settings in the Deployment specification.
To recreate the above example, launch three instances of k1s, one for Deployments, one for ReplicaSets, and one for Pods:
k1s default deployments
k1s default replicasets
k1s default pods
Then, create a Deployment:
kubectl create deployment dep1 --image=nginx
Scale the Deployment:
kubectl scale deployment dep1 --replicas=10
Change the container image in the Pod template of the Deployment, which causes a rolling update:
kubectl patch deployment dep1 -p '{"spec":{"template":{"spec":{"containers":[{"name":"nginx","image":"nginx:1.19.0"}]}}}}'
You can also manually edit the Deployment with
kubectl edit deployment dep1
.
Finally, delete the Deployment:
kubectl delete deployment dep1