<p>I'm missing some kubernetes ingress-nginx configuration here in order to run a php-fpm app on k8s in minikube.</p>

<p>The k8s configuration files:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: server-cluster-ip-service
              servicePort: 5000

---
apiVersion: v1
kind: Service
metadata:
  name: server-cluster-ip-service
spec:
  type: ClusterIP
  selector:
    component: server
  ports:
    - port: 5000
      targetPort: 5000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: server-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      component: server
  template:
    metadata:
      labels:
        component: server
    spec:
      containers:
        - name: server
          image: xxx/phpfpm
          ports:
            - containerPort: 5000
          env:
            - name: APP_ENV
              value: dev
            - name: APP_DEBUG
              value: '1'
            - name: APP_SECRET
              value: 74bd83726749616f29166ef53c5f0557
            - name: MYSQL_HOST
              value: mysql-cluster-ip-service
            - name: MYSQL_ROOT_PASSWORD
              value: root
            - name: MYSQL_DATABASE
              value: db
            - name: MYSQL_DATABASE_TEST
              value: test
            - name: MYSQL_USER
              value: user
            - name: MYSQL_PASSWORD
              value: secret
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-cluster-ip-service
spec:
  type: ClusterIP
  selector:
    component: mysql
  ports:
    - port: 3306
      targetPort: 3306
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: mysql
  template:
    metadata:
      labels:
        component: mysql
    spec:
      volumes:
        - name: mysql-storage
          persistentVolumeClaim:
            claimName: database-persistent-volume-claim
      containers:
        - name: mysql
          image: mysql:5.7.22
          ports:
            - containerPort: 3306
          volumeMounts:
            - name: mysql-storage
              mountPath: /var/lib/mysql
              subPath: mysql
          env:
            - name: MYSQL_HOST
              value: mysql-cluster-ip-service
            - name: MYSQL_ROOT_PASSWORD
              value: root
            - name: MYSQL_DATABASE
              value: db
            - name: MYSQL_USER
              value: user
            - name: MYSQL_PASSWORD
              value: secret
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: database-persistent-volume-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
</code></pre>

<p>Nginx server <strong>working</strong> configuration file used on docker nginx image for previous docker development environment (nginx is in docker a separated container from php container):</p>

<pre><code>server {

    listen 443 default_server ssl;

    root   /opt/app/public;
    index  index.php;

    ...

    location / {
       try_files $uri $uri/ /index.php$is_args$args;
    }

    location /healthcheck {
        return 200 'ok';
        add_header Content-Type text/plain;
    }

    error_page 404 /index.php;

    location ~ ^/(index)\.php(/|$) {

        fastcgi_pass php:9000;
        fastcgi_index index.php;

        include fastcgi_params;
    }
}
</code></pre>

<p>when accessing minikube ip on browser I get 502 error.</p>

<p>I've installed <strong>ingress-nginx</strong> running following commands (as explained in their <a href="https://kubernetes.github.io/ingress-nginx/deploy/" rel="nofollow noreferrer">installation guide</a>)</p>

<pre><code>$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
$ minikube addons enable ingress
$ make dev-env
</code></pre>

<p>I assume I need to map somehow the root (nginx conf) to /opt/app/public and somehow configure the fastcgi_pass in the ingress-nginx which I'm still honestly a bit lost on how all together works. </p>

jj-aa
<p>This might be one of the following problems.Your ingress seems fine.</p>

<ul>
<li><p>Did you mean to run an nginx container in the same pod as your php container? Once you have nginx running in the same pod, you will have to replace "php" in your <code>fastci_pass</code> to "127.0.0.1".</p></li>
<li><p>Check your pod logs, if you are getting <code>connection refused</code> it's problem with your php container, it's not exposing the ports properly. Try doing <code>port-forward</code>ing on your php pod and see if you can access 5000 through localhost. </p></li>
<li><p>I see you have your <code>fastcgi_pass</code> on php:9000, is this supposed to be 5000? </p></li>
</ul>
