我在 minikube 中有一个 python 应用程序和 vue-js 应用程序。我尝试通过在 URL 中提及“python-app-service”来发布 python 应用服务,但 vue js 仍然将其应用为文字“python-app-service”而不是 IP 地址。
假设这是我的部署,名为 python-server
:
规范:
容器:
- 图像:python-服务器:最新
imagePullPolicy:IfNotPresent
名称: python-servier
端口:
- 容器端口:8001
名称:python-服务器
我的服务名为python-server-service
规范:
端口:
- 端口:8001
目标端口:8001
另一方面,我有类似的 vue js 部署和服务。
现在我想在 vue js 中向 python-server
执行 axios post 请求:
axios.post('python-server-service'+'/api/new/post',
this.name, // the data to post
{ headers: {
'Content-type': 'application/x-www-form-urlencoded',
}
}).then(response => ....);
而不是这个:
axios.post('http://127.0.0.1:3030/api/new/post',
this.name, // the data to post
{ headers: {
'Content-type': 'application/x-www-form-urlencoded',
}
}).then(response => ....);
但不幸的是,vueJS 不会解析我的 python-server-service
并将其作为文字字符串“python-server-service”。
如何在 minikube 中运行的 vuejs 中获取 python-app-service IP 地址?
谢谢。
最佳答案
最有意义的解决方案是使用 Kubernetes Service并将主机名与 Kubernetes DNS nomenclature 一起使用:<service-name>.<namespace>.svc.cluster.local:<exposed-port>
。由于两个 Pod 位于同一集群中,因此可以是 ClusterIP服务类型。
IP 地址的问题在于它们在 Kubernetes 集群(甚至是 minikube)中并未固定,但为了进行测试,您始终可以像这样获取 pod 的 IP 地址:
$ kubectl get pod <pod-name> -o=jsonpath='{.status.podIP}'
关于python - 如何在vue js中获取kubernetes/minikube env变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53224029/