-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSimpleDeploymentCreate.java
36 lines (32 loc) · 1.36 KB
/
SimpleDeploymentCreate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package io.fabric8;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import java.util.Collections;
public class SimpleDeploymentCreate {
public static void main(String[] args) {
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
Deployment deployment = new DeploymentBuilder()
.withNewMetadata().withName("nginx-deployment").addToLabels("app", "nginx").endMetadata()
.withNewSpec()
.withReplicas(3)
.withNewSelector()
.withMatchLabels(Collections.singletonMap("app", "nginx"))
.endSelector()
.withNewTemplate()
.withNewMetadata().addToLabels("app", "nginx").endMetadata()
.withNewSpec()
.addNewContainer()
.withName("nginx")
.withImage("nginx:1.7.9")
.addNewPort().withContainerPort(80).endPort()
.endContainer()
.endSpec()
.endTemplate()
.endSpec()
.build();
client.apps().deployments().inNamespace("default").resource(deployment).create();
}
}
}