【问题标题】:How to get kubernetes / minikube env variable in vue js如何在 vue js 中获取 kubernetes / minikube env 变量
【发布时间】:2019-04-12 22:09:16
【问题描述】:

我在 minikube 中有一个 python 应用和 vue-js 应用。我试图通过在 URL 中提及“python-app-service”来向 python 应用程序服务发帖,但是 vue js 仍然将其应用为文字“python-app-service”而不是 IP 地址。

假设这是我的部署,称为python-server spec: containers: - image: python-server:latest imagePullPolicy: IfNotPresent name: python-servier ports: - containerPort: 8001 name: python-server

我的服务叫python-server-service

spec: ports: - port: 8001 targetPort: 8001

另一方面,我为 vue js 提供了类似的 deploymet 和服务。

现在我想在 vue js 中向python-server 发送 axios 发布请求:

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 地址?

谢谢。

【问题讨论】:

    标签: python vue.js kubernetes minikube


    【解决方案1】:

    最有意义的解决方案是使用 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}'
    

    【讨论】:

    • 我已经做到了,但是 vuejs 或任何其他应用程序正在将其读取为文字字符串。例如 url="mypythonapp" 是红色的 mypythonapp 而不是将其解析为应用程序的 IP 地址
    • 你没有解释你对你的问题做了什么......你的部署对于你的 python 和 vue 来说是什么样的?
    猜你喜欢
    • 2019-05-05
    • 2020-10-18
    • 1970-01-01
    • 2020-05-13
    • 2018-10-24
    • 2019-09-12
    • 2020-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多