Back to Blog
Running Laravel on Kubernetes: From Basics to Production
When Kubernetes Makes Sense
Kubernetes adds complexity but provides powerful orchestration for scaling, self-healing, and deployment management. Use it when you need these capabilities at scale.
Deployment Manifest
apiVersion: apps/v1
kind: Deployment
metadata:
name: laravel-app
spec:
replicas: 3
selector:
matchLabels:
app: laravel
template:
metadata:
labels:
app: laravel
spec:
containers:
- name: app
image: myregistry/laravel-app:latest
ports:
- containerPort: 80
env:
- name: APP_KEY
valueFrom:
secretKeyRef:
name: laravel-secrets
key: app-key
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /health
port: 80
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 80
initialDelaySeconds: 5
periodSeconds: 5
Service
apiVersion: v1
kind: Service
metadata:
name: laravel-service
spec:
selector:
app: laravel
ports:
- port: 80
targetPort: 80
type: ClusterIP
Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: laravel-ingress
annotations:
kubernetes.io/ingress.class: nginx
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
tls:
- hosts:
- app.example.com
secretName: laravel-tls
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: laravel-service
port:
number: 80
Queue Workers
apiVersion: apps/v1
kind: Deployment
metadata:
name: laravel-queue
spec:
replicas: 2
template:
spec:
containers:
- name: queue
image: myregistry/laravel-app:latest
command: ["php", "artisan", "queue:work", "--tries=3"]
resources:
requests:
memory: "128Mi"
cpu: "100m"
Horizontal Pod Autoscaler
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: laravel-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: laravel-app
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
Conclusion
Kubernetes provides powerful orchestration for Laravel at scale. Start with basic deployments, add health checks and autoscaling, and build expertise incrementally.
Related Articles
Need Help With Your Project?
I respond to all inquiries within 24 hours. Let's discuss how I can help build your production-ready system.
Get In Touch