Deploying Laravel on Kubernetes with Ingress: A Complete Starter Guide - ANSNEW

Deploying Laravel on Kubernetes with Ingress: A Complete Starter Guide

Deploying Laravel on Kubernetes with Ingress: A Complete Starter Guide
Deploying Laravel on Kubernetes with Ingress: A Complete Starter Guide 

Laravel is one of the most popular PHP frameworks, widely used for building scalable web applications. But when it comes to deploying Laravel in modern cloud environments, things can get tricky—especially if you want high availability, scalability, and maintainability. That’s where Kubernetes shines. And to make things easier, I’ve put together a Laravel on Kubernetes (with Ingress) Starter Pack, available on GitHub: Laravel-on-Kubernetes-with-Ingress-Starter-Pack.

This bundle is designed to give you a production-ready setup to containerize, deploy, and scale your Laravel application using Kubernetes, complete with Nginx Ingress support. Let’s walk through everything included and how to get it running.


What’s Inside the Starter Pack

The repository provides a complete Kubernetes-ready package for Laravel. Here’s what you’ll find:

  • Dockerfile — A multi-stage build using PHP-FPM 8.3 and Nginx, managed with Supervisor.
  • .docker/ — Contains PHP, Nginx, and Supervisor configuration files.
  • k8s/ — Kubernetes manifests, including:
    • Namespace
    • ConfigMap
    • Secret
    • PersistentVolumeClaim (PVC)
    • Deployment
    • Service
    • Ingress
    • Horizontal Pod Autoscaler (HPA)
    • kustomization.yaml for easy management

Step 1: Configure Secrets and Environment Variables

Before deploying, configure your Laravel app secrets and environment variables:

  1. Secrets (sensitive values like database credentials):
    • Open k8s/secret-app.yaml
    • Set values for DB_*, APP_KEY, and APP_URL
  2. ConfigMap (non-sensitive configs):
    • Open k8s/configmap-app.yaml
    • Add values like cache settings, mail driver, or any other non-secret environment variable
  3. StorageClass:
    • In k8s/pvc.yaml, update storageClassName with your cluster’s available storage class
    • Or, remove the line to use the default StorageClass

Step 2: Build and Push Your Docker Image

Your Laravel app needs to be containerized. From the project root, run:

docker build -t yourrepo/laravel-app:latest .
docker push yourrepo/laravel-app:latest

Update the image name inside k8s/deployment.yaml to match your repository.


Step 3: Deploy to Kubernetes

Once everything is set, apply the manifests:

kubectl apply -k k8s/

This will create all required Kubernetes resources: namespace, deployment, service, PVC, Ingress, and HPA.


Step 4: Configure Ingress, DNS, and TLS

The Ingress resource exposes your Laravel app to the outside world:

  • In k8s/ingress.yaml, replace laravel.example.com with your domain.
  • If you use cert-manager for TLS:
    • Uncomment the TLS section in ingress.yaml
    • Set cert-manager.io/cluster-issuer to match your cluster issuer
  • Finally, point your DNS A/AAAA records to your Ingress Controller’s external IP.

Step 5: Handle Laravel Storage and Cache

Laravel needs persistent storage for uploads, logs, and cache:

  • A PVC is mounted at /var/www/html/storage to persist uploaded files.
  • /var/www/html/bootstrap/cache uses emptyDir, which is ephemeral.

This ensures uploads remain intact across pod restarts.


Step 6: Add Health Checks

To ensure Kubernetes can properly manage pod readiness, a health check route is included:

Route::get('/healthz', fn() => response('OK', 200));

The readiness probe in deployment.yaml will then monitor this endpoint.


Step 7: Enable Auto-Scaling

The Horizontal Pod Autoscaler (HPA) is configured in k8s/hpa.yaml:

  • Scales between 2–10 replicas
  • Triggered when CPU utilization exceeds 70%

You can tweak these settings based on your workload.


Advanced Notes & Options

  • Asset Delivery via CDN: If you already serve assets via a CDN, adjust cache headers in .docker/default.conf.
  • Redis / Queues / Octane: Add Redis and queue services in your cluster, then configure their envs in k8s/secret-app.yaml.
  • Alternative Setup: If you prefer sidecar Nginx instead of a combined PHP-FPM + Nginx container, update the Deployment spec accordingly.

Why Use This Starter Pack?

Deploying Laravel on Kubernetes can be complex, with many moving parts—Docker, Nginx, PHP-FPM, PVCs, Ingress, scaling, and secrets. This starter pack simplifies it by providing a ready-to-use boilerplate that you can customize for your own projects.

With this setup, you get:

  • A production-ready Laravel deployment
  • Automatic scaling with HPA
  • Persistent storage for user uploads
  • Secure Ingress with TLS support
  • Health checks for reliable rollouts


Download ANSNEW APP For Ads Free Expriences!
Yamin Hossain Shohan
Software Engineer, Researcher & Digital Creator

I'm a researcher, software engineer, and digital creator who uses technology and creativity to make useful tools and create interesting content.

Copyright Disclaimer

All the information is published in good faith and for general information purpose only. We does not make any warranties about the completeness, reliability and accuracy of this information. Any action you take upon the information you find on ansnew.com is strictly at your own risk. We will not be liable for any losses and/or damages in connection with the use of our website. Please read our complete disclaimer. And we do not hold any copyright over the article multimedia materials. All credit goes to the respective owner/creator of the pictures, audios and videos. We also accept no liability for any links to other URLs which appear on our website. If you are a copyright owner or an agent thereof, and you believe that any material available on our services infringes your copyrights, then you may submit a written copyright infringement notification using the contact details

(0) Comments on "Deploying Laravel on Kubernetes with Ingress: A Complete Starter Guide"

* Most comments will be posted if that are on-topic and not abusive
Back To Top