因此,我编写了一个在path /api/v1/books
上侦听并作为部署部署在我的k8s集群上的应用程序接口,创建了服务(restapi-service
),以便我们可以从另一个pods调用该服务。现在我创建了另一个部署(restapi-ui-deployment
),它只有一个.html
页面,并且它被部署在nginx上,它最终调用我们之前创建的服务来获得响应。现在,问题是当我执行restapi-ui-deployment
的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.")
}
}
发布于 2019-08-05 00:45:20
我担心您对应用程序的工作方式感到困惑。XmlHttpRequest源自not浏览器,因此不在kubernetes集群之外,而不是来自集群内的nginx。(nginx提供html页面) kubernetes dns在kubernetes之外不可用,从外部到ClusterIP的连接也不起作用。解决方案:创建一个合适的Ingress并从你的前端调用它,或者在你的nginx上提供一个代理,在那里你得到了前端交付。(这将导致真正获得请求来源作为您的nginx)
https://stackoverflow.com/questions/57348029
复制相似问题