连接后端API地址

我有一个使用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 

前端正在客户端浏览器上运行。 我axiosurl连接到http:// testapi:3001 ,这显然不工作。 任何想法如何让它连接到支持的API?

您只能使用同一个kubernetes集群内的任何其他部署的服务名称。 如果你想从前端调用它,你将不得不暴露一个外部的公共可访问端点。