【问题标题】:connecting backend API address连接后端API地址
【发布时间】:2017-11-20 12:00:49
【问题描述】:

我有一个使用 Vuejs 编写的前端单页应用程序,我使用 axios 调用后端 API。我正在尝试使用 kubernetes 来运行服务:

我的部署和服务 yml 文件:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: testapi
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: testapi
    spec:
      containers:
      - name: testapi
        image: testregistry.azurecr.io/testapi:latest
        ports:
        - containerPort: 3001
---
apiVersion: v1
kind: Service
metadata:
  name: testapi
spec:
  type: LoadBalancer
  ports:
  - port: 3001
  selector:
    app: testapi
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: testportal
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: testportal
    spec:
      containers:
      - name: testportal
        image: testregistry.azurecr.io/testportal
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: testportal
spec:
  type: LoadBalancer
  ports:
  - port: 8080
  selector:
    app: testportal

前端在客户端浏览器上运行。我的 axios url 连接到http://testapi:3001,这显然不起作用。知道如何将其连接到支持的 API 吗?

【问题讨论】:

    标签: docker kubernetes


    【解决方案1】:

    您只能在同一 kubernetes 集群内的任何其他部署中使用该服务名称。如果您想从前端调用它,则必须公开一个外部公共可访问端点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      • 1970-01-01
      • 2012-12-26
      • 1970-01-01
      • 1970-01-01
      • 2017-07-24
      相关资源
      最近更新 更多