|
|
@@ -1,5 +1,8 @@
|
|
|
package cn.seecoder.paas.util;
|
|
|
|
|
|
+import io.fabric8.kubernetes.api.model.metrics.v1beta1.NodeMetricsList;
|
|
|
+import io.fabric8.kubernetes.client.ConfigBuilder;
|
|
|
+import io.fabric8.kubernetes.client.DefaultKubernetesClient;
|
|
|
import io.kubernetes.client.Exec;
|
|
|
import io.kubernetes.client.openapi.ApiClient;
|
|
|
import io.kubernetes.client.openapi.apis.AppsV1Api;
|
|
|
@@ -35,6 +38,8 @@ public class K8sApiConfiguration {
|
|
|
|
|
|
private final AppsV1Api watchAppsV1Api;
|
|
|
|
|
|
+ private DefaultKubernetesClient fabricK8sClient;
|
|
|
+
|
|
|
@Autowired
|
|
|
public K8sApiConfiguration(ApplicationProperties applicationProperties) {
|
|
|
ApplicationProperties.K8s k8s = applicationProperties.getK8s();
|
|
|
@@ -50,6 +55,19 @@ public class K8sApiConfiguration {
|
|
|
this.watchApiClient = Config.fromToken(k8s.getApiServer(), k8s.getToken(), k8s.isValidateSSL());
|
|
|
this.watchCoreV1Api = new CoreV1Api(watchApiClient);
|
|
|
this.watchAppsV1Api = new AppsV1Api(watchApiClient);
|
|
|
+
|
|
|
+ // fabric client
|
|
|
+ io.fabric8.kubernetes.client.Config config = new ConfigBuilder().withMasterUrl(k8s.getApiServer()).withOauthToken(k8s.getToken()).withTrustCerts(k8s.isValidateSSL()).build();
|
|
|
+ this.fabricK8sClient = new DefaultKubernetesClient(config);
|
|
|
+ NodeMetricsList nodeMetricList = this.fabricK8sClient.top().nodes().metrics();
|
|
|
+ nodeMetricList.getItems().forEach(item -> {
|
|
|
+ System.out.println(item.getUsage().toString());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public DefaultKubernetesClient fabricK8sClient() {
|
|
|
+ return this.fabricK8sClient;
|
|
|
}
|
|
|
|
|
|
@Bean
|