Deploy Podman containers with Kubernetes YAML manifests and kubectl integration

Intermediate 25 min Apr 18, 2026 126 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Learn how to deploy and manage Podman containers using Kubernetes YAML manifests with kubectl integration. This tutorial covers systemd user services, YAML generation, pod networking, and volume management.

Prerequisites

  • Basic Linux command line knowledge
  • Understanding of containers and containerization concepts
  • Familiarity with YAML syntax

What this solves

Podman provides Kubernetes-compatible container orchestration without requiring a full Kubernetes cluster. This approach lets you use familiar kubectl commands and Kubernetes YAML manifests to manage containers locally while maintaining the security benefits of rootless containers.

You get the declarative configuration model of Kubernetes with the simplicity and security of Podman, making it ideal for development environments, edge deployments, or single-node production setups that don't need the complexity of a full Kubernetes cluster.

Step-by-step configuration

Update system packages

Start by updating your package manager to ensure you get the latest container tools.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install Podman and kubectl

Install Podman for container management and kubectl for Kubernetes-style commands.

sudo apt install -y podman curl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
sudo dnf install -y podman curl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

Configure systemd user services

Enable lingering for your user to allow systemd user services to run without being logged in.

sudo loginctl enable-linger $USER
systemctl --user enable podman.socket
systemctl --user start podman.socket

Set up Podman systemd integration

Configure Podman to work with systemd for automatic container management and service integration.

mkdir -p ~/.config/systemd/user
echo 'export DOCKER_HOST=unix:///run/user/'$UID'/podman/podman.sock' >> ~/.bashrc
source ~/.bashrc

Create a sample application

Set up a simple web application to demonstrate Kubernetes YAML deployment with Podman.

mkdir -p ~/podman-k8s-demo
cd ~/podman-k8s-demo

Create Kubernetes deployment YAML

Define a Kubernetes deployment manifest for a sample NGINX application with proper resource limits and labels.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: docker.io/nginx:latest
        ports:
        - containerPort: 80
        resources:
          limits:
            memory: "256Mi"
            cpu: "500m"
          requests:
            memory: "128Mi"
            cpu: "250m"
        volumeMounts:
        - name: nginx-config
          mountPath: /etc/nginx/nginx.conf
          subPath: nginx.conf
      volumes:
      - name: nginx-config
        configMap:
          name: nginx-config

Create Kubernetes service YAML

Define a service to expose the NGINX deployment with proper port mapping and service discovery.

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    app: nginx
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 30080
  type: NodePort

Create ConfigMap for custom configuration

Set up a ConfigMap to demonstrate volume mounting and configuration management.

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
data:
  nginx.conf: |
    events {
        worker_connections 1024;
    }
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
        sendfile      on;
        keepalive_timeout 65;
        server {
            listen       80;
            server_name  localhost;
            location / {
                root   /usr/share/nginx/html;
                index  index.html index.htm;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   /usr/share/nginx/html;
            }
        }
    }

Generate Podman containers from Kubernetes YAML

Use Podman to create containers directly from Kubernetes manifests without a cluster.

podman play kube nginx-configmap.yaml
podman play kube nginx-deployment.yaml
podman play kube nginx-service.yaml

Create systemd services from Kubernetes YAML

Generate systemd service files for automatic startup and management of your Kubernetes workloads.

podman generate systemd --new --files --name nginx-deployment-nginx
mv *.service ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable pod-nginx-deployment.service
systemctl --user start pod-nginx-deployment.service

Set up kubectl integration with Podman

Configure kubectl to work with Podman by creating a kubeconfig that points to Podman's API.

mkdir -p ~/.kube
cat > ~/.kube/config << EOF
apiVersion: v1
kind: Config
clusters:
  • cluster:
server: unix:///run/user/$UID/podman/podman.sock name: podman contexts:
  • context:
cluster: podman user: podman name: podman current-context: podman users:
  • name: podman
EOF

Configure pod networking

Set up pod networking to allow communication between containers and expose services properly.

podman network create --driver bridge podman-k8s
echo 'podman-k8s network created for Kubernetes-style networking'

Create persistent volume configuration

Set up persistent volumes for stateful applications that need data persistence.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-storage
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/tmp/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

Deploy application with persistent storage

Create the storage directory and deploy the persistent volume configuration.

sudo mkdir -p /tmp/data
sudo chown $USER:$USER /tmp/data
chmod 755 /tmp/data
podman play kube persistent-volume.yaml
Never use chmod 777. It gives every user on the system full access to your files. Instead, fix ownership with chown and use minimal permissions like 755 for directories.

Verify your setup

Test that your Podman Kubernetes integration is working correctly.

podman pod list
podman ps -a
systemctl --user status pod-nginx-deployment.service
curl http://localhost:30080
podman logs nginx-deployment-nginx

You can also use kubectl-style commands if you have the integration configured:

podman version
podman info | grep -A5 "network"
podman network ls

Managing your deployment

Update deployment with new YAML

Modify your YAML files and redeploy to update your running containers.

podman play kube --replace nginx-deployment.yaml
systemctl --user restart pod-nginx-deployment.service

Scale your deployment

Modify the replicas field in your deployment YAML and redeploy to scale containers.

sed -i 's/replicas: 2/replicas: 3/' nginx-deployment.yaml
podman play kube --replace nginx-deployment.yaml

Clean up deployment

Remove the deployment and associated resources when no longer needed.

systemctl --user stop pod-nginx-deployment.service
systemctl --user disable pod-nginx-deployment.service
podman play kube --down nginx-deployment.yaml
podman play kube --down nginx-service.yaml
podman play kube --down nginx-configmap.yaml

Common issues

SymptomCauseFix
kubectl commands failPodman socket not runningsystemctl --user start podman.socket
Containers exit immediatelyResource limits too restrictiveIncrease memory/CPU limits in YAML
Service not accessiblePort mapping incorrectCheck podman port output and service YAML
Volume mount permission deniedIncorrect directory ownershipchown $USER:$USER /path/to/volume and chmod 755
Systemd service fails to startPod definition changedRegenerate service files with podman generate systemd
Network connectivity issuesContainer network misconfiguredRecreate with podman network create

Next steps

Running this in production?

Want this handled for you? Setting this up once is straightforward. Keeping it patched, monitored, backed up and performant across environments is the harder part. See how we run infrastructure like this for European teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.