使用docker-compose.yaml给出Spring Boot应用程序:
version: '3'
services:
my-ws:
build: .
image: my-ws
container_name: my-ws
ports:
- "8080:8080"
和kubernetes体现:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: my-ws
spec:
replicas: 3
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
app: my-ws
spec:
containers:
- name: my-ws
image: myacr.azurecr.io/my-ws:v1
ports:
- containerPort: 8080
resources:
requests:
cpu: 250m
limits:
cpu: 500m
---
apiVersion: v1
kind: Service
metadata:
name: my-ws
spec:
loadBalancerIP: <redacted>
type: LoadBalancer
ports:
- port: 8080
selector:
app: my-ws
我们可以在Azure Kubernetes Service上成功部署,并且应用程序在端口8080上响应。我们希望它在端口80上响应。我们尝试将docker-compose.yaml端口更改为:
ports:
- 80:80
和清单:
- containerPort: 80
...
-port: 80
并重新部署。部署成功,但是该应用程序在8080或80上均不可用。
答案 0 :(得分:2)
您需要将服务端口80映射到容器端口8080,这是最简单的解决方案(破坏性最小):
---
apiVersion: v1
kind: Service
metadata:
name: my-ws
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: my-ws
ps。将其他所有内容保留在更改之前