amazon-web-services - AWS EKS:服务(LoadBalancer)正在运行但未响应请求
问题描述
我正在使用 AWS EKS。我在 kubernetes 集群中的 gunicorn 的帮助下启动了我的 django 应用程序。
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: api
labels:
app: api
type: web
spec:
replicas: 1
template:
metadata:
labels:
app: api
type: web
spec:
containers:
- name: vogofleet
image: xx.xx.com/api:image2
imagePullPolicy: Always
env:
- name: DATABASE_HOST
value: "test-db-2.xx.xx.xx.xx.com"
- name: DATABASE_PASSWORD
value: "xxxyyyxxx"
- name: DATABASE_USER
value: "admin"
- name: DATABASE_PORT
value: "5432"
- name: DATABASE_NAME
value: "test"
ports:
- containerPort: 9000
我已经应用了这些更改,我可以看到我的 pod 正在运行kubectl get pods
现在,我试图通过服务对象公开它。这是我的服务对象,
# service
---
apiVersion: v1
kind: Service
metadata:
name: api
labels:
app: api
spec:
ports:
- port: 9000
protocol: TCP
targetPort: 9000
selector:
app: api
type: web
type: LoadBalancer
该服务也已启动并运行。它为我提供了访问服务的外部 IP,即负载均衡器的地址。我可以看到它在 AWS 控制台中启动了一个新的负载均衡器。但我无法从浏览器访问它。它说地址没有返回任何数据。ELB 将实例上的运行状况检查显示为 OutOfService。
集群中还有其他 Pod 正在运行。当我printenv
在这些 pod 中运行时,结果如下,
root@consumer-9444cf7cd-4dr5z:/consumer# printenv | grep API
API_PORT_9000_TCP_ADDR=172.20.140.213
API_SERVICE_HOST=172.20.140.213
API_PORT_9000_TCP_PORT=9000
API_PORT=tcp://172.20.140.213:9000
API_PORT_9000_TCP=tcp://172.20.140.213:9000
API_PORT_9000_TCP_PROTO=tcp
API_SERVICE_PORT=9000
我试图检查与我的 api pod 的连接,
root@consumer-9444cf7cd-4dr5z:/consumer# telnet $API_PORT_9000_TCP_ADDR $API_PORT_9000_TCP_PORT
Trying 172.20.140.213...
telnet: Unable to connect to remote host: Connection refused
但是,当我将端口转发到我的本地主机时,我可以在我的本地主机上访问它,
$ kubectl port-forward api-6d94dcb65d-br6px 9000
并检查连接,
$ nc -vz localhost 9000
found 0 associations
found 1 connections:
1: flags=82<CONNECTED,PREFERRED>
outif lo0
src ::1 port 53299
dst ::1 port 9000
rank info not available
TCP aux info available
Connection to localhost port 9000 [tcp/cslistener] succeeded!
为什么我无法从其他容器和公共互联网访问它?而且,安全组是正确的。
解决方案
我也有同样的问题。这是 kubectl describe service 命令的 o/p。
kubectl describe services nginx-elb
Name: nginx-elb
Namespace: default
Labels: deploy=slido
Annotations: service.beta.kubernetes.io/aws-load-balancer-internal: true
Selector: deploy=slido
Type: LoadBalancer
IP: 10.100.29.66
LoadBalancer Ingress: internal-a2d259057e6f94965bfc1f08cf86d4ce-884461987.us-west-2.elb.amazonaws.com
Port: http 80/TCP
TargetPort: 3000/TCP
NodePort: http 32582/TCP
Endpoints: 192.168.60.119:3000
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 119s service-controller Ensuring load balancer
Normal EnsuredLoadBalancer 117s service-controller Ensured load balancer
推荐阅读
- angular - services - 如何只处理一次 import {environment}?
- mysql - 将 MySQL 数据显示到 HTML div - Node.js
- javascript - 绕过有声视频的 chrome 自动暂停?
- haskell - 访问数据类型的属性
- r - ggplot 按值排序构面标签
- java - Java中Heridity的正确用法和私有属性问题?
- javascript - c3图表:数据来自url时出错
- arrays - 从 Json Angular 5 推入数组
- python - 如何计算条目之间的时间差?
- swift - 如何在 swift 中为服务器登录创建正确的完成处理程序?