Code Monkey home page Code Monkey logo

k1s's Introduction

k1s: The world's simplest Kubernetes dashboard

A simplistic Kubernetes dashboard implemented with 50 lines of Bash code.

 ____ ____ ____                                                         |┻┳
||k |||1 |||s ||                                                     __ |┳┻
||__|||__|||__||     The world's simplest Kubernetes dashboard     (•.• |┻┳
|/__\|/__\|/__\|                                                      \⊃|┳┻
                                                                        |┻┳

Screencast

What is it?

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.

What is it not?

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.

How does it work?

With a lot of highly condensed Bash scripting. This article contains a line-by-line explanation of the code.

Installation

macOS with Homebrew

brew install weibeld/core/k1s

All other scenarios

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
}

Dependencies

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/

Usage

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: default
  • resource-type: pods

You can run multiple instances of the k1s script simultaneously.

To exit the dashboard, type Ctrl-C.

Example usages

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

Resource types

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.

All namespaces and non-namespaced 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.

Example application

A suitable example application of k1s is observing the scalings and rolling updates of a Deployment:

Example application

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 and maxUnavailable 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

k1s's People

Contributors

weibeld avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.