python - 如何在vue js中获取kubernetes/minikube env变量

标签 python vue.js kubernetes minikube

我在 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/

相关文章:

python - 在网站中嵌入简单的交互式数据可视化(Bokeh?其他平台?)

python - 如何部署 Django 1.6、Python 3.3 和 Apache?

typescript - 使用 Vue 类组件、Vuex 类时出现 ESLint 错误

kubernetes - 由于 Istio VirtualService,有没有办法代理对 ExternalName 服务的调用?

kubernetes - 来自带有 microk8s 的主机的简单入口?

amazon-web-services - 为特定路径设置 Ingress-Nginx 速率限制 rps

python - 如何将 Python 程序的标准输出移至文件?

python - 调试监视器输出读数

javascript - 无法在.env文件中指定url vue cli 3

javascript - 单击背景时防止模态关闭[Vuejs]