How to deploy a Laravel for Rust app on Cloider Kubernetes Engine

Deploy a Laravel for Rust app with PostgreSQL to a Cloider Kubernetes cluster: build and push the image to the Cloider registry, write the manifests, run migrations as a Job, and expose it on a free HTTPS subdomain, with a screenshot of every step.

Marei Morsy··10 min read
Delopy a laravel rust app on cloider kubernetes engine
On this page

Key takeaways

  • Push the image to registry.cloider.com and pull it with a Pull only token stored as an imagePullSecret.
  • Keep APP_KEY and DATABASE_URL in a Secret created with kubectl, and the rest in a ConfigMap.
  • Run migrations as a Job with the same image, then let the Deployment probe /up.
  • Pods reach the managed PostgreSQL database on its private host with sslmode=require.
  • A target exposes a Service on a free cloider.app subdomain with HTTPS, no Ingress needed.

Cloider App Engine is the shortest way to run a web app, but sometimes you want Kubernetes itself: your own manifests, Jobs, private Services, or the same setup you run elsewhere. Cloider Kubernetes gives you a managed cluster in a couple of minutes, with no control plane or nodes to look after.

In this guide you deploy a Laravel for Rust app with a PostgreSQL database to a Cloider Kubernetes cluster, three ways:

  1. The classic way, from the dashboard: dockerize the app, build the image, create the database, write the Kubernetes manifests, and verify it works.

  2. With the cloider CLI: build and push to the Cloider container registry, deploy the app, then expose it on a free subdomain with HTTPS.

  3. With an AI coding agent: "using cloider cli deploy this app to cloider kubernetes engine".

Options 1 and 2 show every step with a screenshot. The finished app is live at laravel-rust-k8s.cloider.app, and the code and manifests are on GitHub at mareimorsy/laravel-rust-blog. If you only need the app running, the App Engine guide is shorter.

What you need

  • A Cloider account. New accounts get a welcome credit.

  • Docker with buildx, and kubectl.

  • The app: git clone https://github.com/mareimorsy/laravel-rust-blog.git.

The repository's k8s/ folder holds four manifests. Secrets are not in it: you create them with kubectl, so they never land in git.

File

What it creates

k8s/config.yaml

ConfigMap laravel-config: APP_ENV, APP_DEBUG, APP_URL, LOG_CHANNEL

k8s/migrate.yaml

Job laravel-migrate: runs ./myapp migrate --force once

k8s/deployment.yaml

Deployment laravel: 2 replicas on port 8080, probes on /up

k8s/service.yaml

Service laravel: port 80 to the pods' port 8080


Option 1: the classic way, from the dashboard

Step 1: Dockerize the app

Laravel for Rust compiles your whole application, migrations included, into one binary. At runtime it still reads three folders next to it: public/ (the Vite build), resources/views/ (the root view) and storage/. The Dockerfile in the repository builds all of that in three stages:

  1. assets: npm ci and npm run build write the Inertia + React frontend to public/build.

  2. server: cargo build --release --locked builds the binary. The two cache mounts keep the Cargo registry and the build folder between builds, so a rebuild only compiles what changed.

  3. runtime: a slim Debian image with the binary, public/, resources/views/ and a writable storage/, running as a non-root app user.

Dockerfile
# syntax=docker/dockerfile:1

FROM node:24-slim AS assets
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY vite.config.ts tsconfig.json ./
COPY resources ./resources
COPY public ./public
RUN npm run build

FROM rust:1.100-slim-trixie AS server
WORKDIR /app
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
    --mount=type=cache,target=/usr/local/cargo/build \
    cargo build --release --locked \
    && cp target/release/myapp /usr/local/bin/myapp

FROM debian:trixie-slim
RUN apt-get update \
    && apt-get install -y --no-install-recommends ca-certificates \
    && rm -rf /var/lib/apt/lists/* \
    && useradd --system --no-create-home app
WORKDIR /app
COPY --from=server /usr/local/bin/myapp ./myapp
COPY --from=assets /app/public ./public
COPY resources/views ./resources/views
RUN mkdir -p storage/app storage/logs && chown -R app:app storage

ENV SERVER_HOST=0.0.0.0 \
    SERVER_PORT=8080
USER app
EXPOSE 8080
CMD ["./myapp"]
The Dockerfile of the laravel-rust-blog repository printed in a terminal
The Dockerfile: Vite assets, the release binary, and a small Debian runtime on port 8080.

Two settings matter on any platform. The server listens on 127.0.0.1:8000 by default, which nothing outside the container can reach, so the image sets SERVER_HOST=0.0.0.0 and SERVER_PORT=8080. And Cloider terminates HTTPS in front of your app, so src/app.rs trusts the proxy, which makes the URLs the app generates start with https://:

Rust
.with_middleware(|middleware, _| {
    // Cloider's load balancer terminates HTTPS, and apps are only reachable through it
    middleware.trust_proxies(["*"]);
    // ...
})

The framework also answers GET /up with a 200 once it has started, which is what Cloider and Kubernetes use as the health check.

Step 2: Build the image

Kubernetes pulls images from a registry, so push yours to the Cloider container registry. Open Registry, click Create Project and name it. Project names are shared by everyone on registry.cloider.com, so pick your own, here laravel-rust.

The Create new project form of the container registry with the name laravel-rust and a 5 GB storage limit
A registry project holds your images under one name.
The registry projects list with laravel-rust at registry.cloider.com/laravel-rust, private and Ready
The project is private and ready.

On the Tokens tab, click Create Token. Name it laptop, limit it to the laravel-rust project and give it Pull & push:

The Create Token dialog with the name laptop, only the laravel-rust project, Pull and push permission and no expiry
A token for your machine, limited to one project.

The secret is shown once, with a ready docker login command and a ready Kubernetes pull secret command. Copy it now.

The Token created dialog with the registry host, the username, the secret hidden here, a docker login command and a kubectl create secret docker-registry command
The secret is shown only once. It is hidden in this screenshot.

Log docker in with the username and secret from that dialog (doe.cloider is this account's), then build the image for linux/amd64, the platform Cloider's nodes run, and push it:

Bash
echo "$REGISTRY_TOKEN" | docker login registry.cloider.com -u doe.cloider --password-stdin
docker buildx build --platform linux/amd64 -t registry.cloider.com/laravel-rust/blog:v1 --push .
docker login to registry.cloider.com printing Login Succeeded
Logged in to registry.cloider.com.
docker buildx output building the stages and pushing registry.cloider.com/laravel-rust/blog:v1
Built and pushed. On an Apple silicon Mac the amd64 build runs under emulation, so the first one is slow.
The laravel-rust project Repositories tab listing the blog repository with one image
The image is in the registry.

Step 3: Create the database

Open Databases, click Create Database, name it laravel-k8s with the user laravel, pick PostgreSQL v18 and the Hobby plan, and create it.

The new database form with the name laravel-k8s, the user laravel, PostgreSQL v18, Allow Everything trusted sources and SSL on
A managed PostgreSQL database for the cluster.

Once it is Ready, copy the DSN from the Private tab of Quick Connect on its page, as in the App Engine guide. Pods in your Cloider clusters reach the database on its private host, ...db.cloider.internal.

Step 4: Create the cluster and the Kubernetes manifests

Open Kubernetes and click Create Cluster. A name is all it needs:

The Create new cluster form with the cluster name laravel
A cluster needs only a name.
The clusters list with the laravel cluster on Kubernetes v1.36 in the Starting status
The cluster starts in a couple of minutes.

When it is ready, click it. The cluster page lists your workloads, and has Apply YAML, a Terminal with kubectl, and a button to download the kubeconfig.

The laravel cluster page with the workload views on the left and the Apply YAML, Terminal and kubeconfig buttons
Everything about the cluster in one page.

Connect kubectl to it. Download the kubeconfig from the cluster page, or let the CLI merge it into yours:

Bash
cloider cluster kubeconfig laravel --merge --use
kubectl get nodes
cloider cluster kubeconfig adding the cloider-laravel context, and kubectl get nodes showing a Ready node
kubectl talks to the cluster.

Create the namespace and the two Secrets: the app's APP_KEY and DATABASE_URL, and the registry login the pods pull the image with. Use a Pull only registry token for the cluster:

Bash
export APP_KEY="base64:$(openssl rand -base64 32)"
export DATABASE_URL="postgres://laravel:PASSWORD@laravel-k8s-xgdoy3.db.cloider.internal:20611/laravel-k8s?sslmode=require"  # the private DSN
export PULL_TOKEN="..."  # the secret of a Pull only token for the laravel-rust project

kubectl create namespace laravel
kubectl -n laravel create secret generic laravel-secrets \
  --from-literal=APP_KEY="$APP_KEY" --from-literal=DATABASE_URL="$DATABASE_URL"
kubectl -n laravel create secret docker-registry cloider-registry \
  --docker-server=registry.cloider.com --docker-username=doe.cloider --docker-password="$PULL_TOKEN"
kubectl creating the laravel namespace, the laravel-secrets Secret and the cloider-registry docker-registry Secret
The secrets live only in the cluster.

Now the manifests. The ConfigMap holds the settings that aren't secret:

YAML
# Settings that aren't secret. APP_KEY and DATABASE_URL live in the Secret
# laravel-secrets, created with kubectl so they never land in git.
apiVersion: v1
kind: ConfigMap
metadata:
  name: laravel-config
  namespace: laravel
data:
  APP_ENV: production
  APP_DEBUG: "false"
  APP_URL: https://laravel-rust-k8s.cloider.app
  LOG_CHANNEL: stderr

A Job runs the migrations once, with the same image, settings and secrets as the app:

YAML
# Runs the migrations once, before the new version serves traffic.
# Delete and apply it again on every deploy that adds a migration.
apiVersion: batch/v1
kind: Job
metadata:
  name: laravel-migrate
  namespace: laravel
spec:
  backoffLimit: 3
  ttlSecondsAfterFinished: 86400
  template:
    spec:
      restartPolicy: Never
      imagePullSecrets:
        - name: cloider-registry
      containers:
        - name: migrate
          image: registry.cloider.com/laravel-rust/blog:v1
          command: ["./myapp", "migrate", "--force"]
          envFrom:
            - configMapRef:
                name: laravel-config
            - secretRef:
                name: laravel-secrets

The Deployment runs two replicas, pulls the image with the cloider-registry secret, and uses the framework's /up route for its readiness and liveness probes:

YAML
apiVersion: apps/v1
kind: Deployment
metadata:
  name: laravel
  namespace: laravel
  labels:
    app: laravel
spec:
  replicas: 2
  selector:
    matchLabels:
      app: laravel
  template:
    metadata:
      labels:
        app: laravel
    spec:
      imagePullSecrets:
        - name: cloider-registry
      containers:
        - name: web
          image: registry.cloider.com/laravel-rust/blog:v1
          ports:
            - name: http
              containerPort: 8080
          envFrom:
            - configMapRef:
                name: laravel-config
            - secretRef:
                name: laravel-secrets
          readinessProbe:
            httpGet:
              path: /up
              port: http
            periodSeconds: 5
          livenessProbe:
            httpGet:
              path: /up
              port: http
            initialDelaySeconds: 10
            periodSeconds: 10
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 500m
              memory: 256Mi

And a ClusterIP Service in front of them:

YAML
apiVersion: v1
kind: Service
metadata:
  name: laravel
  namespace: laravel
spec:
  selector:
    app: laravel
  ports:
    - name: http
      port: 80
      targetPort: http

Apply all four with Apply YAML on the cluster page: paste them one after the other, separated by ---, and click Apply. kubectl apply -f k8s/ does the same from your terminal.

The Apply YAML dialog with the ConfigMap and the migration Job pasted into the editor
Paste the manifests and apply them.
The Deployments view right after applying, with the laravel Deployment starting at 0 of 2 ready
The Deployment starts its two replicas.

Step 5: Verify it works

Within a minute the migration Job completes and both replicas are running:

Bash
kubectl -n laravel get jobs,pods
kubectl -n laravel logs job/laravel-migrate
kubectl get jobs,pods showing the laravel-migrate Job complete and two laravel pods running
The Job ran once, the app runs twice.
The migration Job's log: the users, cache, jobs and posts tables migrated, 4 migrations ran
The migrations ran against the managed database.
The Pods view of the cluster page with two laravel pods Running and the laravel-migrate pod Completed
The same, in the dashboard.

Then talk to the Service through a port-forward. In production the app only answers requests for its APP_URL host, so send that as the Host header:

Bash
kubectl -n laravel port-forward svc/laravel 8080:80 &
curl -s -o /dev/null -w "%{http_code}\n" localhost:8080/up
curl -s -o /dev/null -w "%{http_code}\n" -H "Host: laravel-rust-k8s.cloider.app" localhost:8080/posts
Two curl commands through the port-forward, both returning 200
The app answers through its Service.

The app is running in your cluster. Option 2 shows how to put it on the internet with HTTPS.


Option 2: deploy with the cloider CLI and get a free HTTPS subdomain

This time every step is in the terminal. Install the CLI and log in first: curl -fsSL https://cloider.com/install.sh | sh, then cloider login.

Step 1: Dockerize the app

The Dockerfile from option 1 is already in the repository.

Step 2: Build and push to the Cloider container registry

Create a registry project, and let the CLI log docker in. cloider registry login makes a token for this machine and hands its secret to docker on stdin, so you never copy it:

Bash
cloider registry create laravel-rust-cli
cloider registry login
cloider registry create laravel-rust-cli creating the project
A new registry project.
cloider registry login logging docker in to registry.cloider.com for 30 days
docker is logged in, no secret to copy.
Bash
docker buildx build --platform linux/amd64 -t registry.cloider.com/laravel-rust-cli/blog:v1 --push .
The end of a plain progress docker buildx build, pushing every layer of the image
Pushed, reusing the build cache.

Step 3: Deploy the app

Create the cluster and a database that only the cluster may reach:

Bash
cloider cluster create laravel-cli --wait
cloider db create laravel-cli-db --engine postgresql --trusted-source cluster:laravel-cli --wait
cloider cluster create laravel-cli --wait creating a Kubernetes 1.36 cluster and reporting it ready
The cluster is ready.
cloider db create laravel-cli-db with the trusted source cluster:laravel-cli, ready
The database trusts only the cluster.

Point kubectl at the cluster and create the namespace:

Bash
cloider cluster kubeconfig laravel-cli --merge --use
kubectl create namespace laravel
cloider cluster kubeconfig adding the cloider-laravel-cli context and kubectl creating the laravel namespace
kubectl now uses the new cluster.

Create the Secrets straight from the CLI's output, so neither the database password nor the registry token is ever printed:

Bash
DB=$(cloider db get laravel-cli-db -o json)
kubectl -n laravel create secret generic laravel-secrets \
  --from-literal=APP_KEY="base64:$(openssl rand -base64 32)" \
  --from-literal=DATABASE_URL="postgres://$(jq -r .database_user <<<$DB):$(cloider db password laravel-cli-db)@$(jq -r .private_host <<<$DB):$(jq -r .database_port <<<$DB)/$(jq -r .database_name <<<$DB)?sslmode=require"

TOKEN=$(cloider registry token create --label laravel-cli --project laravel-rust-cli --read-only -o json)
kubectl -n laravel create secret docker-registry cloider-registry --docker-server=registry.cloider.com \
  --docker-username="$(jq -r .token.username <<<$TOKEN)" --docker-password="$(jq -r .secret <<<$TOKEN)"
The terminal creating laravel-secrets from cloider db output and cloider-registry from a read only registry token
Both secrets, without a secret on screen.

Point the manifests at your image (your project name differs from the one in the repository), apply them and wait for the rollout:

Bash
sed -i '' 's#laravel-rust/blog#laravel-rust-cli/blog#' k8s/deployment.yaml k8s/migrate.yaml   # on Linux: sed -i
kubectl apply -f k8s/
kubectl -n laravel rollout status deployment/laravel
kubectl apply -f k8s/ creating the ConfigMap, Deployment, Job and Service, and the rollout finishing
Applied and rolled out.

Step 4: Expose it and get a free SSL subdomain

You don't need an Ingress controller or a load balancer. Claim a free cloider.app subdomain and add a target that routes it to the Service. Cloider serves it over HTTPS:

Bash
cloider cluster services laravel-cli
cloider domain create laravel-rust-k8s.cloider.app
cloider target create laravel-rust-k8s.cloider.app --cluster laravel-cli --service laravel/laravel
cloider cluster services listing the laravel Service, cloider domain create claiming laravel-rust-k8s.cloider.app, and cloider target create routing it to laravel-cli/laravel/laravel:80
The subdomain routes to the Service.
The domain page of laravel-rust-k8s.cloider.app in the dashboard with one Cluster target to the laravel Service on port 80
The target in the dashboard, under Domains.

Open https://laravel-rust-k8s.cloider.app and write a post:

The New post form of the app on Kubernetes with the title Hello from Kubernetes
Writing a post on the Kubernetes deployment.
The published post Hello from Kubernetes on the live app
Live over HTTPS on a free subdomain.

To ship a new version, push the image with a new tag, update it in the manifests and apply them again, after re-running the migration Job if you added a migration (kubectl -n laravel delete job laravel-migrate, then apply).


Option 3: let an AI coding agent deploy it

With the CLI installed and logged in, open the project in your AI coding agent and ask:

Text
using cloider cli deploy this app to cloider kubernetes engine

cloider --help points agents to docs.cloider.com/llms.txt, the deployment strategy they follow on Cloider. It tells them to start with cloider whoami, to use managed databases rather than running PostgreSQL in the cluster, and to use Kubernetes when you ask for it, as this prompt does. The commands are the ones in option 2, and the same commands are available as tools through the Cloider MCP server, cloider mcp. See AI coding agents in the docs.


Troubleshooting

  • ImagePullBackOff: the cloider-registry secret is missing from the laravel namespace, or its token can't read the project. Create a Pull only token for that project.

  • exec format error: the image was built for arm64. Build with --platform linux/amd64.

  • 400 Bad Request: the request's host isn't the APP_URL in k8s/config.yaml. Set it to the domain you route to the Service.

  • 500 on every page, with relation "posts" does not exist in the logs: the migration Job hasn't run, or failed. Check kubectl -n laravel logs job/laravel-migrate.

What it costs

A cluster is billed for the CPU and memory its workloads use (and volumes or load balancers, if you add them), the registry by the gigabyte stored ($0.20 per GB a month), and the Hobby database plan is $3.99 a month. Everything is charged by the hour, and targets on a free subdomain cost nothing extra. A new account's welcome credit covers this guide. Delete the cluster, the database and the registry project when you're done.

Frequently asked questions

How do I run Laravel for Rust migrations on Kubernetes?

Run the binary's migrate command once as a Job (command ./myapp migrate --force) with the same image, ConfigMap and Secret as the Deployment, before or alongside the rollout.

How do pods in a Cloider cluster pull private images?

Create a Pull only token in the Cloider registry, store it as a kubernetes.io/dockerconfigjson Secret in the namespace, and reference it in imagePullSecrets.

Do I need an Ingress controller on Cloider Kubernetes?

No. Claim a domain or a free cloider.app subdomain and add a target that routes it to your Service. Cloider terminates HTTPS for you.

Which platform should I build the image for?

linux/amd64. On an Apple silicon Mac, build with docker buildx build --platform linux/amd64.

Written byMarei Morsy

Comments