使用的k8s client包:java
<dependency> <groupId>io.fabric8</groupId> <artifactId>kubernetes-client</artifactId> <version>2.6.1</version> <exclusions> <exclusion> <artifactId>slf4j-api</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.fabric8</groupId> <artifactId>kubernetes-model</artifactId> <version>1.1.4</version> </dependency> <dependency> <groupId>io.fabric8</groupId> <artifactId>kubernetes-api</artifactId> <version>2.3.5</version> <exclusions> <exclusion> <artifactId>slf4j-api</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency>
使用方式k8sApiUrl为k8s apiserver地址:api
Config config = new ConfigBuilder().withMasterUrl(k8sApiUrl).build(); DefaultKubernetesClient kubernetesClient = new DefaultKubernetesClient(config);
而后能够经过kubernetesClent进行RC建立、删除、scale;service建立删除等等操做,另外就是传入执行命令:ui
// 建立RC kubernetesClient.replicationControllers().inNamespace(namespace).createOrReplace(rc); //扩缩容 kubernetesClient.replicationControllers().inNamespace(namespace).withName( rcName).scale(replicas); // POD执行命令 kubernetesClient.pods().withName(podName).exec("command1","command2"); 更多方法自行挖掘,好比RC、POD、Endpoints 监听......