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

时间:2015-12-23 20:00:45

标签: amazon-web-services docker sinatra kubernetes coreos

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

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

我已经激活了注册表插件,我已将其正确代理到我的本地盒子,因此我可以将图像推送到localhost:5000上的群集。我还在每个节点上正确加载了代理pod,以便localhost:5000也可以从该注册表中提取图像。

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

然后我将一个相当简单的Sinatra应用程序停靠在我的集群上运行并将其推送到注册表。我还准备了一个ReplicationController定义和服务定义来运行应用程序。拉出并启动图像没问题,我可以使用kubectl从属于复制组的每个pod获取启动日志。

我的问题是当我curl我的服务的公共ELB端点时,它就会挂起。

我尝试的事情:

  • 我获得了运行我的pod的其中一个节点的公共IP,并试图在服务描述中描述的NodePort上curl,同样的事情。
  • 我通过SSH连接到该节点并尝试curl localhost:3000,结果相同。
  • 同时SSH进入该节点,我尝试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将启动Puma服务器侦听端口3000。

我的复制组定义如下:

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的输出:

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 

1 个答案:

答案 0 :(得分:0)

我的Kubernetes设置没有任何问题。事实证明,该应用程序无法启动,因为由于某些无关的网络问题导致与数据库的连接超时。

对于任何好奇的人:不要在10.x.x.x IP范围内(例如RDS,Elasticache等)启动Kubernetes以外的任何内容。长话短说,Kubernetes目前有一个硬编码的IPTables伪装规则,它会扰乱与该范围内任何不属于集群的任何事物的通信。查看详细信息here

我最终做的是在不同的IP范围内为我的数据存储创建一个单独的VPC,并与我的Kubernetes VPC对等。

相关问题