我正在使用Google Cloud中的以下部署文件部署nginx映像。
对于Replicationcontroller:
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx-web
labels:
name: nginx-web
app: demo
spec:
replicas: 2
template:
metadata:
labels:
name: nginx-web
spec:
containers:
- name: nginx-web
image: nginx
ports:
- containerPort: 5000
name: http
protocol: TCP
用于服务部署
apiVersion: v1
kind: Service
metadata:
name: nginx-web
labels:
name: nginx-web
app: demo
spec:
selector:
name: nginx-web
type: LoadBalancer
ports:
- port: 84
targetPort: 5000
protocol: TCP
但是当我在端口84上对external_IP(我从loadbalancer获得)进行卷曲时,我收到连接拒绝错误。可能是什么问题?
答案 0 :(得分:1)
您在复制控制器中使用的nginx映像正在侦听端口80(这就是构建映像的方式)。
您需要修复复制控制器规范,如下所示:
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx-web
labels:
name: nginx-web
app: demo
spec:
replicas: 2
template:
metadata:
labels:
name: nginx-web
spec:
containers:
- name: nginx-web
image: nginx
ports:
- containerPort: 80
name: http
protocol: TCP
并调整您的服务:
apiVersion: v1
kind: Service
metadata:
name: nginx-web
labels:
name: nginx-web
app: demo
spec:
selector:
name: nginx-web
type: LoadBalancer
ports:
- port: 84
targetPort: 80
protocol: TCP