<p>I'm trying to get my dokerized Rails app to run on Kubernetes hosted at GCP.</p>
<pre><code>kubectl apply -f k8s/webshop.yml
kubectl get pods
NAME                      READY     STATUS             RESTARTS   AGE
shop-lcvxc   2/3       CrashLoopBackOff   23         1h
</code></pre>
<p>So far so good, but the app will not start. Investigating further reveals that it has tried to start Rails (Puma) twice.
Any idea why this happens?</p>
<h1>Logs</h1>
<p><strong>$ kubectl logs shop-lcvxc  -c webshop</strong></p>
<pre><code>=&gt; Booting Puma
=&gt; Rails 5.2.0 application starting in development
=&gt; 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 &quot;0.0.0.0&quot; port 3001 (Errno::EADDRINUSE)
</code></pre>
<p><strong>$ kubectl logs shop-lcvxc  -c app</strong></p>
<pre><code>=&gt; Booting Puma
=&gt; Rails 5.2.0 application starting in development
=&gt; 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
</code></pre>
<p><strong>k8s/webshop.yml</strong></p>
<pre><code>  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: [&quot;/cloud_sql_proxy&quot;,
 44                     &quot;-instances=company:europe-west1:staging=tcp:5432&quot;,
 45                     &quot;-credential_file=/secrets/cloudsql/credentials.json&quot;]
 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
</code></pre>
<h1>Dockerfile</h1>
<pre><code>FROM XX.dkr.ecr.eu-west-1.amazonaws.com/webshop-bundled:1.3

COPY Gemfile* /app/
COPY . /app/

WORKDIR /app

CMD [&quot;/usr/local/bundle/bin/rails&quot;, &quot;s&quot;, &quot;-b&quot;, &quot;0.0.0.0&quot;, &quot;-p&quot;, &quot;3001&quot;]
</code></pre>
<p>^ That image is from this image:</p>
<p><strong>Dockerfile-bundled</strong></p>
<pre><code>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
</code></pre>
<p><em>✗ kubectl describe pod shop-lcvxc</em></p>
<pre><code>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:  &lt;none&gt;
    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:  &lt;none&gt;
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 &quot;default-token-bs796&quot;
  Normal  Pulling                10m   kubelet, gke-my-fam-default-pool-12d29bdf-c9t0  pulling image &quot;eu.gcr.io/acme-my-fam/webapp:latest&quot;
  Normal  Pulled                 10m   kubelet, gke-my-fam-default-pool-12d29bdf-c9t0  Successfully pulled image &quot;eu.gcr.io/acme-my-fam/webapp:latest&quot;
  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
</code></pre>

martins
<p>Containers share the port / network within a pod. So you can't have two processes listening on the same port.</p>

<p>Quite strangely your deployment yaml only specifies the <code>app</code> container however you used the <code>shop</code> container as well in your question?</p>
