Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mathewparet's avatar

Kubernetes is killing me! A course would be nice.

I think I'm losing my edge here haha. I can't seem to understand Kubernetes at all.

It would be nice to have a guide or course on setting up a laravel project using Kubernetes.

My app runs on Laravel, inertiajs, redis, mysql, and meilisearch. It would be nice to have a course that covers this plus option to go for a managed db, managed redis etc and an option to add more than one website pods (so I can deploy multiple websites, one per pod) on a single cluster.

2 likes
2 replies
LaryAI's avatar
Level 58

To set up a Laravel project using Kubernetes, you can follow these general steps. This guide will help you get started with deploying a Laravel application along with Redis, MySQL, and Meilisearch on a Kubernetes cluster. We'll also touch on using managed services and deploying multiple websites.

Prerequisites

  1. Kubernetes Cluster: You need access to a Kubernetes cluster. You can use a local setup like Minikube or a cloud provider like Google Kubernetes Engine (GKE), Amazon EKS, or Azure AKS.
  2. kubectl: Ensure you have kubectl installed and configured to interact with your cluster.
  3. Docker: You need Docker to build your application images.

Steps

1. Dockerize Your Laravel Application

Create a Dockerfile for your Laravel application:

2. Create Kubernetes Manifests

Create a deployment.yaml for your Laravel application:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: laravel-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: laravel
  template:
    metadata:
      labels:
        app: laravel
    spec:
      containers:
      - name: laravel
        image: your-dockerhub-username/laravel-app:latest
        ports:
        - containerPort: 9000

Create a service.yaml for your Laravel application:

apiVersion: v1
kind: Service
metadata:
  name: laravel-service
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 9000
  selector:
    app: laravel

3. Deploy MySQL, Redis, and Meilisearch

For simplicity, you can use Helm charts or managed services for these components. Here's an example of deploying MySQL using a Kubernetes manifest:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:5.7
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: yourpassword
        ports:
        - containerPort: 3306

For Redis and Meilisearch, you can follow similar steps or use managed services provided by your cloud provider.

4. Deploy Multiple Websites

To deploy multiple websites, you can create separate deployments and services for each Laravel application. Ensure each deployment has a unique label and service name.

5. Use Managed Services

If you prefer managed services for MySQL and Redis, you can configure your Laravel application to connect to these services by updating the environment variables in your Kubernetes deployment.

Conclusion

This is a basic setup to get you started with deploying a Laravel application on Kubernetes. For a production-ready setup, consider using Helm for managing your deployments, setting up proper networking, and implementing security best practices. Additionally, you might want to explore using Ingress controllers for routing traffic to multiple applications.

Haych's avatar

Let us know if you get this working.

Please or to participate in this conversation.