Podman play kube – How to use volumes for data persistence

Podman (the POD manager) is an open source tool for developing, managing, and running containers on Linux systems.

podman play kube will read in a structured file of Kubernetes YAML. It will then recreate the containers, pods or volumes described in the YAML. Containers within a pod are then started and the ID of the new Pod or the name of the new Volume is the output.

Please refer Podman installation on Ubuntu 22.04 for installation of podman on Ubuntu.

Please refer Podman play kube โ€“ How to run a pod from a yaml file for running a pod using play kube.

Modify pod.yaml to include volumes for containers

apiVersion: v1
kind: Pod
metadata:
  labels:
    app: wordpress
  name: wordpress
spec:
  containers:
    - image: docker.io/mysql:8.0 # MySQL Image
      name: db
      envFrom:
        - configMapRef:
            name: config # Load Environment Variables from ConfigMap
      ports:
        - containerPort: 3306 # MySQL Container Port
          hostPort: 3306 # MySQL Host Port
          name: mysql
      volumeMounts:
      - mountPath: /var/lib/mysql # directory in the container which is mounted
        name: wordpress-db # volume name
    - image: docker.io/wordpress:6.2.1-apache # WordPress Image
      name: ui
      ports:
        - containerPort: 80 # WordPress Container Port
          hostPort: 8080 # WordPress Host Port
          name: wordpress
      envFrom:
        - configMapRef:
            name: config # Load Environment Variables from ConfigMap
      volumeMounts:
      - name: wordpress-ui # volume name
        mountPath: /var/www/html # directory in the container which is mounted
  restartPolicy: Always
  volumes:
    - name: wordpress-db # volume name for db
      hostPath:
        path: /home/hyrule/pod-volumes/wordpress-db # host path for db volume, change accordingly
        type: Directory
    - name: wordpress-ui
      hostPath:
        path: /home/hyrule/pod-volumes/wordpress-ui # host path for ui volume, change accordingly
        type: Directory

Create directories in host system. Change below command accordingly based on pod.yaml

mkdir -p  /home/hyrule/pod-volumes/wordpress-db
mkdir -p /home/hyrule/pod-volumes/wordpress-ui