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()); } } }