alexlogy.io | Singapore Tech Blog on the Cloud Infrastructure

alexlogy.io | Singapore Tech Blog on the Cloud Infrastructure


daily thoughts from a cloud infrastructure perspective

Alex
Author

a cloud infrastructure manager who is fascinated with devops philosophies

Share


Tags


How to deploy scalable PHP applications in Kubernetes?

Performance tuning for PHP has always been a problem for every infrastructure engineers. How do you make the application load faster? How do you make the latency lower?

I had my fair share of deploying PHP applications since I first started coming in contact with Wordpress (a blogging software) and Laravel (a PHP framework) back in 2011. Back then, dockers didn't exist yet and Public Clouds were not popular back then, we had to deploy the PHP application in virtual machines or dedicated servers. It was easy setting up Apache and Mod_PHP to setup our PHP applications. Our only option to scale our application is to clone the virtual machines or dedicated servers and load balance between the applications.. (that sucks right?)

Fast forward 10 years ahead to where we are right now in time, we have an abundance of Public Clouds, technologies available to allow us to scale freely and as automated as possible. I shall not elaborate on Kubernetes and containers as that is not the focus of this post.

Now, how can we design highly scalable PHP applications in Kubernetes?

First, we have to understand how PHP requests work starting from the user's request to https://example.alexlogy.io/index.php and how it traverse through the servers.

Diagram depicting how PHP Request traverse through the servers

If you refer to the diagram above, you will realise every single request for a PHP file have around 6 steps to complete (without accounting for any database or other connections such as redis/kafka/etc).

Let's break down the important factors before we dive into designing the architecture for Kubernetes.

With the above points, I can design the architecture in the below illustration:

Re-designed PHP Architecture Mockup Diagram

As such, we can setup the containers this way:

To complete the setup, we can setup the CI/CD process with the following method:

With the above design, you can have a highly scalable architecture design for PHP applications in Kubernetes as each deployment will have HPA to scale as necessary.

Alex
Author

Alex

a cloud infrastructure manager who is fascinated with devops philosophies

View Comments