Skip to content

jbangdev/k8s-cli-java

jbang
Switch branches/tags
Code
This branch is 8 commits ahead of codementor:master.
Contribute

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

k8s-cli-java project

This project is an example of how to extend kubernetes cli (kubectl) with a Java application. It demonstrates the use of Kubernetes client-java 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 kubectl-<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

Getting Started

Start a cluster: kind create cluster

and run one of the commands: ./KubeExample.java pod list

Example:

./KubeExample.java pod list
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
________________________________________________________________
| 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 list2
  • 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

Simple Java Demo of Kubernetes kubectl plugin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published