Skip to content

Kubernetes kubectl plugin example using Fabric8 with jbang

Notifications You must be signed in to change notification settings

codementor/k8s-cli-fabric8-jbang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

k8s-cli-fabric8-jbang project

This project is an example of how to extend kubernetes cli (kubectl) with a Java application. It demonstrates the use of Fabric8 Kubernetes Client and access the Kubernetes API. In order to be a kubectl plugin it is necessary to have a file which uses the defined naming convention of kube-<plugin-name>. This is a challenge in Java, but can be done with jbang. In order to provide a good CLI experience picocli is used.

Prerequisites

j'bang and Fabric8

I have found that the quickest way to get started with kubectl plugins and Kubernetes development in Java is jbang and fabric8. jbang strips away the extra cruft allowing demonstrations to be barebones what is necessary. Fabric8 provides a way of accessing the Kubernetes API in a Java friendly way without all the (null, null, null, null...).

Getting Started

Start a cluster: kind create cluster

and run one of the commands: ./kubectl-example pod list

Example:

./kubectl-example pod list
________________________________________________________________
| Pod Name                                  | namespace         |
|===============================================================|
| coredns-6955765f44-f966p                  | kube-system       |
| coredns-6955765f44-xnzbg                  | kube-system       |
| etcd-kind-control-plane                   | kube-system       |
| kindnet-cznll                             | kube-system       |
| kube-apiserver-kind-control-plane         | kube-system       |
| kube-controller-manager-kind-control-plane| kube-system       |
| kube-proxy-tw9cb                          | kube-system       |
| kube-scheduler-kind-control-plane         | kube-system       |
| local-path-provisioner-7745554f7f-gk5j9   | local-path-storage|

List of Commands

  • pod list
  • pod add [-n namespace] [-i image]
  • resources

Adding as a kubectl plugin

The executable needs to be the path. From the root of the project run: export PATH=$PATH:$PWD

Now give kubectl a try with example. run: kubectl example pod list You should get the same output as above.

About

Kubernetes kubectl plugin example using Fabric8 with jbang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published