Getting 502 bad gateway

Hello @Inderpreet @juliettet @akshayyw
I have got assigned a task called “Fix issue with PhpFpm Application Deployed on Kubernetes”. Below is the question:

We deployed a Nginx and PHPFPM based application on Kubernetes cluster last week and it had been working fine. This morning one of the team members was troubleshooting an issue with this stack and he was supposed to run Nginx welcome page for now on this stack till issue with phpfpm is fixed but he made a change somewhere which caused some issue and the application stopped working. Please look into the issue and fix the same:

The deployment name is nginx-phpfpm-dp and service name is nginx-service . Figure out the issues and fix them. FYI Nginx is configured to use default http port, node port is 30008 and copy index.php under /tmp/index.php to deployment under /var/www/html . Please do not try to delete/modify any other existing components like deployment name, service name etc.

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.

===========

what I have done

===========

  1. Checked the pods (running)

  2. Checked SVC

  3. Checked config maps where port is set to 80:

Data

nginx.conf:

events {
}
http {
server {
listen 80 default_server;
listen [::]:80 default_server;

# Set nginx to serve files from the shared volume!
root /var/www/html;
index  index.html index.htm;
server_name _;
location / {
  try_files $uri $uri/ =404;
}
location ~ \.php$ {
  include fastcgi_params;
  fastcgi_param REQUEST_METHOD $request_method;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_pass 127.0.0.1:9000;
}

}
}

  1. Changed the service port to 80:

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 443/TCP 94m
nginx-service LoadBalancer 10.96.4.209 80:30008/TCP 15m

  1. Copied the file in nginx-container and checked as well:

kubectl exec -it nginx-phpfpm-dp-5cccd45499-mvfzs -c nginx-container /bin/bash

ls /var/www/html/

index.php

<?php // Show all information, defaults to INFO_ALL phpinfo(); // Show just the module information. // phpinfo(8) yields identical results. phpinfo(INFO_MODULES); ?>root@ng
  1. As I am selecting view port and choosing the port 30008, I am getting 403 error:

403 Forbidden

nginx/1.23.2

  1. Again gone into container:

→ Tried to change the user to apache and apache user does not exist

How to proceed?

Hi @Ashu27 ,

Sorry for the late response.

I encountered the sane 403 error. Check out this thread: Need help with task "Fix issue with PhpFpm Application Deployed on Kubernetes "

# configMap should look kike this:
kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config
data:
  nginx.conf: |
    events {
    }
    http {
    server {
    listen 80 default_server;
    listen [::]:80 default_server;

        # Set nginx to serve files from the shared volume!
        root /var/www/html;
        index index.html index.htm index.php;
        server_name _;
        location / {
            try_files $uri $uri/ =404;
        }
            location ~ \.php$ {
            include fastcgi_params;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass 127.0.0.1:9000;
        }
        }
    }

# end

# copy ndex.php to container & restart
k cp /tmp/index.php nginx-phpfpm-dp-7bf99ff87b-mtjxv:/var/www/html -c nginx-container

k rollout restart deployment nginx-phpfpm-dp

# make sure ports of service = 80 + make sure type is nodePort

k exec -it <pod> -n default -- /bin/sh

ls 

# should see index.php

Hope this helps:-)