8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » Linux » Here

Podman : Generate and Play Kubernetes YAML Files

Podman can generate Kubernetes YAML files from existing pod definitions, and use the generated YAML files to fire up new pods. This allows us to define multi-container applications with a single file, similar to Docker Compose files.

Related articles.

Setup

Let's assume we start with the build described in this article.

This leaves us with the following pod.

$ podman pod list
POD ID         NAME     STATUS    CREATED          # OF CONTAINERS   INFRA ID
9a42ad992aa6   my_pod   Running   16 minutes ago   3                 74a62f158f25
$

If we inspect it, we can see the internal structure of the pod.

$ podman pod inspect my_pod
{
     "Config": {
          "id": "9a42ad992aa60aae21d97f8c7a21c1fcbe63a216dfa566d984b5a758f831dd72",
          "name": "my_pod",
          "hostname": "my_pod",
          "labels": {

          },
          "cgroupParent": "machine.slice",
          "sharesCgroup": true,
          "sharesIpc": true,
          "sharesNet": true,
          "sharesUts": true,
          "infraConfig": {
               "makeInfraContainer": true,
               "infraPortBindings": [
                    {
                         "hostPort": 1521,
                         "containerPort": 1521,
                         "protocol": "tcp",
                         "hostIP": ""
                    },
                    {
                         "hostPort": 5500,
                         "containerPort": 5500,
                         "protocol": "tcp",
                         "hostIP": ""
                    },
                    {
                         "hostPort": 8080,
                         "containerPort": 8080,
                         "protocol": "tcp",
                         "hostIP": ""
                    },
                    {
                         "hostPort": 8443,
                         "containerPort": 8443,
                         "protocol": "tcp",
                         "hostIP": ""
                    }
               ]
          },
          "created": "2020-05-26T19:29:31.527520579Z",
          "lockID": 0
     },
     "State": {
          "cgroupPath": "machine.slice/machine-libpod_pod_9a42ad992aa60aae21d97f8c7a21c1fcbe63a216dfa566d984b5a758f831dd72.slice",
          "infraContainerID": "74a62f158f25a7cf1ee970afec08dbcd34a51f6954f5146a8080bfe16ca1ddef"
     },
     "Containers": [
          {
               "id": "3636bbe053445b989a1ffed12e044229c6cd8c9b56e3c640781f9d95a2aa6276",
               "state": "running"
          },
          {
               "id": "3dfe524b96dc9e785cd3954e4ec7bf0a584aef695b2200dde53ad7b89090017b",
               "state": "running"
          },
          {
               "id": "74a62f158f25a7cf1ee970afec08dbcd34a51f6954f5146a8080bfe16ca1ddef",
               "state": "running"
          }
     ]
}
$

The running containers look like this.

$ podman ps -a
CONTAINER ID  IMAGE                      COMMAND               CREATED         STATUS             PORTS                   NAMES
3636bbe05344  localhost/ol8_ords:latest  /bin/sh -c exec $...  17 minutes ago  Up 17 minutes ago  0.0.0.0:1521->1521/tcp  ol8_ords_con
3dfe524b96dc  localhost/ol8_19:latest    /bin/sh -c exec $...  17 minutes ago  Up 17 minutes ago  0.0.0.0:1521->1521/tcp  ol8_19_con
74a62f158f25  k8s.gcr.io/pause:3.1                             17 minutes ago  Up 17 minutes ago  0.0.0.0:1521->1521/tcp  9a42ad992aa6-infra
$

Generate a Kubernetes YAML File

We create a Kubernetes YAML file using the podman generate kube command. By default the output is directed to stdout, but the "-f" flag directs the output to a named file.

$ podman generate kube my_pod -f /tmp/my_pod_kube.yaml

The resulting file contains the following information.

# Generation of Kubernetes YAML is still under development!
#
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-1.6.4
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2020-05-26T19:48:06Z"
  labels:
    app: mypod
  name: mypod
spec:
  containers:
  - command:
    - /bin/sh
    - -c
    - exec ${SCRIPTS_DIR}/start.sh
    env:
    - name: PATH
      value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    - name: TERM
      value: xterm
    - name: HOSTNAME
      value: my_pod
    - name: container
      value: podman
    - name: SOFTWARE_DIR
      value: /u01/software
    - name: DB_PORT
      value: "1521"
    - name: KEYSTORE_PASSWORD
      value: KeystorePassword1
    - name: PROXY_IPS
      value: 123.123.123.123\|123.123.123.124
    - name: DB_SERVICE
      value: pdb1
    - name: CATALINA_HOME
      value: /u01/tomcat/latest
    - name: CATALINA_BASE
      value: /u01/config/instance1
    - name: KEYSTORE_DIR
      value: /u01/keystore
    - name: ORDS_HOME
      value: /u01/ords
    - name: TEMP_TABLESPACE
      value: TEMP
    - name: SYS_PASSWORD
      value: SysPassword1
    - name: SQLCL_SOFTWARE
      value: sqlcl-19.4.0.354.0937.zip
    - name: DB_HOSTNAME
      value: localhost
    - name: APEX_REST_PASSWORD
      value: ApexPassword1
    - name: PUBLIC_PASSWORD
      value: ApexPassword1
    - name: SCRIPTS_DIR
      value: /u01/scripts
    - name: APEX_TABLESPACE
      value: APEX
    - name: AJP_SECRET
      value: AJPSecret1
    - name: APEX_IMAGES_REFRESH
      value: "false"
    - name: JAVA_SOFTWARE
      value: OpenJDK11U-jdk_x64_linux_hotspot_11.0.7_10.tar.gz
    - name: APEX_PUBLIC_USER_PASSWORD
      value: ApexPassword1
    - name: APEX_LISTENER_PASSWORD
      value: ApexPassword1
    - name: TOMCAT_SOFTWARE
      value: apache-tomcat-9.0.34.tar.gz
    - name: APEX_SOFTWARE
      value: apex_20.1_en.zip
    - name: ORDS_CONF
      value: /u01/ords/conf
    - name: JAVA_HOME
      value: /u01/java/latest
    - name: ORDS_SOFTWARE
      value: ords-19.4.0.352.1226.zip
    image: localhost/ol8_ords:latest
    name: ol8ordscon
    ports:
    - containerPort: 1521
      hostPort: 1521
      protocol: TCP
    - containerPort: 5500
      hostPort: 5500
      protocol: TCP
    - containerPort: 8080
      hostPort: 8080
      protocol: TCP
    - containerPort: 8443
      hostPort: 8443
      protocol: TCP
    resources: {}
    securityContext:
      allowPrivilegeEscalation: true
      capabilities: {}
      privileged: false
      readOnlyRootFilesystem: false
      runAsUser: 501
    stdin: true
    tty: true
    volumeMounts:
    - mountPath: /u01/config/instance1
      name: u01-volumes-ol8_19_ords_tomcat
    workingDir: /
  - command:
    - /bin/sh
    - -c
    - exec ${SCRIPTS_DIR}/start.sh
    env:
    - name: PATH
      value: /u01/app/oracle/product/19.0.0/dbhome_1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    - name: TERM
      value: xterm
    - name: HOSTNAME
      value: my_pod
    - name: container
      value: podman
    - name: ORACLE_BASE
      value: /u01/app/oracle
    - name: DB_SOFTWARE
      value: LINUX.X64_193000_db_home.zip
    - name: ORAENV_ASK
      value: "NO"
    - name: PDB_NAME
      value: pdb1
    - name: INSTALL_APEX
      value: "true"
    - name: APEX_PASSWORD
      value: ApexPassword1
    - name: ORACLE_PASSWORD
      value: oracle
    - name: APEX_SOFTWARE
      value: apex_20.1_en.zip
    - name: ORA_INVENTORY
      value: /u01/app/oraInventory
    - name: ORACLE_SID
      value: cdb1
    - name: SYS_PASSWORD
      value: SysPassword1
    - name: PDB_PASSWORD
      value: PdbPassword1
    - name: APEX_EMAIL
      value: me@example.com
    - name: SOFTWARE_DIR
      value: /u01/software
    - name: SCRIPTS_DIR
      value: /u01/scripts
    - name: ORACLE_HOME
      value: /u01/app/oracle/product/19.0.0/dbhome_1
    image: localhost/ol8_19:latest
    name: ol819con
    resources: {}
    securityContext:
      allowPrivilegeEscalation: true
      capabilities: {}
      privileged: false
      readOnlyRootFilesystem: false
      runAsUser: 500
    stdin: true
    tty: true
    volumeMounts:
    - mountPath: /u02
      name: u01-volumes-ol8_19_ords_db
    workingDir: /
  volumes:
  - hostPath:
      path: /u01/volumes/ol8_19_ords_tomcat
      type: Directory
    name: u01-volumes-ol8_19_ords_tomcat
  - hostPath:
      path: /u01/volumes/ol8_19_ords_db
      type: Directory
    name: u01-volumes-ol8_19_ords_db
status: {}

There are some things to notice about the contents of the file.

If we remove the environment variables with default values and add back the "_" characters that were removed, the file looks like this.

# Generation of Kubernetes YAML is still under development!
#
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-1.6.4
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2020-05-26T11:05:04Z"
  labels:
    app: my_pod
  name: my_pod
spec:
  containers:
  - command:
    - /bin/sh
    - -c
    - exec ${SCRIPTS_DIR}/start.sh
    env:
    - name: HOSTNAME
      value: my_pod
    - name: container
      value: podman
    image: localhost/ol8_19:latest
    name: ol8_19_con
    ports:
    - containerPort: 1521
      hostPort: 1521
      protocol: TCP
    - containerPort: 5500
      hostPort: 5500
      protocol: TCP
    - containerPort: 8080
      hostPort: 8080
      protocol: TCP
    - containerPort: 8443
      hostPort: 8443
      protocol: TCP
    resources: {}
    securityContext:
      allowPrivilegeEscalation: true
      capabilities: {}
      privileged: false
      readOnlyRootFilesystem: false
      runAsUser: 500
    stdin: true
    tty: true
    volumeMounts:
    - mountPath: /u02
      name: u01-volumes-ol8_19_ords_db
    workingDir: /
  - command:
    - /bin/sh
    - -c
    - exec ${SCRIPTS_DIR}/start.sh
    env:
    - name: HOSTNAME
      value: my_pod
    - name: container
      value: podman
    - name: DB_HOSTNAME
      value: localhost
    image: localhost/ol8_ords:latest
    name: ol8_ords_con
    resources: {}
    securityContext:
      allowPrivilegeEscalation: true
      capabilities: {}
      privileged: false
      readOnlyRootFilesystem: false
      runAsUser: 501
    stdin: true
    tty: true
    volumeMounts:
    - mountPath: /u01/config/instance1
      name: u01-volumes-ol8_19_ords_tomcat
    workingDir: /
  volumes:
  - hostPath:
      path: /u01/volumes/ol8_19_ords_db
      type: Directory
    name: u01-volumes-ol8_19_ords_db
  - hostPath:
      path: /u01/volumes/ol8_19_ords_tomcat
      type: Directory
    name: u01-volumes-ol8_19_ords_tomcat
status: {}

We will refer to this amended file as "/tmp/my_pod_kube_compact.yaml" below.

Play a Kubernetes YAML File

Podman allows us to play a Kubernetes YAML file to create a pod. In order to do this we need to remove the exiting pod, so we can rebuild it using the Kubernetes YAML file. The following commands clean up the containers, along with their volumes, and the pod.

podman rm -vf ol8_ords_con
podman rm -vf ol8_19_con
podman pod rm my_pod

The pod no longer exists.

$ podman ps -a
CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS  PORTS  NAMES
$

We can now rebuild the pod using the podman generate kube command.

$ podman play kube /tmp/my_pod_kube_compact.yaml
Pod:
ca53a71fecd8aa19a868739695624b4682fc3818e4889dff331284ec824afd15
Containers:
e8b5f9da27a9ee8b9c77cc0c799cf2e197bbb44df5b5aecc78b09ffabd52dcc0
b1944c9bf62e9947b073ecc9ac2420741a05bdb191c4b4f39c3f843b8e54a519
$

We can see the pod has been created.

$ podman pod list
POD ID         NAME     STATUS    CREATED          # OF CONTAINERS   INFRA ID
ca53a71fecd8   my_pod   Running   24 seconds ago   3                 9df5f3af12f1
$

The containers are also visible now.

$ podman ps -a
CONTAINER ID  IMAGE                      COMMAND               CREATED         STATUS             PORTS                   NAMES
b1944c9bf62e  localhost/ol8_ords:latest  /bin/sh -c exec $...  41 seconds ago  Up 40 seconds ago  0.0.0.0:1521->1521/tcp  ol8_ords_con
e8b5f9da27a9  localhost/ol8_19:latest    /bin/sh -c exec $...  41 seconds ago  Up 40 seconds ago  0.0.0.0:1521->1521/tcp  ol8_19_con
9df5f3af12f1  k8s.gcr.io/pause:3.1                             41 seconds ago  Up 41 seconds ago  0.0.0.0:1521->1521/tcp  ca53a71fecd8-infra
$

For more information see:

Hope this helps. Regards Tim...

Back to the Top.