因此,我编写了一个 API 来监听路径/api/v1/books
,并作为部署部署在我的 k8s 集群上,创建了服务 ( restapi-service
),以便我们可以从另一个 pod 调用它。现在我创建了另一个restapi-ui-deployment
部署.html
(restapi-ui-deployment
现在,问题是当我执行到我能够成功 curl的 pod时http://restapi-service:8081/api/v1/books
。但是,如果我们试图从部署的 .html 页面做同样的事情,我会得到
GET http://restapi-service:8081/api/v1/books net::ERR_NAME_NOT_RESOLVED
下面是正在部署的代码restapi-ui-deployment
if (xmlObj != null){
xmlObj.open("GET", "http://restapi-service:8081/api/v1/books", true)
xmlObj.onreadystatechange = processResponse;
xmlObj.send(null)
}
else{
console.log("There was an error getting the object.")
}
function processResponse(){
if (xmlObj.status == 200 && xmlObj.readyState == 4){
console.log("Got the response successfully")
response = xmlObj.responseText
}
else{
console.log("There was an issue getting the response.")
}
}