Search in sources :

Example 1 with Deployment

use of com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment in project yakc by manusa.

the class WipIT method deployment.

@Test
void deployment() throws IOException {
    final AppsV1Api api = KC.create(AppsV1Api.class);
    final String deploymentName = "java-test";
    try {
        api.deleteNamespacedDeployment(deploymentName, "default").get();
        System.out.println("Deployment created");
    } catch (NotFoundException ex) {
        System.out.println("Deployment not found, deletion not needed");
    }
    final Deployment deployment = api.createNamespacedDeployment("default", Deployment.builder().metadata(ObjectMeta.builder().name(deploymentName).build()).spec(DeploymentSpec.builder().replicas(1).selector(LabelSelector.builder().putInMatchLabels("k8s-app", "test-java").build()).template(PodTemplateSpec.builder().metadata(ObjectMeta.builder().name("java-test-pod").putInLabels("k8s-app", "test-java").build()).spec(PodSpec.builder().addToContainers(Container.builder().image("containous/whoami").name("java-test-pod").build()).build()).build()).build()).build()).get();
    System.out.println(deployment);
    api.patchNamespacedDeployment(deploymentName, "default", Deployment.builder().spec(deployment.getSpec().toBuilder().replicas(2).build()).build()).get();
    final PodList selectedPodList = KC.create(CoreV1Api.class).listPodForAllNamespaces(new ListPodForAllNamespaces().labelSelector("k8s-app=test-pod")).get();
    System.out.println(selectedPodList);
}
Also used : PodList(com.marcnuri.yakc.model.io.k8s.api.core.v1.PodList) AppsV1Api(com.marcnuri.yakc.api.apps.v1.AppsV1Api) NotFoundException(com.marcnuri.yakc.api.NotFoundException) Deployment(com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment) ListPodForAllNamespaces(com.marcnuri.yakc.api.core.v1.CoreV1Api.ListPodForAllNamespaces) Test(org.junit.jupiter.api.Test)

Example 2 with Deployment

use of com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment in project yakc by manusa.

the class Deployments method createExample.

private void createExample(KubernetesClient kc) throws IOException {
    final String name = "yakc-example-" + new Random().nextInt(999999);
    final String applicableNamespace = namespace(kc);
    final String appName = "yakc-example-deployment";
    info("Creating example Deployment in " + applicableNamespace + " namespace:");
    final Deployment ss = kc.create(AppsV1Api.class).createNamespacedDeployment(applicableNamespace, Deployment.builder().metadata(ObjectMeta.builder().name(name).build()).spec(DeploymentSpec.builder().selector(LabelSelector.builder().putInMatchLabels("app", appName).build()).replicas(1).template(PodTemplateSpec.builder().metadata(ObjectMeta.builder().putInLabels("app", appName).build()).spec(PodSpec.builder().addToContainers(Container.builder().name(name).image("busybox").addToCommand("sh").addToCommand("-c").addToCommand("echo 'Hello YAKC!' && sleep 300").build()).addToContainers(Container.builder().name(name + "-2").image("busybox").addToCommand("sh").addToCommand("-c").addToCommand("echo 'Hello YAKC! from second container' && sleep 300").build()).build()).build()).build()).build()).get();
    info(" - Deployment " + applicableNamespace + "/" + name + " successfully created!");
    info(" - " + ss.getMetadata().getCreationTimestamp().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}
Also used : Random(java.util.Random) Deployment(com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment)

Example 3 with Deployment

use of com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment in project yakc by manusa.

the class Deployments method restart.

private int restart(KubernetesClient kc) throws IOException {
    if (params == null || params.length != 1) {
        error("Missing required param <name>");
        return 1;
    }
    final String name = params[0];
    final String applicableNamespace = namespace(kc);
    final Deployment toPatch = new Deployment();
    toPatch.setSpec(new DeploymentSpec());
    toPatch.getSpec().setTemplate(PodTemplateSpec.builder().metadata(ObjectMeta.builder().putInAnnotations("yakc.marcnuri.com/restartedAt", Instant.now().toString()).build()).build());
    kc.create(AppsV1Api.class).patchNamespacedDeployment(name, applicableNamespace, toPatch).get();
    return 0;
}
Also used : DeploymentSpec(com.marcnuri.yakc.model.io.k8s.api.apps.v1.DeploymentSpec) Deployment(com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment)

Example 4 with Deployment

use of com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment in project yakc by manusa.

the class DeploymentService method emptyDeployment.

private static Deployment emptyDeployment() {
    final Deployment ret = new Deployment();
    ret.setSpec(new DeploymentSpec());
    return ret;
}
Also used : DeploymentSpec(com.marcnuri.yakc.model.io.k8s.api.apps.v1.DeploymentSpec) Deployment(com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment)

Example 5 with Deployment

use of com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment in project yakc by manusa.

the class DeploymentService method restart.

public Deployment restart(String name, String namespace) throws IOException {
    final Deployment toPatch = emptyDeployment();
    toPatch.getSpec().setTemplate(PodTemplateSpec.builder().metadata(ObjectMeta.builder().putInAnnotations("yakc.marcnuri.com/restartedAt", Instant.now().toString()).build()).build());
    return kubernetesClient.create(AppsV1Api.class).patchNamespacedDeployment(name, namespace, toPatch).get();
}
Also used : Deployment(com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment)

Aggregations

Deployment (com.marcnuri.yakc.model.io.k8s.api.apps.v1.Deployment)7 DeploymentSpec (com.marcnuri.yakc.model.io.k8s.api.apps.v1.DeploymentSpec)2 Test (org.junit.jupiter.api.Test)2 NotFoundException (com.marcnuri.yakc.api.NotFoundException)1 AppsV1Api (com.marcnuri.yakc.api.apps.v1.AppsV1Api)1 ListPodForAllNamespaces (com.marcnuri.yakc.api.core.v1.CoreV1Api.ListPodForAllNamespaces)1 PodList (com.marcnuri.yakc.model.io.k8s.api.core.v1.PodList)1 Random (java.util.Random)1 DisplayName (org.junit.jupiter.api.DisplayName)1