<p>I try to setup a Rails app within a Kubernetes Cluster (which is created with k3d on my local machine.</p>
<p><code>k3d cluster create --api-port 6550 -p &quot;8081:80@loadbalancer&quot; --agents 2</code></p>
<p><code>kubectl create deployment nginx --image=nginx</code></p>
<p><code>kubectl create service clusterip nginx --tcp=80:80</code></p>
<pre><code># apiVersion: networking.k8s.io/v1beta1 # for k3s &lt; v1.19
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx
  annotations:
    ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              number: 80
</code></pre>
<p><strong>I can get an Ingress running which correctly exposes a running Nginx Deployment (&quot;Welcome to nginx!&quot;)</strong>
(I took this example from here: <a href="https://k3d.io/usage/guides/exposing_services/" rel="nofollow noreferrer">https://k3d.io/usage/guides/exposing_services/</a></p>
<p>So I know my setup is working (with nginx).</p>
<p>Now, I simpy wanna point that ingress to my Rails app, but I always get an &quot;Bad Gateway&quot;. (I also tried to point to my other services (elasticsearch, kibana, pgadminer) but I always get a &quot;Bad gateway&quot;.</p>
<p>I can see my Rails app running at (http://localhost:62333/)
last lines of my Dockerfile:</p>
<pre><code>EXPOSE 3001:3001
CMD rm -f tmp/pids/server.pid &amp;&amp; bundle exec rails s -b 0.0.0.0 -p 3001
</code></pre>
<p>Why is my API has the &quot;bad gateway&quot; but Nginx not?</p>
<p><strong>Does it have something to do with my selectors and labels which are created by kompose convert?</strong></p>
<p>This is my complete Rails-API Deployment:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl apply -f api-deployment.yml -f api.service.yml -f ingress.yml
</code></pre>
<p>api-deployment.yml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert -c --file metashop-backend/docker-compose.yml --file metashop-backend/docker-compose.override.yml
    kompose.version: 1.22.0 (HEAD)
  creationTimestamp: null
  labels:
    io.kompose.service: api
  name: api
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: api
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert -c --file metashop-backend/docker-compose.yml --file metashop-backend/docker-compose.override.yml
        kompose.version: 1.22.0 (HEAD)
      creationTimestamp: null
      labels:
        io.kompose.network/metashop-net: 'true'
        io.kompose.service: api
    spec:
      containers:
        - env:
            - name: APPLICATION_URL
              valueFrom:
                configMapKeyRef:
                  key: APPLICATION_URL
                  name: env
            - name: DEBUG
              value: 'true'
            - name: ELASTICSEARCH_URL
              valueFrom:
                configMapKeyRef:
                  key: ELASTICSEARCH_URL
                  name: env
          image: metashop-backend-api:DockerfileJeanKlaas
          name: api
          ports:
            - containerPort: 3001
          resources: {}
      #     volumeMounts:
      #       - mountPath: /usr/src/app
      #         name: api-claim0
      # restartPolicy: Always
      # volumes:
      #   - name: api-claim0
      #     persistentVolumeClaim:
      #       claimName: api-claim0
status: {}
</code></pre>
<p>api-service.yml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert -c --file metashop-backend/docker-compose.yml --file metashop-backend/docker-compose.override.yml
    kompose.version: 1.22.0 (HEAD)
  creationTimestamp: null
  labels:
    app: api
    io.kompose.service: api
  name: api
spec:
  type: ClusterIP
  ports:
    - name: '3001'
      protocol: TCP
      port: 3001
      targetPort: 3001
  selector:
    io.kompose.service: api
status:
  loadBalancer: {}
</code></pre>
<p>ingress.yml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: api
  annotations:
    ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: api
            port:
              number: 3001
</code></pre>
<p>configmap.yml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
data:
  APPLICATION_URL: localhost:3001
  ELASTICSEARCH_URL: elasticsearch
  RAILS_ENV: development
  RAILS_MAX_THREADS: '5'
kind: ConfigMap
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: api-env
  name: env

</code></pre>
<p>I hope I didn't miss anything.</p>
<p>thank you in advance</p>
<p>EDIT: added endpoint, requested in comment:</p>
<p>kind: endpoint</p>
<pre><code>kind: Endpoints
apiVersion: v1
metadata:
  name: api
  namespace: default
  labels:
    app: api
    io.kompose.service: api
  selfLink: /api/v1/namespaces/default/endpoints/api
subsets:
  - addresses:
      - ip: 10.42.1.105
        nodeName: k3d-metashop-cluster-server-0
        targetRef:
          kind: Pod
          namespace: default
          apiVersion: v1
    ports:
      - name: '3001'
        port: 3001
        protocol: TCP

</code></pre>

Jan
<p>The problem was within the Dockerfile:</p>
<p>I had not defined <code>ENV RAILS_LOG_TO_STDOUT true</code>, so I was not able to see any errors in the pod logs.</p>
<p>After I added <code>ENV RAILS_LOG_TO_STDOUT true</code> I saw errors like <code>database xxxx does not exist</code></p>
