我使用Java Kubernetes Client API在集群中创建一个pod
@PostMapping(value = "/pod/add")
public V1Pod deployPod() throws IOException, ApiException{
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api();
V1ObjectMeta meta = new V1ObjectMeta();
meta.name("ms2-pod");
Map<String, String> labels = new HashMap<>();
labels.put("app", "ms2-pod");
meta.labels(labels);
V1ContainerPort port = new V1ContainerPort();
port.containerPort(9090);
V1Container container = new V1Container();
container.name("ms2-container");
container.image("ms2");
container.imagePullPolicy("IfNotPresent");
container.ports(Arrays.asList(port));
V1PodSpec spec = new V1PodSpec();
spec.containers(Arrays.asList(container));
V1Pod podBody = new V1Pod();
podBody.apiVersion("v1");
podBody.kind("Pod");
podBody.metadata(meta);
podBody.spec(spec);
V1Pod pod = api.createNamespacedPod("default", podBody, null, null, null);
return pod;
}
所以在运行docker容器并调用EndPoint [url = / pod / add]
时出现错误java.net.ConnectException:无法连接到localhost / 127.0.0.1:8080“
注意:我可以正常使用其他不使用API的端点