【发布时间】:2021-10-18 04:55:18
【问题描述】:
我有一个 node.js Web 应用程序的两个 docker 容器
- 后端服务器
- 前端,取决于后端 我尝试使用 azure kubernetes 服务托管容器,但无法将它们连接到网络。
需要后端连接的前端Envionment.Prod.ts文件:
export const environment = {
production: true,
domainURL: window.location.host,
interfaceURL: 'http://52.224.xx.xx:3000/api/',
assetURL: 'assets',
name: 'prod'
};
如您所见,我的服务器在 http://localhost_or_public_ip:3000/api/ 上侦听 并且前端容器需要连接到服务器。
使用 AKS,在运行时分配部署后集群中的公共 ip,如何将此服务器 ip 配置到我的前端以使其侦听特定 ip 和端口?
- 有没有办法在 kubernetes 中使用 localhost:port?
- 如果没有,您能否建议一种方法来部署适合生产环境的应用程序?
注意:多容器部署在 localhost docker 环境和 azure 容器实例上运行良好
在 windows 上使用 docker 桌面
我已经为这个问题苦苦挣扎了一段时间,如果有人可以指导我解决问题,那将会很有帮助! 感谢您的意见
Deployment.yaml 文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: cspback
spec:
replicas: 1
selector:
matchLabels:
app: cspback
template:
metadata:
labels:
app: cspback
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: cspback
image: [azure_registry].azurecr.io/backend:latest
env:
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: cspback
spec:
ports:
- port: 3000
selector:
app: cspback
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: cspfront
spec:
replicas: 1
selector:
matchLabels:
app: cspfront
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
app: cspfront
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: cspfront
image: [azure_registry].azurecr.io/frontend:v1
ports:
- containerPort: 86
resources:
requests:
cpu: 250m
limits:
cpu: 500m
imagePullSecrets:
- name: secretupdate
---
apiVersion: v1
kind: Service
metadata:
name: cspfront
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: cspfront
【问题讨论】:
标签: node.js docker kubernetes azure-aks