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);
}
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));
}
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;
}
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;
}
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();
}
Aggregations