Kubernetes tries to start Rails twice on the same pod
Kubernetes tries to start Rails twice on the same pod
I'm trying to get my dokerized Rails app to run on Kubernetes hosted at GCP.
kubectl apply -f k8s/webshop.yml
kubectl get pods
NAME READY STATUS RESTARTS AGE
shop-lcvxc 2/3 CrashLoopBackOff 23 1h
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?
Logs
$ kubectl logs shop-lcvxc -c webshop
=> 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 logs 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"]
1 Answer
1
Containers share the port / network within a pod. So you can't have two processes listening on the same port.
Quite strangely your deployment yaml only specifies the app
container however you used the shop
container as well in your question?
app
shop
image: hub.docker.com/my-webshop:latest
My pod is supposed to specify one dockerized Rails app, but following this example [1] is looks like they are using both "app" and "myapp". [1] github.com/GoogleCloudPlatform/kubernetes-engine-samples/blob/…
– martins
1 min ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Yes, but I only want 1 container running on port 3000. And that is
image: hub.docker.com/my-webshop:latest
– martins
7 mins ago