1
2‐% podman‐kube‐generate(1)
3
4podman‐kube‐generate   ‐   Generate   Kubernetes  YAML  based  on
5containers, pods or volumes
6

podman kube generate [options] container... | pod... | volume...

8

podman kube generate will generate Kubernetes YAML (v1

10specification)   from   Podman   containers,   pods  or  volumes.
11Regardless of whether the input is for containers or pods, Podman
12will always generate the specification as a Pod. The input may be
13in the form of one or more containers, pods or volumes  names  or
14IDs.
15

Podman Containers or Pods

17
18Volumes  appear  in the generated YAML according to two different
19volume types. Bind‐mounted volumes become hostPath  volume  types
20and  named  volumes  become  persistentVolumeClaim  volume types.
21Generated hostPath volume types will be  one  of  three  subtypes
22depending  on  the state of the host path: DirectoryOrCreate when
23no file or directory exists at the host, Directory when host path
24is  a  directory, or File when host path is a file. The value for

claimName for a persistentVolumeClaim is the name of the named

26volume registered in Podman.
27
28Potential  name  conflicts between volumes are avoided by using a
29standard naming scheme for each volume type. The hostPath  volume
30types  are  named  according  to  the  path  on the host machine,
31replacing forward slashes  with  hyphens  less  any  leading  and
32trailing  forward  slashes.  The  special  case of the filesystem
33root, /, translates to the name root. Additionally, the  name  is
34suffixed    with   ‐host   to   avoid   naming   conflicts   with

persistentVolumeClaim volumes. Each persistentVolumeClaim volume

36type  uses  the name of its associated named volume suffixed with

‐pvc.

38
39Note that if an init container is created with type once and  the
40pod  has been started, the init container will not show up in the
41generated kube YAML as once  type  init  containers  are  deleted
42after  they  are  run.  If  the pod has only been created and not
43started, it will be in the generated kube YAML.  Init  containers
44created  with  type  always  will always be generated in the kube
45YAML as they are never deleted, even after running to completion.
46

Note: When using volumes and generating a Kubernetes YAML for an

48unprivileged  and rootless podman container on an SELinux enabled

system, one of the following options must be completed:

50  * Add the "privileged: true" option to the pod spec
51  * Add type: spc_t under the securityContext  seLinuxOptions  in
52the pod spec
53  *   Relabel   the   volume   via   the  CLI  command  chcon  ‐t

container_file_t ‐R <directory>

55
56Once completed, the correct  permissions  will  be  in  place  to
57access  the  volume  when  the  pod/container  is  created  in  a
58Kubernetes cluster.
59
60Note that the generated Kubernetes YAML file can be used  to  re‐
61run the deployment via podman‐play‐kube(1).
62
63Output  to the given file, instead of STDOUT. If the file already
64exists, kube generate will refuse to replace  it  and  return  an
65error.
66
67Generate  a  Kubernetes  service  object in addition to the Pods.
68Used to generate a Service specification  for  the  corresponding
69Pod  output.  In  particular, if the object has portmap bindings,
70the service specification will include a NodePort declaration  to
71expose  the  service.  A random port is assigned by Podman in the
72specification.
73
74Create Kubernetes Pod YAML for a container called some‐mariadb.
75
76
77$ sudo podman kube generate some‐mariadb
78# Save the output of this file and use kubectl create ‐f to import
79# it into Kubernetes.
80#
81# Created with podman‐0.11.2‐dev
82apiVersion: v1
83kind: Pod
84metadata:
85  creationTimestamp: 2018‐12‐03T19:07:59Z
86  labels:
87    app: some‐mariadb
88  name: some‐mariadb‐libpod
89spec:
90  containers:
91  ‐ command:
92    ‐ docker‐entrypoint.sh
93    ‐ mysqld
94    env:
95    ‐ name: HOSTNAME
96    ‐ name: GOSU_VERSION
97      value: "1.10"
98    ‐ name: GPG_KEYS
99      value: "199369E5404BD5FC7D2FE43BCBCB082A1BB943DB \t177F4010FE56CA3336300305F1656F24C74CD1D8
100        \t430BDF5C56E7C94E848EE60C1C4CBDCDCD2EFD2A \t4D1BB29D63D98E422B2113B19334A25F8507EFA5"
101    ‐ name: MARIADB_MAJOR
102      value: "10.3"
103    ‐ name: MARIADB_VERSION
104      value: 1:10.3.10+maria~bionic
105    ‐ name: MYSQL_ROOT_PASSWORD
106      value: x
107    image: quay.io/baude/demodb:latest
108    name: some‐mariadb
109    ports:
110    ‐ containerPort: 3306
111      hostPort: 36533
112    resources: {}
113    securityContext:
114      capabilities:
115        drop:
116        ‐ CAP_MKNOD
117        ‐ CAP_NET_RAW
118        ‐ CAP_AUDIT_WRITE
119    tty: true
120status: {}
121
122
123Create Kubernetes Pod YAML for a  container  with  the  directory

/home/user/my‐data on the host bind‐mounted in the container to

/volume.

126
127
128$ podman kube generate my‐container‐with‐bind‐mounted‐data
129# Save the output of this file and use kubectl create ‐f to import
130# it into Kubernetes.
131#
132# Created with podman‐3.1.0‐dev
133apiVersion: v1
134kind: Pod
135metadata:
136  creationTimestamp: "2021‐03‐18T16:26:08Z"
137  labels:
138    app: my‐container‐with‐bind‐mounted‐data
139  name: my‐container‐with‐bind‐mounted‐data
140spec:
141  containers:
142  ‐ command:
143    ‐ /bin/sh
144    image: docker.io/library/alpine:latest
145    name: test‐bind‐mount
146    resources: {}
147    securityContext:
148      capabilities:
149        drop:
150        ‐ CAP_MKNOD
151        ‐ CAP_NET_RAW
152        ‐ CAP_AUDIT_WRITE
153    volumeMounts:
154    ‐ mountPath: /volume
155      name: home‐user‐my‐data‐host
156  restartPolicy: Never
157  volumes:
158  ‐ hostPath:
159      path: /home/user/my‐data
160      type: Directory
161    name: home‐user‐my‐data‐host
162status: {}
163
164
165Create Kubernetes Pod YAML for a container with the named  volume

priceless‐data mounted in the container at /volume.

167
168
169$ podman kube generate my‐container‐using‐priceless‐data
170# Save the output of this file and use kubectl create ‐f to import
171# it into Kubernetes.
172#
173# Created with podman‐3.1.0‐dev
174apiVersion: v1
175kind: Pod
176metadata:
177  creationTimestamp: "2021‐03‐18T16:26:08Z"
178  labels:
179    app: my‐container‐using‐priceless‐data
180  name: my‐container‐using‐priceless‐data
181spec:
182  containers:
183  ‐ command:
184    ‐ /bin/sh
185    image: docker.io/library/alpine:latest
186    name: test‐bind‐mount
187    resources: {}
188    securityContext:
189      capabilities:
190        drop:
191        ‐ CAP_MKNOD
192        ‐ CAP_NET_RAW
193        ‐ CAP_AUDIT_WRITE
194    volumeMounts:
195    ‐ mountPath: /volume
196      name: priceless‐data‐pvc
197  restartPolicy: Never
198  volumes:
199  ‐ name: priceless‐data‐pvc
200    persistentVolumeClaim:
201      claimName: priceless‐data
202status: {}
203
204
205Create Kubernetes Pod YAML for a pod called demoweb and include a
206service.
207
208
209$ sudo podman kube generate ‐s demoweb
210# Save the output of this file and use kubectl create ‐f to import
211# it into Kubernetes.
212#
213# Created with podman‐0.12.2‐dev
214apiVersion: v1
215kind: Pod
216metadata:
217  creationTimestamp: 2018‐12‐18T15:16:06Z
218  labels:
219    app: demoweb
220  name: demoweb‐libpod
221spec:
222  containers:
223  ‐ command:
224    ‐ python3
225    ‐ /root/code/graph.py
226    image: quay.io/baude/demoweb:latest
227    name: practicalarchimedes
228    resources: {}
229    tty: true
230    workingDir: /root/code
231status: {}
232‐‐‐
233apiVersion: v1
234kind: Service
235metadata:
236  creationTimestamp: 2018‐12‐18T15:16:06Z
237  labels:
238    app: demoweb
239  name: demoweb‐libpod
240spec:
241  ports:
242  ‐ name: "8050"
243    nodePort: 31269
244    port: 8050
245    targetPort: 0
246  selector:
247    app: demoweb
248  type: NodePort
249status:
250  loadBalancer: {}
251
252

podman(1), podman‐container(1), podman‐pod(1), podman‐kube‐

play(1), podman‐kube‐down(1)

255
256December  2018,  Originally  compiled  by  Brent Baude (bbaude at
257redhat dot com)
258
259
260
261
262
263
264
Impressum