protected static void createPod(Kubernetes kubernetes, KubernetesFactory kubernetesFactory) throws Exception { String name = "console2"; String image = "fabric8/hawtio"; Pod pod = new Pod(); pod.setId(name); Map<String, String> labels = new HashMap<>(); labels.put("fabric8", "true"); labels.put("container", name); pod.setLabels(labels); PodState desiredState = new PodState(); pod.setDesiredState(desiredState); ContainerManifest manifest = new ContainerManifest(); desiredState.setManifest(manifest); Container manifestContainer = new Container(); manifestContainer.setName(name); manifestContainer.setImage(image); List<Container> containers = new ArrayList<>(); containers.add(manifestContainer); manifest.setContainers(containers); System.out.println("About to create pod on " + kubernetesFactory.getAddress() + " with " + pod); kubernetes.createPod(pod, "mynamespace"); System.out.println("Created pod: " + name); System.out.println(); }
public static void main(String... args) { KubernetesFactory kubeFactory = new KubernetesFactory(true); if (args.length > 0) { kubeFactory.setAddress(args[0]); } System.out.println("Connecting to kubernetes on: " + kubeFactory.getAddress()); try { Kubernetes kube = kubeFactory.createKubernetes(); listPods(kube); listServices(kube); listReplicationControllers(kube); createPod(kube, kubeFactory); listPods(kube); } catch (Exception e) { System.out.println("FAILED: " + e); e.printStackTrace(); } }