【问题标题】:Kubernetes Load balancer server connection refused:Default 80 port is workingKubernetes 负载均衡器服务器连接被拒绝:默认 80 端口正在工作
【发布时间】:2019-03-31 01:04:49
【问题描述】:
【问题讨论】:
标签:
kubernetes
google-cloud-platform
google-kubernetes-engine
spring-cloud-gcp
【解决方案1】:
这很可能是您的 Kubernetes 服务和/或部署的问题。 GKE 将自动配置映射到Service 资源的端口所需的防火墙规则。
确保您已在您的Service 上公开了port 80,并将其映射到您的Deployment 的Pods 上的一个有效端口
这里是一个使用Deployment 和Service 暴露一个nginx pod的例子:
部署.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
service.yaml:
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- name: http
port: 80
targetPort: 80
要查看正在映射的 IP 地址(和端口),您可以运行:
kubectl get services 和 kubectl describe pod <your pod name>`
如果您仍有问题,请提供上述两个kubectl 命令的输出。
祝你好运!