Podman play kube – How to run a pod from a yaml file

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.

Pull pause image

podman pull k8s.gcr.io/pause:3.5

Create a file named configmap.yaml to hold environment variables values

apiVersion: v1
kind: ConfigMap
metadata:
  name: config
data:
  # MySQL Container Envrionment Variables
  MYSQL_ROOT_PASSWORD: welcome123 # MySQL root password
  MYSQL_DATABASE: wordpress # WordPress Database Name
  MYSQL_USER: wordpress # WordPress Database User
  MYSQL_PASSWORD: welcome123 # WordPress Database User Password
  # WordPress Container Envrionment Variables
  WORDPRESS_DB_HOST: 127.0.0.1 # MySQL Host
  WORDPRESS_DB_PASSWORD: welcome123 # DB Password
  WORDPRESS_DB_USER: wordpress # DB User

Create a file named pod.yaml to mention the containers belong to the pod.

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
    - 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
  restartPolicy: Never

Run below command to create the pod

podman play kube --configmap configmap.yaml pod.yaml 

Terminal output for reference

$ podman play kube --configmap configmap.yaml pod.yaml 
Pod:
38b5cc9742f15ef77e1d12711af6fb3ef04b8f962b297a2ac8483f86cc90dcc3
Containers:
308ee2933cb602657dc168a1ce5d95fc48ee57b7757d05414bbb878a3cadb901
c97efa9eb6bf4b87b8e963895f0fb7e801dae3ba35c730f68fea6c16cb297683

Check the pod running status

podman pod ls

Terminal output for reference

ability@abb:~/scripts$ podman pod ls
POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
38b5cc9742f1  wordpress   Running     10 seconds ago  a03b5dece28a  3

Check the containers running using below command

podman ps

Terminal output for reference

$ podman ps 
CONTAINER ID  IMAGE                                     COMMAND               CREATED        STATUS            PORTS                                         NAMES
a03b5dece28a  k8s.gcr.io/pause:3.5                                            4 minutes ago  Up 4 minutes ago  0.0.0.0:8080->80/tcp, 0.0.0.0:3306->3306/tcp  38b5cc9742f1-infra
308ee2933cb6  docker.io/library/mysql:8.0               mysqld                4 minutes ago  Up 4 minutes ago  0.0.0.0:8080->80/tcp, 0.0.0.0:3306->3306/tcp  wordpress-db
c97efa9eb6bf  docker.io/library/wordpress:6.2.1-apache  apache2-foregroun...  4 minutes ago  Up 4 minutes ago  0.0.0.0:8080->80/tcp, 0.0.0.0:3306->3306/tcp  wordpress-ui

Open url http://<host_ip>:8080 in browser to access wordpress application. Installation workflow is displayed on the page.

Wordpress Installation - Select Language