我有一个使用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网址连接到http://testapi:3001,显然无效。知道如何将它连接到支持的API吗?
答案 0 :(得分:0)
您只能在同一个kubernetes集群内的任何其他部署中使用该服务名称。如果要从前端调用它,则必须公开外部公共可访问端点。