Skip to content
migration.tools

cloud · kubernetes · docker

From Docker Compose to Kubernetes: what translates and what you must redesign

Moving Docker Compose to Kubernetes: Deployments and Services, depends_on, volumes, secrets, health checks, cron jobs — and the parts that need a redesign.

By

Updated · first published · 5 min read

A Docker Compose file on the left feeding a route line into a group of Kubernetes objects: Deployment, Service, ConfigMap, Secret and PersistentVolumeClaim.

Key points

  • Each Compose service usually becomes a Deployment plus a Service with the same name, so other services keep reaching it at the same hostname.
  • depends_on has no Kubernetes equivalent. Applications must retry their connections, and readiness probes decide when a pod receives traffic.
  • Named volumes become PersistentVolumeClaims; bind mounts of host paths don't translate and should become ConfigMaps or images.
  • Kubernetes Secrets are base64-encoded, not encrypted. Enable encryption at rest or use a secrets manager.
  • Crontab entries become CronJobs; set spec.timeZone explicitly, because the cluster won't use the old server's local time.

Docker Compose describes a set of containers on one machine. Kubernetes describes the desired state of workloads on a cluster of machines that can fail, reschedule and scale. Most of a Compose file translates mechanically into Kubernetes objects. The parts that don't are the parts that depended on there being exactly one machine.

This guide covers both: the mechanical mapping, and the assumptions you'll need to redesign.

First, make the current setup reproducible

If some containers were started by hand with docker run, capture them first. Every flag — ports, volumes, environment variables, restart policy, network — belongs in a Compose file, where it can be reviewed and converted. The docker run to Compose converter turns a command into a service definition.

Then check that docker compose up on a clean machine produces a working system. If it doesn't, the missing piece is something the old server provided, and it will be missing in Kubernetes too.

The mechanical mapping

ComposeKubernetes
A serviceA Deployment (or a StatefulSet for databases)
image, command, entrypoint, environmentThe same fields on the container spec
ports / exposecontainerPort plus a Service
deploy.replicasspec.replicas
deploy.resources.limitsresources.limits and requests
healthchecklivenessProbe and readinessProbe
Named volumePersistentVolumeClaim
env_file with secretsSecret
env_file with settingsConfigMap
restart: alwaysDefault for Deployments
build:Build and push an image to a registry first

The Docker Compose to Kubernetes converter applies this mapping and writes the manifests, with a plain-language note for each feature that needs a decision. The open-source Kompose project does a similar job from the command line.

Service names stay the same

In Compose, a service called db is reachable at the hostname db. In Kubernetes, a Service called db is reachable at db from the same namespace, too (and at db.<namespace>.svc.cluster.local from anywhere). Name the Service after the Compose service and connection strings like postgres://db:5432 keep working unchanged.

Exposing ports

ports: ["8080:80"] in Compose publishes container port 80 on the host's port 8080. Kubernetes has no single host. Inside the cluster, a ClusterIP Service is enough. To reach a service from outside, use a LoadBalancer Service or, for HTTP, an Ingress or Gateway that routes by hostname and path.

What needs a redesign

Startup order: depends_on

Compose's depends_on starts the database before the application. Kubernetes has no equivalent across pods: everything starts at once, in no particular order, and any pod can restart at any time.

The fix belongs in the application, not the manifest. Make every service retry its connections with backoff instead of exiting on the first failure. Then add a readiness probe, so a pod only receives traffic once it can actually serve it. If something must happen before the main container starts — a schema migration, waiting for a dependency — use an init container.

This is also more robust in Compose, so it's worth doing before the move.

Volumes and files on the host

Named volumes translate well: each becomes a PersistentVolumeClaim, and the cluster's storage class provides the disk.

Bind mounts don't. A Compose line like ./nginx.conf:/etc/nginx/nginx.conf mounts a file from the machine's disk, and in a cluster there's no single machine. Configuration files belong in a ConfigMap mounted as a volume. Code and assets belong in the image. Converting a bind mount to a hostPath volume works only on a single-node cluster and is best treated as a temporary bridge.

Databases

A database in a Deployment with a PersistentVolumeClaim will run, but it loses the guarantees a database needs: stable identity, ordered startup, and careful handling when a node fails. Use a StatefulSet, a database operator, or — often the best answer — a managed database service from your cloud provider, and keep only stateless services in the cluster.

Secrets

Move passwords, tokens and API keys out of environment blocks and into a Secret. The .env to Kubernetes Secret converter turns an existing .env file into a manifest you can load with envFrom, without pasting credentials into someone else's server. The broader .env converter writes the same variables as a ConfigMap, JSON, YAML or Terraform variables.

Know what a Secret is and isn't: values are base64-encoded, which is an encoding, not encryption. Anyone who can read the Secret object can read the value. Enable encryption at rest for Secrets in the cluster, restrict access with RBAC, and don't commit plain Secret manifests to Git — use Sealed Secrets, SOPS, or an external secrets manager.

Logs

On a single server, applications often write log files to disk. In Kubernetes, write logs to standard output and standard error. The cluster collects them, and files inside a container disappear when the pod is replaced.

Scheduled jobs

Cron jobs that ran on the old server — backups, cleanup scripts, reports — usually live outside the Compose file entirely, in the host's crontab. They're easy to forget. Each one becomes a CronJob, and the cron to Kubernetes CronJob converter writes the manifest from a crontab line.

Two details matter:

  • Time zone. The old server's cron ran in its local time. A CronJob's schedule is interpreted in the controller's time zone (UTC on most clusters) unless you set spec.timeZone, such as Europe/Paris. A job that ran at 2 a.m. local time will otherwise run at a different hour.
  • Overlap. Cron happily starts a new run while the previous one is still going. Set concurrencyPolicy: Forbid for jobs that shouldn't overlap.

If you're moving jobs to a cloud scheduler instead, the cron expression converter translates the schedule to other formats, such as EventBridge's six-field syntax and systemd timers.

A migration order that works

  1. Capture every container in Compose and prove it runs from scratch.
  2. Make services retry connections; add health check endpoints.
  3. Move configuration into environment variables and files you can mount.
  4. Convert to manifests and review every note.
  5. Move secrets into Secrets, with encryption at rest.
  6. Decide where the database lives — ideally a managed service.
  7. Deploy to a staging namespace and run the test suite against it.
  8. Move scheduled jobs, with explicit time zones.
  9. Cut over traffic, keeping the old host running until you're confident.

Compose files are a good starting point because they already describe the system as code. The conversion is quick; the work is in removing the single-server assumptions the Compose file never had to state.

About the author

Abdessamad Bettal, full-stack engineer and the developer of migration.tools — free, private, browser-based tools for moving databases, data, websites and content between systems.

LinkedIn GitHub