Containers and Kubernetes · Intermediate · 18 min
Move a Compose app to Podman pods and Kubernetes YAML
By Padding · Updated 26 Nov 2026
Ubuntu 26.04 · Podman 5.7 (Ubuntu archive) · kubeconform 0.8.0
You will run a Node.js app and PostgreSQL 18 together in one rootless Podman pod, export it as Kubernetes YAML, tidy that YAML until kubeconform accepts it, and recreate the app from the file with podman kube play.
On this page
A Compose file describes services that Docker connects over a private network and finds by name. Kubernetes describes pods: groups of containers that share one network, so they reach each other on localhost. Podman sits between the two. It runs pods on a single machine without a daemon, writes a running pod out as Kubernetes YAML, and plays that YAML back. That makes it a practical half-way house when you want to leave Compose but are not ready for a cluster.
In this tutorial you take the page-counter app from /tutorials/docker-compose-app-with-postgres (a small Node.js app that stores hits in PostgreSQL 18) and run it in a rootless Podman 5.7 pod. You then generate Kubernetes YAML from the pod, clean it up until kubeconform accepts it against Kubernetes 1.37 schemas, and recreate the app from the cleaned file. Along the way you see which parts of Compose have no direct equivalent.
Run every command as your normal user, not with sudo, unless the command shows sudo. If rootless Podman is new to you, read /tutorials/run-rootless-containers-with-podman first; it explains the user namespaces that make this work.
Step 1 · Install Podman and set up the project folder
Install Podman and curl from the Ubuntu archive:
sudo apt update
sudo apt install -y podman curl
podman --versionThe last command prints podman version 5.7.0. Ubuntu 26.04 ships the 5.7 series; the upstream project has moved on to 6.x, so newer documentation may show options that 5.7 does not have. When in doubt, read the man page on your machine (man podman-kube-play).
Make a fresh folder for this tutorial and copy the app files into it. Replace ~/hits-app with wherever you kept the folder from the Compose tutorial:
mkdir -p ~/hits-pod-demo
cp ~/hits-app/server.js ~/hits-app/package.json ~/hits-app/package-lock.json ~/hits-pod-demo/
cd ~/hits-pod-demo
lsThe app reads its connection string from DATABASE_URL. The PostgreSQL client it uses, node-postgres, also reads the standard PGPASSWORD variable when the connection string has no password. You use that below to keep the password out of every URL.
Check it worked
podman --version shows 5.7, and ls in ~/hits-pod-demo lists package-lock.json, package.json and server.js.
Step 2 · Build the app image with Podman
Compose built the image for you because the file said build: .. Podman pods and Kubernetes YAML only name images, so you build the image yourself first.
Write a Containerfile. It matches the Dockerfile from the Compose tutorial with one change: the base image name is fully qualified. Podman will not guess a registry for a short name such as node:26-slim unless your registries configuration tells it to, and naming docker.io removes the guesswork:
cat > Containerfile <<'EOF'
FROM docker.io/library/node:26-slim
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
COPY server.js ./
ENV NODE_ENV=production
EXPOSE 3000
USER node
CMD ["node", "server.js"]
EOF
podman build -f Containerfile -t localhost/hits-web:1 .The localhost/ prefix is how Podman marks an image that exists only on this machine. The base images are the largest download in this tutorial. On prepaid mobile data, run this step and the next one on Wi-Fi if you can; later runs reuse the images already on disk.
Check it worked
podman images localhost/hits-webOne row appears, with the tag 1.
Step 3 · Create a pod and run PostgreSQL in it
Generate the database password once and keep it in a private file. The file is created with mode 600 before anything is written to it, and tr removes the trailing newline so the stored value is exactly 32 characters:
cd ~/hits-pod-demo
install -m 600 /dev/null pgpass
openssl rand -hex 16 | tr -d '\n' > pgpass
podman secret create hits-pgpass pgpassA Podman secret is stored outside any container and handed to a container only when you ask for it, so the password never appears on a command line or in your shell history.
Create the pod. Ports belong to the pod, not to the containers in it, and you cannot add them later, so publish the app's port now. 127.0.0.1:8080 keeps it reachable from this machine only:
podman pod create --name hits -p 127.0.0.1:8080:3000
podman volume create hits-dbdataStart PostgreSQL inside the pod. --secret ...,type=env,target=POSTGRES_PASSWORD turns the secret into the environment variable the image reads on first start. The volume is mounted at /var/lib/postgresql, the parent folder the PostgreSQL 18 image expects:
podman run -d --pod hits --name hits-db \
--secret hits-pgpass,type=env,target=POSTGRES_PASSWORD \
-e POSTGRES_USER=app -e POSTGRES_DB=appdb \
-v hits-dbdata:/var/lib/postgresql \
docker.io/library/postgres:18Compose waited for the database with depends_on and a health check. A pod has no such ordering, so wait by hand, for at most a minute:
timeout 60 sh -c 'until podman exec hits-db pg_isready -h 127.0.0.1 -U app -d appdb; do sleep 2; done'Check it worked
The wait ends with a line like 127.0.0.1:5432 - accepting connections. Then:
podman pod psThe hits pod is listed as running with 2 containers: hits-db and the small infra container that holds the pod's shared network.
Step 4 · Add the app to the pod
Every container in a pod shares one network namespace, so the app reaches PostgreSQL on 127.0.0.1:5432. There is no service name like db to resolve. The connection string has no password; the secret arrives as PGPASSWORD:
podman run -d --pod hits --name hits-web \
--secret hits-pgpass,type=env,target=PGPASSWORD \
-e DATABASE_URL=postgres://app@127.0.0.1:5432/appdb \
localhost/hits-web:1Check it worked
curl -s http://127.0.0.1:8080/
curl -s http://127.0.0.1:8080/
podman ps --pod --format '{{.Names}} {{.PodName}} {{.Status}}'The requests print something like {"hits":1,"service":"web"} and {"hits":2,"service":"web"}. The service field is there if you did the change step in the Compose tutorial; without it you see {"hits":1} and {"hits":2}. The list shows hits-db and hits-web in the pod hits, both Up, next to the infra container. If the app is not up, podman logs hits-web shows why; a connection error usually means the database was not ready yet, and podman start hits-web tries again.
Step 5 · Generate Kubernetes YAML from the running pod
Ask Podman to describe the running pod as Kubernetes YAML:
podman kube generate hits -f hits-generated.yaml-f refuses to overwrite an existing file, so delete hits-generated.yaml first if you run this twice. Open the file in your editor and look for these parts:
kind: Podwith two containers. Their names come from your containers, and the infra container is left out.image:lines namingdocker.io/library/postgres:18andlocalhost/hits-web:1.persistentVolumeClaimwithclaimName: hits-dbdata. Podman writes named volumes as claims but does not write the claim object itself.- A
portsentry withcontainerPort: 3000andhostPort: 8080. - Environment variables you set, written as plain values, and extra annotations and fields that only Podman uses.
Podman may or may not have written the secret's value into the file. Check without printing the password:
grep -c -F -f pgpass hits-generated.yamlThe number is how many lines contain the password. If it is anything other than 0, treat hits-generated.yaml as a secret: do not commit it or paste it anywhere. Either way, you will not use it directly.
Check it worked
hits-generated.yaml exists, contains kind: Pod, and you know whether it holds the password. A quick way to see the structure without the values:
grep -n -E 'kind:|name:|image:|claimName:|containerPort:|hostPort:' hits-generated.yamlStep 6 · Tidy the YAML for a real cluster
The generated file is a snapshot of one pod on one machine. A cluster needs a few changes, and this is where the parts of Compose that do not carry over show up:
build:has no equivalent. Kubernetes only pulls images, so you build and push them yourself. Podman'skube playhas one shortcut: if a folder in the current directory has the same name as the image and holds a Containerfile, it builds that image. A cluster never does this.depends_onhas no equivalent. Containers in a pod start without waiting for each other. The app either retries its connection or exits and is restarted, which the defaultrestartPolicy: Alwaysdoes for you.profileshave no equivalent. Keep optional pieces in separate YAML files and apply only the ones you need.healthcheckbecomes liveness, readiness and startup probes, which are configured differently; see/tutorials/keep-snip-healthy-with-probes-and-graceful-shutdown..envinterpolation does not exist. Values either sit in the YAML or come from a Secret or ConfigMap.
Write the cleaned files by hand. First the Deployment, which is safe to commit because it holds no secrets. It uses a Deployment so the cluster replaces the pod if it dies, replicas: 1 with the Recreate strategy because a single PostgreSQL volume cannot be shared by two pods at once, no hostPort, and passwords read from a Secret called hits-db:
cat > hits.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: hits
labels:
app: hits
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: hits
template:
metadata:
labels:
app: hits
spec:
containers:
- name: db
image: docker.io/library/postgres:18
env:
- name: POSTGRES_USER
value: app
- name: POSTGRES_DB
value: appdb
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: hits-db
key: password
volumeMounts:
- name: dbdata
mountPath: /var/lib/postgresql
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
memory: 512Mi
- name: web
image: localhost/hits-web:1
env:
- name: DATABASE_URL
value: postgres://app@127.0.0.1:5432/appdb
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: hits-db
key: password
ports:
- containerPort: 3000
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
memory: 256Mi
volumes:
- name: dbdata
persistentVolumeClaim:
claimName: hits-dbdata
EOFNext the claim, in its own file. A cluster needs it to provide storage. Podman does not: on this machine the claim name already points at the hits-dbdata volume, so you keep this file for the cluster only:
cat > hits-pvc.yaml <<'EOF'
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: hits-dbdata
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
EOFLast, the Secret, built from the same pgpass file so the password matches the one already stored in the database volume. Kubernetes stores Secret values base64-encoded, which is an encoding, not encryption, so this file is created private and must never be committed:
install -m 600 /dev/null hits-secret.yaml
cat >> hits-secret.yaml <<EOF
apiVersion: v1
kind: Secret
metadata:
name: hits-db
type: Opaque
data:
password: $(base64 -w0 pgpass)
EOFIf the folder is a Git repository, add pgpass, hits-secret.yaml and hits-generated.yaml to .gitignore now.
Check it worked
ls -l hits.yaml hits-pvc.yaml hits-secret.yaml
grep -c hostPort hits.yamlhits-secret.yaml has mode -rw-------, and the grep prints 0.
Step 7 · Check the YAML with kubeconform
kubeconform checks manifests against the Kubernetes API schemas without a cluster. Download the v0.8.0 release and its checksum file from GitHub and check the archive before installing it. A binary installed this way gets no apt updates; to upgrade later, repeat this step with a newer version:
VERSION=0.8.0
case "$(uname -m)" in
x86_64) ARCH=amd64 ;;
aarch64) ARCH=arm64 ;;
*) echo "Unsupported processor: $(uname -m)"; false ;;
esac
TMP=$(mktemp -d)
cd "$TMP"
curl -fsSLO "https://github.com/yannh/kubeconform/releases/download/v${VERSION}/kubeconform-linux-${ARCH}.tar.gz"
curl -fsSLO "https://github.com/yannh/kubeconform/releases/download/v${VERSION}/CHECKSUMS"
grep " kubeconform-linux-${ARCH}.tar.gz\$" CHECKSUMS | sha256sum -c
tar -xzf "kubeconform-linux-${ARCH}.tar.gz" kubeconform
mkdir -p ~/.local/bin
install -m 0755 kubeconform ~/.local/bin/
export PATH="$HOME/.local/bin:$PATH"
cd ~/hits-pod-demo
rm -rf "$TMP"The sha256sum line must print kubeconform-linux-<arch>.tar.gz: OK. If it prints FAILED, stop and download again.
Validate the three tidy files against Kubernetes 1.37. -strict also rejects fields the schema does not know and keys written twice, the two mistakes hand-edited YAML makes most often:
kubeconform -strict -summary -kubernetes-version 1.37.0 hits.yaml hits-pvc.yaml hits-secret.yamlkubeconform downloads one small JSON schema per kind the first time, so it needs a network connection.
For comparison, run the same check on the raw generated file and read what it reports:
kubeconform -strict -summary -kubernetes-version 1.37.0 hits-generated.yamlWhatever it says, schema checks only prove the YAML has the right shape. They do not tell you that hostPort ties the pod to one node or that localhost/hits-web:1 cannot be pulled by a cluster, which is why you tidied by hand.
Check it worked
The first command ends with Summary: 3 resources found in 3 files - Valid: 3, Invalid: 0, Errors: 0, Skipped: 0. If a resource is invalid, the line above the summary names the file, the kind and the field.
Step 8 · Recreate the app from YAML with podman kube play
Remove the hand-built pod. The volume stays, so the hit count survives:
podman pod rm -f hits
podman volume lsLoad the Secret first. Podman stores a Kubernetes Secret as a Podman secret with the same name, which secretKeyRef then reads:
podman kube play hits-secret.yamlPlay the Deployment. The YAML no longer has a hostPort, so --publish adds one for this machine, matched to the containerPort 3000 in the file:
podman kube play --publish 127.0.0.1:8080:3000 hits.yamlPodman creates one pod from the Deployment and starts both containers. If the app starts before PostgreSQL is ready it exits and is restarted, so give it a moment:
timeout 60 sh -c 'until curl -fs http://127.0.0.1:8080/; do sleep 2; done'; echoTo run the same files on another machine with Podman, copy hits.yaml across, copy hits-secret.yaml over SSH (it holds the password), and send the image with podman image scp localhost/hits-web:1 <user>@<host>:: (replace the user and host). The data stays in this machine's volume; the other machine starts with an empty database. To keep the pod running across reboots, a Quadlet .kube file can run hits.yaml as a systemd service, as in /tutorials/run-podman-containers-as-systemd-services-with-quadlet.
For a real cluster, push the image to a registry the cluster can pull from, change localhost/hits-web:1 to that image name, and apply hits-secret.yaml, hits-pvc.yaml and hits.yaml with kubectl apply -f. Keeping the app and its database in one pod means they always run and scale together; on a cluster you would usually split PostgreSQL into its own StatefulSet and Service, as in /tutorials/run-postgresql-for-snip-in-a-statefulset.
Check it worked
The curl loop prints a count that carries on from before, such as {"hits":3,"service":"web"} (or {"hits":3} if your server.js has no service field), because the new pod uses the same hits-dbdata volume. podman pod ps lists a new running pod whose name starts with hits.
Step 9 · Clean up
--down stops and removes everything that kube play created from the file. Without --force it leaves the volume alone:
cd ~/hits-pod-demo
podman kube play --down hits.yaml
podman secret lsThe next commands delete the database volume with all its data, the secrets, the images and the project folder with the password file. Run them only when you no longer need any of it. If podman secret ls still listed hits-db, also run podman secret rm hits-db.
podman volume rm hits-dbdata
podman secret rm hits-pgpass
podman rmi localhost/hits-web:1 docker.io/library/postgres:18 docker.io/library/node:26-slim
cd ~
rm -rf ~/hits-pod-demoIf you will not use kubeconform again, remove it with rm ~/.local/bin/kubeconform.
Check it worked
podman pod ps -a
podman volume ls
podman secret lsNo hits pod, volume or secret is listed.
Next steps
- Learn the rootless model behind every command here in
/tutorials/run-rootless-containers-with-podman. - Put the app on a real cluster with
/tutorials/deploy-and-expose-an-app-on-kubernetes.
Related tutorials
- Run rootless containers with Podman on UbuntuYou will install Podman 5.7 on Ubuntu 26.04, run an Nginx container as your own user with no daemon and no root, see how user namespaces map its users to your subordinate ID range, and know where the Docker alias and podman compose stop matching Docker.
- How to Run an App and PostgreSQL Together with Docker ComposeYou will describe a Node.js app and a PostgreSQL 18 database in one compose.yaml, start both with one command, keep the data in a named volume, and keep the database password out of the file.
- How to Deploy an App and Expose It with a Service on KubernetesYou will run an app on Kubernetes 1.37 as a Deployment with two replicas, watch it heal itself, give it a stable address with a Service, reach it from your computer, and roll out a new version with a way back.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials