Deploying Laravel in Kubernetes
Photo by David Ramírez / Unsplash

Deploying Laravel in Kubernetes

Deploying Laravel in Kubernetes simplifies running, scaling and monitoring Kubernetes in an easily reproducible way.

There are plenty of aspects to take into account when running Laravel.

FPM, Nginx, Certificates, Static Assets, Queue Workers, Caches, The Scheduler, Monitoring, Distributed Logging and a bunch more stuff.

Tools like Laravel Forge, and Laravel Vapor manage many of these things for you, but what would the tech world look like without choices ?

Laravel already ships with a Docker setup with Laravel Sail, but in this series we will build our own images in a production like fashion, specialising the containers and images to each of the different parts of our application.

We will also create a reproducible setup for our application,
which can easily be used to deploy other Laravel applications as well.

This series will cover everything from local development, CI/CD, Codified Infrastructure including databases, Declarative configurations for deployment in Kubernetes for each independent component of the application, Monitoring the deployed application and infrastructure, Distributed Logging infrastructure, and Alerting for application and infrastructure metrics.

There is a lot covered in this series, and the best way to approach this would be to read 2-3 posts, and implement them as you go through, and then do a bit of digging to better understand why and how they work.

Below all the series episodes are listed in their particular section of deployment

Getting the application ready for Kubernetes

Laravel in Kubernetes Part 1 - Installing Laravel
This series will show you how to go from laravel new to Laravel running in Kubernetes, including monitoring, logging, exposing and bunch more. Part 1 of this series covers creating a new laravel installation which we can deploy in Kubernetes. TLDR; Laravel In Kubernetes Part 1Laravel In Kubernetes P…
Laravel in Kubernetes Part 2 - Dockerizing Laravel
In this part of the series, we are going to Dockerise our Laravel application with different layers, for all the different technical pieces of our application (FPM, Web Server, Queues, Cron etc.) We will do this by building layers for each process, copy in the codebase, and build separate containers
Laravel in Kubernetes Part 3 - Container Registries
In this post, we will take our new Dockerfile and layers, and build the images, and push them up to a registry, so we can easily use them in Kubernetes. TLDR - Laravel In Kubernetes Part 3Laravel In Kubernetes Part 3. GitHub Gist: instantly share code, notes, and snippets.Gist262588213843476Table

Deploying the infrastructure for the application

Laravel in Kubernetes Part 4 - Kubernetes Cluster Setup
In this post, we will spin up our Kubernetes cluster using Terraform, in DigitalOcean. We will create this using Terraform, so we can easily spin up and spin down our cluster, as well as keep all of our information declarative. If you’d like to spin up a cluster without Terraform,
Laravel in Kubernetes Part 5 - Deploying a database for our application
Deploying a database for our application can be quite a challenge. On one hand, using a managed database makes sense from a management perspective, but might be a bit more expensive than running it ourselves. On the other hand, running it ourselves comes with a whole array of possible maintenance

Deploying the application in Kubernetes

Laravel in Kubernetes Part 6 - Deploying Laravel Web App in Kubernetes
In this post we will cover deploying our Laravel Web App inside of Kubernetes. This covers our main app and our migrations in Kubernetes. This post also assumes you have Dockerised your application, using Part 2 & Part 3 from this series. If not, and you have containerised your application,
Laravel in Kubernetes Part 7 - Deploying Redis to run Queue workers and cache
In this post, we’ll go over deploying a Redis instance, where we can run our Queue workers from in Laravel. The Redis instance can also be used for Caching inside Laravel, or a second Redis cluster can be installed for Cache separately We will cover two methods of running a
Laravel in Kubernetes Part 8 - Deploying Laravel Queue workers in Kubernetes
In this post we will cover deploying Laravel Queue workers in Laravel. Deploying Laravel Queue workers in Kubernetes, makes it fairly easy to scale out workers when jobs start piling up, and releasing resources when there is lower load on the system. Queue connection updateWe need to make sure the
Laravel in Kubernetes Part 9 - Deploying the Laravel Scheduler
In this post, we’ll cover deploying the Laravel Scheduler in Kubernetes. The Laravel Scheduler takes care of running tasks / jobs on a set schedule or at specific times. Kubernetes Cronjob or Cron in a Container ?There are some differences we need to be aware of before willy-nilly jumping into a

Exposing the application to the internet

Laravel in Kubernetes Part 10 - Exposing the application
Our application is now successfully deployed in Kubernetes, but we need to expose it to the outside world. We can access it locally by running kubectl port-forward svc/laravel-in-kubernetes-webserver 8080:80 and going to http://localhost:8080. We need to expose our application to the outside world …
Laravel in Kubernetes Part 11 - Adding Let’s Encrypt certificates to the application
The next important piece, is for us to add certificates to our application, so our users can securely use our application across the internet. We are going to use Cert Manager to achieve this, as it will automatically provision new certificates for us, as well as renew them on a