You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
833 B

10 months ago
package Util;
import com.jfinal.kit.PathKit;
import io.kubernetes.client.openapi.models.V1Pod;
import io.kubernetes.client.openapi.models.V1PodList;
import java.io.File;
public class K8sClientTest {
public static void main(String[] args) {
//Master /root/.kube/config文件拷贝过来
String kubeConfigPath = PathKit.getRootClassPath()+ "\\.kube\\config";
if (!new File(kubeConfigPath).exists()) {
System.out.println("kubeConfig不存在跳过");
return;
}
K8sClient k8sClient = new K8sClient(kubeConfigPath);
V1PodList podList = k8sClient.getAllPodList();
for (V1Pod item : podList.getItems()) {
System.out.println(item.getMetadata().getNamespace() + ":" + item.getMetadata().getName());
}
}
}