<p>I'm moving a PHP application into Kubernetes and running into a "Bad Gateway" after some actions are performed.</p>

<p>I'm thinking the error is from one of two things:</p>

<ul>
<li>The PHP program is sending a <code>GET</code> to <code>http://192.168.39.129/admin/a_merge_xls_db.php?tmp_tbl=_imp_companies_20200329_160813</code></li>
<li>Or from the upload itself</li>
</ul>

<p>I doubt it is the last one because this Excel file is only 14kb. </p>

<p>What is going on is the user has an Excel template to import new accounts. They go to the admin portal <code>/admin</code>, select to import, it parses the Excel file, and imports into Postgres. </p>

<p>Despite this error, the data is making its way into the database. After it successfully imports, a <code>GET</code> is sent to <code>a_merge_xls_db.php?tmp_tbl=_imp_companies_20200329_160813</code>. That is when the "Bad Gateway" comes up after like 7 seconds.</p>

<p>Seems like it might be an issue in my <code>ingress.yaml</code> for <code>ingress-nginx</code> abd handling the <code>?=_</code> or something. I've tried a few things, but still am not able to resolve the issue.</p>

<p>Here is what I have in the <code>ingress.yaml</code>:</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/add-base-url: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/proxy-body-size: 500mb
  name: ingress-service
  namespace: default
spec:
  rules:
    - http:
        paths:
          - path: /?(.*)
            backend:
              serviceName: client-cluster-ip-service-dev
              servicePort: 3000
          - path: /admin/?(.*)
            backend:
              serviceName: admin-cluster-ip-service-dev
              servicePort: 4000
          - path: /api/?(.*)
            backend:
              serviceName: api-cluster-ip-service-dev
              servicePort: 5000
</code></pre>

<p>Any suggestions?</p>

<p><strong>ADDITIONAL INFO 3/30/20</strong></p>

<p>I'm including the <code>Dockerfile.dev</code> and <code>admin.yaml</code> as I'm still having issues:</p>

<pre><code># Dockerfile.dev

FROM php:7.3-fpm
EXPOSE 4000
RUN apt-get update \ 
    &amp;&amp; apt-get install -y libpq-dev zlib1g-dev libzip-dev \
    &amp;&amp; docker-php-ext-install pgsql zip
COPY . /app
WORKDIR /app/src
CMD ["php", "-S", "0.0.0.0:4000"]
</code></pre>

<pre><code># admin.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: admin-deployment-dev
spec:
  replicas: 1
  selector:
    matchLabels:
      component: admin
  template:
    metadata:
      labels:
        component: admin
    spec:
      containers:
        - name: admin
          image: testappacr.azurecr.io/test-app-admin
          ports:
            - containerPort: 4000
          env:
            - name: PGUSER
              valueFrom:
                secretKeyRef:
                  name: test-app-dev-secrets
                  key: PGUSER
            - name: PGHOST
              value: postgres-cluster-ip-service-dev
            - name: PGPORT
              value: "1423"
            - name: PGDATABASE
              valueFrom:
                secretKeyRef:
                  name: test-app-dev-secrets
                  key: PGDATABASE
            - name: PGPASSWORD
              valueFrom:
                secretKeyRef:
                  name: test-app-dev-secrets
                  key: PGPASSWORD
            - name: SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: test-app-dev-secrets
                  key: SECRET_KEY
            - name: SENDGRID_API_KEY
              valueFrom:
                secretKeyRef:
                  name: test-app-dev-secrets
                  key: SENDGRID_API_KEY
            - name: DOMAIN
              valueFrom:
                secretKeyRef:
                  name: test-app-dev-secrets
                  key: DOMAIN           
            - name: DEBUG
              valueFrom:
                secretKeyRef:
                  name: test-app-dev-secrets
                  key: DEBUG
          volumeMounts:
          - mountPath: "/docs/"
            name: file-storage
      volumes:
        - name: file-storage
          persistentVolumeClaim:
            claimName: file-storage
---
apiVersion: v1
kind: Service
metadata:
  name: admin-cluster-ip-service-dev
spec:
  type: ClusterIP
  selector:
    component: admin
  ports:
    - port: 4000
      targetPort: 4000
</code></pre>

<p>If I just have the <code>- path: /admin</code>, I have an issue where the assets are not being served. The <code>.css</code> and <code>.js</code> come back as with <code>200</code>, but nothing is applied to the application. If I navigate to the URL of the asset, for example, <code>http://192.168.39.129/admin/css/portal.css</code> it just shows the page you get when you go to <code>/admin</code>.</p>

<p>This issue is resolved by changing back to <code>- path: /admin/?(.*)</code>, but then I run into the issue I initially posted about.</p>

<p>I've been playing with various regex most of the morning, but still get the same results when it comes to the "Bad Domain".</p>

<p>I'm likely overlooking something given I'm learning Kubernetes. It really seems like it should be working given coderanger's suggestion and also this issue which echos the same thing:</p>

<p><a href="https://github.com/kubernetes/ingress-nginx/issues/3380" rel="nofollow noreferrer">https://github.com/kubernetes/ingress-nginx/issues/3380</a></p>

cjones
<p>You need to specify the <code>nginx.ingress.kubernetes.io/use-regex: "true"</code> annotation. This is called out because by default Kubernetes Ingress objects expect plain prefix matching, not regexs. Or in your case, just use an actual prefix, <code>/</code>, <code>/admin</code>, and <code>/api</code>.</p>
