Deploy a pod using Java Kubernetes client Api

7/12/2019

What is the clean way to deploy a pod using kubernetes client api in Java ?

import io.kubernetes.client.ApiClient;

-- Smaillns
api
java
kubernetes

1 Answer

7/12/2019
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.Configuration;
import io.kubernetes.client.apis.CoreV1Api;
import io.kubernetes.client.models.V1Pod;
import io.kubernetes.client.models.V1PodList;
import io.kubernetes.client.util.Config;

import java.io.IOException;

public class Example {
    public static void main(String[] args) throws IOException, ApiException{
        ApiClient client = Config.defaultClient();
        Configuration.setDefaultApiClient(client);

        CoreV1Api api = new CoreV1Api();
        V1Pod podTemplate = init_pod;
        V1Pod pod = api.createNamespacedPod(pod creation arguments and podTemplate)
        System.out.println("pod status : " + pod.getStatus().getPhase());
    }
}

The above code might not be accurate. But this code might give you a gist of getting started.

A sample medium post that describes using java client of kubernetes is here

-- Malathi
Source: StackOverflow