Kubernetes: NGINX/PHP-FPM graceful shutdown and 502 errors

Kubernetes: NGINX/PHP-FPM graceful shutdown and 502 errors

Kubernetes: NGINX/PHP-FPM graceful shutdown and 502 errors. In the Graceful shutdown in Kubernetes is not always trivial and on the Stackoveflow in the Nginx / PHP FPM graceful stop. So graceful question is a note that FPM's master and this can lead to the 502 as well. That during downscaling clients get 502 errors.

We have a PHP application running with Kubernetes in pods with two dedicated containers — NGINX и PHP-FPM.

The problem is that during downscaling clients get 502 errors. E.g. when a pod is stopping, its containers can not correctly close existing connections.

So, in this post, we will take a closer look at the pods’ termination process in general, and NGINX and PHP-FPM containers in particular.

Testing will be performed on the AWS Elastic Kubernetes Service by the  Yandex.Tank utility.

Ingress resource will create an AWS Application Load Balancer with the  AWS ALB Ingress Controller.

Pod Lifecycle — Termination of Pods

So, let’s take an overview of the pods’ stopping and termination process.

Basically, a pod is a set of processes running on a Kubernetes WorkerNode, which are stopped by standard IPC (Inter-Process Communication) signals.

To give the pod the ability to finish all its operations, a  container runtime at first ties softly stop it (graceful shutdown) by sending a SIGTERM signal to a PID 1 in each container of this pod (see  docker stop). Also, a cluster starts counting a grace period before force kill this pod by sending a SIGKILL signal.

The SIGTERM can be overridden by using the STOPSIGNAL in an image used to spin up a container.

php-fpm nginx kubernetes troubleshooting docker

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

50+ Useful Kubernetes Tools for 2020 - Part 2

Our original Kubernetes tool list was so popular that we've curated another great list of tools to help you improve your functionality with the platform.

Kubernetes vs Docker

Get Hands-on experience on Kubernetes and the best comparison of Kubernetes over the DevOps at your place at Kubernetes training

Docker Explained: Docker Architecture | Docker Registries

Following the second video about Docker basics, in this video, I explain Docker architecture and explain the different building blocks of the docker engine; docker client, API, Docker Daemon. I also explain what a docker registry is and I finish the video with a demo explaining and illustrating how to use Docker hub.

Kubernetes Is Deprecating Docker Support—What Does This Mean

Starting with Kubernetes 1.20 developers have received a warning that Kubernetes is deprecating Docker. This means that Kubernetes officially ceases to support the Docker tech stack, as you can already see in the release notes on GitHub. Let's see what this means.

How to Setup Nginx with PHP-FPM on Ubuntu 20.04

The PHP FPM (FastCGI Process Manager) is used for deploying PHP based websites over Nginx web server. FPM is a process manager to manage the FastCGI SAPI (Server API) in PHP. This tutorial will help you to install and configure Nginx with PHP-FPM on Ubuntu 20.04 system. Prerequisites Shell access with sudo privileged account to […]