Search in sources :

Example 1 with V1PodBuilder

use of io.kubernetes.client.openapi.models.V1PodBuilder in project java by kubernetes-client.

the class YamlExample method main.

public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException {
    V1Pod pod = new V1PodBuilder().withNewMetadata().withName("apod").endMetadata().withNewSpec().addNewContainer().withName("www").withImage("nginx").withNewResources().withLimits(new HashMap<>()).endResources().endContainer().endSpec().build();
    System.out.println(Yaml.dump(pod));
    V1Service svc = new V1ServiceBuilder().withNewMetadata().withName("aservice").endMetadata().withNewSpec().withSessionAffinity(V1ServiceSpec.SessionAffinityEnum.CLIENTIP).withType(V1ServiceSpec.TypeEnum.NODEPORT).addNewPort().withProtocol(V1ServicePort.ProtocolEnum.TCP).withName("client").withPort(8008).withNodePort(8080).withTargetPort(new IntOrString(8080)).endPort().endSpec().build();
    System.out.println(Yaml.dump(svc));
    // Read yaml configuration file, and deploy it
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    // See issue #474. Not needed at most cases, but it is needed if you are using war
    // packging or running this on JUnit.
    Yaml.addModelMap("v1", "Service", V1Service.class);
    // Example yaml file can be found in $REPO_DIR/test-svc.yaml
    File file = new File("test-svc.yaml");
    V1Service yamlSvc = (V1Service) Yaml.load(file);
    // Deployment and StatefulSet is defined in apps/v1, so you should use AppsV1Api instead of
    // CoreV1API
    CoreV1Api api = new CoreV1Api();
    V1Service createResult = api.createNamespacedService("default", yamlSvc, null, null, null, null);
    System.out.println(createResult);
    V1Service deleteResult = api.deleteNamespacedService(yamlSvc.getMetadata().getName(), "default", null, null, null, null, null, new V1DeleteOptions());
    System.out.println(deleteResult);
}
Also used : V1DeleteOptions(io.kubernetes.client.openapi.models.V1DeleteOptions) V1PodBuilder(io.kubernetes.client.openapi.models.V1PodBuilder) IntOrString(io.kubernetes.client.custom.IntOrString) V1ServiceBuilder(io.kubernetes.client.openapi.models.V1ServiceBuilder) V1Pod(io.kubernetes.client.openapi.models.V1Pod) V1Service(io.kubernetes.client.openapi.models.V1Service) ApiClient(io.kubernetes.client.openapi.ApiClient) File(java.io.File) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api)

Example 2 with V1PodBuilder

use of io.kubernetes.client.openapi.models.V1PodBuilder in project pravega by pravega.

the class K8SequentialExecutor method getTestPod.

private V1Pod getTestPod(String className, String methodName, String podName) {
    log.info("Running test pod with security enabled :{}, transport enabled: {}", Utils.AUTH_ENABLED, Utils.TLS_AND_AUTH_ENABLED);
    V1Pod pod = new V1PodBuilder().withNewMetadata().withName(podName).withNamespace(NAMESPACE).withLabels(ImmutableMap.of("POD_NAME", podName, "app", APP)).endMetadata().withNewSpec().withServiceAccountName(SERVICE_ACCOUNT).withAutomountServiceAccountToken(true).withVolumes(new V1VolumeBuilder().withName("task-pv-storage").withPersistentVolumeClaim(new V1PersistentVolumeClaimVolumeSourceBuilder().withClaimName("task-pv-claim").build()).build()).addNewContainer().withName(// container name is same as that of the pod.
    podName).withImage(TEST_POD_IMAGE).withImagePullPolicy("IfNotPresent").withCommand("/bin/sh").withArgs("-c", "java" + getArgs() + " -cp /data/test-collection.jar io.pravega.test.system.SingleJUnitTestRunner " + className + "#" + methodName + /*+ " > server.log 2>&1 */
    "; exit $?").withVolumeMounts(new V1VolumeMountBuilder().withMountPath("/data").withName("task-pv-storage").build()).endContainer().withRestartPolicy("Never").endSpec().build();
    if (Utils.TLS_AND_AUTH_ENABLED) {
        pod = new V1PodBuilder(pod).editSpec().withVolumes(new V1VolumeBuilder().withName("tls-certs").withSecret(new V1SecretVolumeSourceBuilder().withSecretName(Utils.TLS_SECRET_NAME).build()).build()).editContainer(0).withVolumeMounts(new V1VolumeMountBuilder().withMountPath(Utils.TLS_MOUNT_PATH).withName("tls-secret").build()).endContainer().endSpec().build();
    }
    return pod;
}
Also used : V1VolumeBuilder(io.kubernetes.client.openapi.models.V1VolumeBuilder) V1SecretVolumeSourceBuilder(io.kubernetes.client.openapi.models.V1SecretVolumeSourceBuilder) V1PodBuilder(io.kubernetes.client.openapi.models.V1PodBuilder) V1Pod(io.kubernetes.client.openapi.models.V1Pod) V1VolumeMountBuilder(io.kubernetes.client.openapi.models.V1VolumeMountBuilder) V1PersistentVolumeClaimVolumeSourceBuilder(io.kubernetes.client.openapi.models.V1PersistentVolumeClaimVolumeSourceBuilder)

Example 3 with V1PodBuilder

use of io.kubernetes.client.openapi.models.V1PodBuilder in project java by kubernetes-client.

the class FluentExample method main.

public static void main(String[] args) throws IOException, ApiException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    CoreV1Api api = new CoreV1Api();
    V1Pod pod = new V1PodBuilder().withNewMetadata().withName("apod").endMetadata().withNewSpec().addNewContainer().withName("www").withImage("nginx").endContainer().endSpec().build();
    api.createNamespacedPod("default", pod, null, null, null, null);
    V1Pod pod2 = new V1Pod().metadata(new V1ObjectMeta().name("anotherpod")).spec(new V1PodSpec().containers(Arrays.asList(new V1Container().name("www").image("nginx"))));
    api.createNamespacedPod("default", pod2, null, null, null, null);
    V1PodList list = api.listNamespacedPod("default", null, null, null, null, null, null, null, null, null, null);
    for (V1Pod item : list.getItems()) {
        System.out.println(item.getMetadata().getName());
    }
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1PodBuilder(io.kubernetes.client.openapi.models.V1PodBuilder) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ApiClient(io.kubernetes.client.openapi.ApiClient) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) V1PodSpec(io.kubernetes.client.openapi.models.V1PodSpec)

Aggregations

V1Pod (io.kubernetes.client.openapi.models.V1Pod)3 V1PodBuilder (io.kubernetes.client.openapi.models.V1PodBuilder)3 ApiClient (io.kubernetes.client.openapi.ApiClient)2 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)2 IntOrString (io.kubernetes.client.custom.IntOrString)1 V1Container (io.kubernetes.client.openapi.models.V1Container)1 V1DeleteOptions (io.kubernetes.client.openapi.models.V1DeleteOptions)1 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)1 V1PersistentVolumeClaimVolumeSourceBuilder (io.kubernetes.client.openapi.models.V1PersistentVolumeClaimVolumeSourceBuilder)1 V1PodList (io.kubernetes.client.openapi.models.V1PodList)1 V1PodSpec (io.kubernetes.client.openapi.models.V1PodSpec)1 V1SecretVolumeSourceBuilder (io.kubernetes.client.openapi.models.V1SecretVolumeSourceBuilder)1 V1Service (io.kubernetes.client.openapi.models.V1Service)1 V1ServiceBuilder (io.kubernetes.client.openapi.models.V1ServiceBuilder)1 V1VolumeBuilder (io.kubernetes.client.openapi.models.V1VolumeBuilder)1 V1VolumeMountBuilder (io.kubernetes.client.openapi.models.V1VolumeMountBuilder)1 File (java.io.File)1