Skip to main content

The podman play kube command now supports deployments

Work back and forth between Podman and Kubernetes.
Image
Yellow parachutes ready for deployment

One of the most exciting features we've added to Podman is support for interacting with Kubernetes objects. With the podman generate kube command, Podman can export your existing containers into Kubernetes Pod YAML for import into an OpenShift or Kubernetes cluster. The podman play kube command does the opposite, taking Kubernetes YAML and running it in Podman. Initially, the play kube command only supported running Pod YAML. However, most Kubernetes users prefer using the more-flexible Deployment YAML, which we did not support. With the Podman v2.0 release, we've addressed this, and Deployment YAML can now be used with the podman play kube command.

Migrations

When we first added podman generate kube and podman play kube, we intended to provide a way to ease migration to Kubernetes. Podman only runs containers on a single node, which means that users often outgrow it as their workloads increase. We wanted to give cluster admins an easy on-ramp to move their work to Kubernetes, an industry-standard solution for managing containers across many nodes. The podman generate kube command makes this possible. We added podman play kube to complement this by allowing developers to test their new YAML locally before deploying it. Our latest support for Deployments makes this much more usable.

Example

Let’s look at an example Deployment from the Kubernetes documentation:

$ cat ./nginx-deployment.yaml  
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

We can easily run this with podman play kube:

$ podman play kube ./nginx-deployment.yaml                                                                        
Trying to pull docker.io/library/nginx:1.14.2...
Getting image source signatures
Copying blob 27833a3ba0a5 done   
Copying blob 0f23e58bd0b7 done   
Copying blob 8ca774778e85 done   
Copying config 295c7be079 done   
Writing manifest to image destination
Storing signatures
Pod:
b4a261247bb458a6be85c600368c5563d086ac1925f4b4f2760bff6b74cd5084
Container:
d969453f4cc39a90a3d3cdcb0429851ea2f4a1e6a9e0deddef0e75204238fa1a
 
Pod:
6e838493599b1b93ca61b30e9bd4a783fc0d5fa5cb9544c8321e499668b1f318
Container:
1548c6b6420108dd13fe237c5da7f120f544293dfc2003f8c30b53dd6e94db39
 
Pod:
7e1a842a18d3cdc423b5408f4353a39ecd87819afcde5f0724842ca62b38bc5c
Container:
1506e5fc3f217403a866de2aaa961a667a423b392efdcc29c197934a5074a039

You can see that the YAML specifies three replicas, so Podman created three pods, each with one container. Let’s do a quick podman ps to see what it made:

$ podman ps -a
CONTAINER ID  IMAGE                 COMMAND               CREATED         STATUS             PORTS   NAMES
0c3fa04969f7  nginx:1.14.2         /docker-entrypoin...  14 seconds ago  Up 13 seconds ago          nginx-deployment-pod-0-nginx
1b50823b01b9  k8s.gcr.io/pause:3.2                        11 seconds ago  Up 8 seconds ago           b461352502f0-infra
56b683ea398b  nginx:1.14.2          /docker-entrypoin...  8 seconds ago   Up 8 seconds ago           nginx-deployment-pod-2-nginx
83276e1e562b  k8s.gcr.io/pause:3.2                        15 seconds ago  Up 13 seconds ago          16d50303cb06-infra
cb7c430f65d1  nginx:1.14.2          /docker-entrypoin...  11 seconds ago  Up 11 seconds ago          nginx-deployment-pod-1-nginx
fe6eefdfd7c4  k8s.gcr.io/pause:3.2                        13 seconds ago  Up 11 seconds ago          288bcb7e5f7c-infra

You can see three infra (Pause) containers and three Nginx containers, one of each per pod, all of them running. Success!

Future plans

Unfortunately, while we can now run deployments with podman play kube, we can't create them yet. The podman generate kube command is not yet able to output Deployment YAML. We plan on working on this for a future release, but contributions are always welcome.

Community contribution

One of the best things about this new feature is that it was added by a community member, Aditya Kamath. The Podman Project is very thankful for the contribution. It is more proof of the power of open source.

[ Getting started with containers? Check out this free course. Deploying containerized applications: A technical overview. ]

Topics:   Containers   Podman  
Author’s photo

Matthew Heon

Matt Heon has been a software engineer on Red Hat's Container Runtimes team for the last five years. He's one of the original authors and lead maintainers of the Podman project. He focuses on container security, networking, and low-level development. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the Red Hat Developer program.