Pod Startup Sequence
LaraKube CLI uses a deterministic startup sequence to ensure that your application never crashes during the initial larakube up or during subsequent updates. This is achieved through Kubernetes initContainers and a "Web-First" dependency model.
🏗 The "Orchestration" Flow
When you run larakube up, Kubernetes attempts to start all pods simultaneously. However, LaraKube CLI enforces a strict functional order:
- Infrastructure First: Databases (Postgres/MySQL) and Cache (Redis) start. They have no dependencies.
- Web Pod (The Leader): The
php-webpod starts but stays in anInitstate until it can reach the database and redis. - Migration Runner: Once the database is up, the
php-webpod executesphp artisan migrate. - Worker Readiness: Dependent pods like
horizon,scheduler, andreverbstay in anInitstate until both the infrastructure is ready AND thephp-webpod is "Ready" (meaning migrations are finished).
🔍 Who waits for what?
| Pod / Service | Waits For... | Why? |
|---|---|---|
| Databases | None | Foundation of the stack. |
| php-web | DB + Redis | Needs to run migrations and clear cache. |
| horizon | DB + Redis + php-web | Prevents workers from crashing if tables don't exist yet. |
| reverb | DB + Redis + php-web | Ensures the database schema is ready for websocket state. |
| scheduler | DB + Redis + php-web | Prevents scheduled tasks from failing due to missing schema. |
🛠 How it works (Technically)
1. wait-for-services
Every PHP-based pod contains a wait-for-services initContainer. It uses nc (Netcat) to probe the database and redis ports.
- Resilience: If you aren't using Redis, LaraKube CLI intelligently skips this check by detecting the
REDIS_HOST=127.0.0.1default.
2. wait-for-web
Worker pods (horizon, reverb, etc.) contain a second initContainer called wait-for-web. It probes the laravel-web service on port 80.
- The Secret: The
php-webpod only becomes "Ready" in Kubernetes after its entrypoint script (which runs migrations) has successfully finished. By waiting for the web service, workers are guaranteed that the database schema is fully up-to-date. - Optimization: To speed up boot times, all sidecars (workers, scheduler, reverb) have
AUTORUN_ENABLED=false. This prevents them from running redundant, time-consumingartisan optimizecommands, as they share the pre-optimizedbootstrap/cachefrom the Web pod.
3. Recreate Strategy
LaraKube CLI uses the strategy: type: Recreate for all deployments.
- Migration Safety: This ensures that during an update, the old pod is fully terminated before the new pod starts. This prevents two pods from trying to run
php artisan migrateat the same time, which would cause database lock errors.
💡 Troubleshooting Startup
If your pods are stuck in Init:0/2 or Init:1/2, it usually means one of the dependencies isn't reachable.
- Check Logs:
kubectl logs <pod-name> -c wait-for-web - Check Web Pod: If the web pod is crashing (e.g., a bad migration), all other pods will wait indefinitely until the web pod is fixed.