繁体   English   中英

Kubernetes尝试在同一Pod上两次启动Rails

[英]Kubernetes tries to start Rails twice on the same pod

我正在尝试让我的dokerized Rails应用程序在GCP托管的Kubernetes上运行。

kubectl apply -f k8s/webshop.yml
kubectl get pods
NAME                      READY     STATUS             RESTARTS   AGE
shop-lcvxc   2/3       CrashLoopBackOff   23         1h

到目前为止一切顺利,但该应用程序无法启动。 调查进一步显示,该公司已尝试两次启动Rails(Puma)。 知道为什么会这样吗?

日志

$ kubectl日志商店-lcvxc -c网上商店

=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
initialize PushNotifications
Puma starting in single mode...
* Version 3.11.4 (ruby 2.4.4-p296), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3001
Exiting
/usr/local/bundle/gems/puma-3.11.4/lib/puma/binder.rb:270:in `initialize': 
Address already in use - bind(2) for "0.0.0.0" port 3001 (Errno::EADDRINUSE)

$ kubectl日志shop-lcvxc -c app

=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
initialize PushNotifications
Puma starting in single mode...
* Version 3.11.4 (ruby 2.4.4-p296), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3001
Use Ctrl-C to stop

K8S / webshop.yml

  1 # from https://cloud.google.com/sql/docs/postgres/connect-kubernetes-engine
  2 apiVersion: extensions/v1beta1
  3 kind: Deployment
  4 metadata:
  5   name: webshop
  6   labels:
  7     app: webshop
  8
  9 spec:
 10   template:
 11     metadata:
 12       labels:
 13         app: webshop
 14     spec:
 15       containers:
 16         - name: app
 17           image: eu.gcr.io/company/webshop:latest
 18           ports:
 19             - containerPort: 3000
 20           # The following environment variables will contain the database host,
 21           # user and password to connect to the PostgreSQL instance.
 22           env:
 23             - name: POSTGRES_HOST
 24               value: 127.0.0.1:5432
 25             - name: POSTGRES_DB
 26               value: webshop-staging
 27             # [START cloudsql_secrets]
 28             - name: POSTGRES_USER
 29               valueFrom:
 30                 secretKeyRef:
 31                   name: cloudsql-db-credentials
 32                   key: username
 33             - name: POSTGRES_PASSWORD
 34               valueFrom:
 35                 secretKeyRef:
 36                   name: cloudsql-db-credentials
 37                   key: password
 38             # [END cloudsql_secrets]
 39
 40         # [START proxy_container]
 41         - name: cloudsql-proxy
 42           image: gcr.io/cloudsql-docker/gce-proxy:1.11
 43           command: ["/cloud_sql_proxy",
 44                     "-instances=company:europe-west1:staging=tcp:5432",
 45                     "-credential_file=/secrets/cloudsql/credentials.json"]
 46           volumeMounts:
 47             - name: cloudsql-instance-credentials
 48               mountPath: /secrets/cloudsql
 49               readOnly: true
 50         # [END proxy_container]
 51       # [START volumes]
 52       volumes:
 53         - name: cloudsql-instance-credentials
 54           secret:
 55             secretName: cloudsql-instance-credentials
 56       # [END volumes]
 57

Dockerfile

FROM XX.dkr.ecr.eu-west-1.amazonaws.com/webshop-bundled:1.3

COPY Gemfile* /app/
COPY . /app/

WORKDIR /app

CMD ["/usr/local/bundle/bin/rails", "s", "-b", "0.0.0.0", "-p", "3001"]

^该图像来自此图像:

Dockerfile捆绑

FROM ruby:2.4-slim-jessie

RUN apt-get update
RUN apt-get install -y libpq-dev libgmp-dev libxml2-dev libxslt-dev
RUN apt-get install -y build-essential patch ruby-dev zlib1g-dev liblzma-dev

COPY Gemfile* /app/
WORKDIR /app
RUN bundle install

✗kubectl描述吊舱店-LCVXC

Name:           webapp-5845b768f7-tflbv
Namespace:      default
Node:           gke-my-fam-default-pool-12d29bdf-c9t0/10.166.0.3
Start Time:     Fri, 06 Jul 2018 08:18:16 +0200
Labels:         pod-template-hash=1401632493
                run=webapp
Annotations:    kubernetes.io/limit-ranger=LimitRanger plugin set: cpu request for container webapp
Status:         Running
IP:             10.4.0.6
Controlled By:  ReplicaSet/webapp-5845b768f7
Containers:
  webapp:
    Container ID:   docker://889fbc56fc28
    Image:          eu.gcr.io/acme-my-fam/webapp:latest
    Image ID:       docker-pullable://eu.gcr.io/acme-my-fam/webapp@sha256:nnnn
    Port:           8080/TCP
    State:          Running
      Started:      Fri, 06 Jul 2018 08:18:43 +0200
    Ready:          True
    Restart Count:  0
    Requests:
      cpu:        100m
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-bs796 (ro)
Conditions:
  Type           Status
  Initialized    True
  Ready          True
  PodScheduled   True
Volumes:
  default-token-bs796:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-bs796
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason                 Age   From                                                 Message
  ----    ------                 ----  ----                                                 -------
  Normal  Scheduled              10m   default-scheduler                                    Successfully assigned webapp-5845b768f7-tflbv to gke-my-fam-default-pool-12d29bdf-c9t0
  Normal  SuccessfulMountVolume  10m   kubelet, gke-my-fam-default-pool-12d29bdf-c9t0  MountVolume.SetUp succeeded for volume "default-token-bs796"
  Normal  Pulling                10m   kubelet, gke-my-fam-default-pool-12d29bdf-c9t0  pulling image "eu.gcr.io/acme-my-fam/webapp:latest"
  Normal  Pulled                 10m   kubelet, gke-my-fam-default-pool-12d29bdf-c9t0  Successfully pulled image "eu.gcr.io/acme-my-fam/webapp:latest"
  Normal  Created                10m   kubelet, gke-my-fam-default-pool-12d29bdf-c9t0  Created container
  Normal  Started                10m   kubelet, gke-my-fam-default-pool-12d29bdf-c9t0  Started container

容器共享Pod中的端口/网络。 因此,您不能有两个进程在同一个端口上进行侦听。

奇怪的是,您的部署yaml仅指定了app容器,但是您在问题中也使用了shop容器?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM