为什么我的pod不响应暴露端口上的请求?

我刚刚推出了一个基于CoreOS kube-aws脚本的相当基本的集群。

https://coreos.com/kubernetes/docs/latest/kubernetes-on-aws.html

我已经激活了registry加载项,并且正确地代理了我的本地框,因此我可以将图像推送到localhost:5000上的群集。 我也有正确加载在每个节点上的代理pod,以便localhost:5000也将从该registry中拉出图像。

https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/registry

然后,我将一个相当简单的Sinatra应用程序docker化到我的集群上运行,并将其推送到registry。 我还准备了一个ReplicationController定义和服务定义来运行应用程序。 图像被拉下来并开始没有问题,我可以使用kubectl复制组的每个窗格获取启动日志。

我的问题是,当我curl的公共ELB端点为我的服务,它只是挂起。

我试过的东西:

  • 我得到了运行我的pod的其中一个节点的公共IP,并尝试在服务描述中描述的NodePort上进行压缩,同样的事情。
  • 我SSH'd到该节点,并试图curl localhost:3000 ,相同的结果。
  • 另外SSH'd到该节点,我试图curl <pod-ip>:3000 ,相同的结果。
  • ps显示Puma进程在3000端口上运行和监听。
  • 该节点上的docker ps显示应用程序容器未将任何端口转发到主机。 这也许是问题吗?

这些请求必须正确路由,因为在任何其他端口上触发这些IP都会导致connection refused而不是挂起。

我的应用程序的Dockerfile非常简单:

 FROM ruby:2.2.4-onbuild RUN apt-get update -qq && apt-get install -y \ libpq-dev \ postgresql-client RUN mkdir -p /app WORKDIR /app COPY . /app EXPOSE 3000 ENTRYPOINT ['ruby', '/app/bin/entrypoint.rb'] 

其中entrypoint.rb将启动一个在端口3000上侦听的Puma服务器。

我的复制组是这样定义的:

 apiVersion: v1 kind: ReplicationController metadata: name: web-controller namespace: app spec: replicas: 2 selector: app: web template: metadata: labels: app: web spec: volumes: - name: secrets secret: secretName: secrets containers: - name: app image: localhost:5000/app:v2 resources: limits: cpu: 100m memory: 50Mi env: - name: DATABASE_NAME value: app_production - name: DATABASE_URL value: postgresql://some.postgres.aws.com:5432 - name: ENV value: production - name: REDIS_URL value: redis://some.redis.aws.com:6379 volumeMounts: - name: secrets mountPath: "/etc/secrets" readOnly: true command: ['/app/bin/entrypoint.rb', 'web'] ports: - containerPort: 3000 

这是我的服务:

 apiVersion: v1 kind: Service metadata: name: web-service spec: ports: - port: 80 targetPort: 3000 protocol: TCP selector: app: web type: LoadBalancer 

kubectl describe service web-service输出kubectl describe service web-service

 Name: web-service Namespace: app Labels: <none> Selector: app=web Type: LoadBalancer IP: 10.3.0.204 LoadBalancer Ingress: some.elb.aws.com Port: <unnamed> 80/TCP NodePort: <unnamed> 32062/TCP Endpoints: 10.2.47.3:3000,10.2.73.3:3000 Session Affinity: None No events. 

其中一个节点上的docker ps显示应用程序容器未将任何端口转发给主机。 这也许是问题吗?

编辑添加entrypoint.rb和Procfile

entrypoint.rb:

 #!/usr/bin/env ruby db_user_file = '/etc/secrets/database_user' db_password_file = '/etc/secrets/database_password' ENV['DATABASE_USER'] = File.read(db_user_file) if File.exists?(db_user_file) ENV['DATABASE_PASSWORD'] = File.read(db_password_file) if File.exists?(db_password_file) exec("bundle exec foreman start #{ARGV[0]}") 

Procfile:

 web: PORT=3000 bundle exec puma message_worker: bundle exec sidekiq -q messages -c 1 -r ./config/environment.rb email_worker: bundle exec sidekiq -q emails -c 1 -r 

我的Kubernetes成立没有错。 事实certificate,该应用程序无法启动,因为连接到数据库是由于一些无关的networking问题超时。

对于任何好奇的人:不要在10.xxx IP范围内启动Kubernetes外部的任何东西(例如RDS,Elasticache等)。 长话短说,Kubernetes目前拥有一个硬编码的IPTables伪装规则,该规则混淆了与该范围内不属于群集的任何事物的通信。 在这里看到细节。

我最终做的是为我的数据存储在不同的IP范围上创build一个独立的VPC,并使用我的Kubernetes VPC进行对等。