Kubernetes负载平衡器服务器连接被拒绝:默认80端口正在工作

时间:2018-10-26 09:41:32

标签: kubernetes google-cloud-platform google-kubernetes-engine spring-cloud-gcp

部署Spring微服务后,Kubernetes中的负载均衡器未连接到Google Cloud Platform中提到的端口。

我们需要更改任何防火墙设置以连接到已部署的服务吗?

enter image description here

1 个答案:

答案 0 :(得分:0)

这很可能是您的Kubernetes服务和/或部署存在的问题。 GKE将自动为映射到Service资源的端口提供所需的防火墙规则。

确保已将port 80上的Service公开,并将其映射到Deployment的{​​{1}}上的有效端口上

以下是使用PodsDeployment来公开Nginx容器的示例:

deployment.yaml: Service

service.yaml: apiVersion: apps/v1 # API Version of this Object kind: Deployment # This Object Type metadata: # Allows you to specify custom metadata name: nginx # Specifies the name of this object spec: # The official specification matching object type schema selector: # Label selector for pods matchLabels: # Must match these label(s) app: nginx # Custom label with value template: # Template describes the pods that are created metadata: # Standard objects metadata labels: # Labels used to group/categorize objects app: nginx # The name of this template spec: # Specification of the desired behaviour of this pod containers: # List of containers belonging to this pod (cannot be changed/updated) - name: nginx # Name of this container image: nginx # Docker image used for this container ports: # Port mapping(s) - containerPort: 80 # Number of port to expose on this pods ip

要查看正在映射的IP地址(和端口),可以运行: apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: type: LoadBalancer selector: app: nginx ports: - name: http port: 80 targetPort: 80 kubectl get services>`

如果仍然有问题,请提供上面两个kubectl describe pod <your pod name命令的输出。

祝你好运!