HTTPS SSH

Introduction

Amdatu Kubernetes is a client library for Kubernetes. It makes the Kubernetes REST API available to Java. This library is designed specifically to work well with OSGi, but can be easily used in any other Java environment as well.

Usage within OSGi

In an OSGi application a service is registered with interface Kubernetes. The service needs to be configured with the url to your Kuberentes API server using Configuration Admin. The PID of the service is org.amdatu.kubernetes.

Using Felix Dependency Manager you can easily inject the Kubernetes service.

@Component
public class Example {
    @ServiceDependency  
    private volatile Kubernetes m_kubernetes;

    public void test() {
        kubernetes.listNodes().subscribe(nodes -> {
            nodes.getItems().forEach(System.out::println);
        });
    }
}

Usage outside of OSGi

In a non-OSGi Java application you pass the Kubernetes API url to the constructor of the KubernetesRestClient.

public class PlainJavaExample {
    private Kubernetes m_kubernetes;

    @Before
    public void setup() {
        m_kubernetes = new KubernetesRestClient("http://[kubernetes-api]:8080", "v1");
    }

    @Test
    public void listNodes() {
        TestSubscriber<NodeList> testSubscriber = new TestSubscriber<>();
        m_kubernetes.listNodes().subscribe(testSubscriber);

        testSubscriber.assertCompleted();
        testSubscriber.assertNoErrors();
    }
}

For Gradle/Maven users the library is available on Bintray. The following Gradle setup contains the correct repository and coordinates.

repositories {
    maven {
        url  "http://dl.bintray.com/cloud-rti/maven"
    }

    mavenCentral()
}


dependencies {
    compile "org.amdatu:amdatu-kubernetes:2.0.1"
    compile "io.reactivex:rxjava:1.1.5"

}

Using RX Observables

The Amdatu Kubernetes API is based on RX, and returns Observables from all methods. This makes it much easier to deal with the asynchronous nature of a HTTP based API.

The integration tests of the project are the best place to learn how to use the API.

Running the integration tests

To run the integration tests, you need a local Kubernetes cluster. We use minikube to start a single node cluster on the local machine and kubectl running in proxy mode to access the REST API directly. Check this document on how to install and start minikube. To run kubectl in proxy mode:

kubectl proxy --port=8080 &

Build & Publish

This repository uses Bitbucket Pipelines for

  • running a build on every push
  • publishing artifacts for every tag:
    • a bundle is pusblished to the download section of this repository. This step need the configuration of the BB_AUTH_STRING variable, see Pipelines documentation
    • a bundle is uploaded to Bintray. Note: it needs to be published in a manual step yet! This step needs the configuration of BINTRAY_USER and BINTRAY_KEY variables.