1
2‐% podman‐kube‐generate(1)
3
4podman‐kube‐generate ‐ Generate Kubernetes YAML based on
5containers, pods or volumes
6
8
10from Podman containers, pods or volumes. Regardless of whether
11the input is for containers or pods, Podman generates the
12specification as a Pod by default. The input may be in the form
13of one or more containers, pods or volumes names or IDs.
14
16
17Volumes appear in the generated YAML according to two different
18volume types. Bind‐mounted volumes become hostPath volume types
19and named volumes become persistentVolumeClaim volume types.
20Generated hostPath volume types are one of three subtypes
21depending on the state of the host path: DirectoryOrCreate when
22no file or directory exists at the host, Directory when host path
23is a directory, or File when host path is a file. The value for
25volume registered in Podman.
26
27Potential name conflicts between volumes are avoided by using a
28standard naming scheme for each volume type. The hostPath volume
29types are named according to the path on the host machine,
30replacing forward slashes with hyphens less any leading and
31trailing forward slashes. The special case of the filesystem
32root, /, translates to the name root. Additionally, the name is
33suffixed with ‐host to avoid naming conflicts with
35type uses the name of its associated named volume suffixed with
37
38Note that if an init container is created with type once and the
39pod has been started, it does not show up in the generated kube
40YAML as once type init containers are deleted after they are run.
41If the pod has only been created and not started, it is in the
42generated kube YAML. Init containers created with type always
43are always generated in the kube YAML as they are never deleted,
44even after running to completion.
45
47unprivileged and rootless podman container on an SELinux enabled
49 * Add the "privileged: true" option to the pod spec
50 * Add type: spc_t under the securityContext seLinuxOptions in
51the pod spec
52 * Relabel the volume via the CLI command chcon ‐t
54
55Once completed, the correct permissions are in place to access
56the volume when the pod/container is created in a Kubernetes
57cluster.
58
59Note that the generated Kubernetes YAML file can be used to re‐
60run the deployment via podman‐play‐kube(1).
61
62Note that if the pod being generated was created with the
65of the infra container set by the user.
66
67Also note that both Deployment and DaemonSet can only have
69
70Output to the given file instead of STDOUT. If the file already
71exists, kube generate refuses to replace it and returns an error.
72
73Don’t truncate annotations to the Kubernetes maximum length of 63
74characters. Note: enabling this flag means the generated YAML
75file is not Kubernetes compatible and can only be used with
77
78Add podman‐only reserved annotations in generated YAML file
79(Cannot be used by Kubernetes)
80
81The value to set replicas to when generating a Deployment kind.
82Note: this can only be set with the option ‐‐type=deployment.
83
84Generate a Kubernetes service object in addition to the Pods.
85Used to generate a Service specification for the corresponding
86Pod output. In particular, if the object has portmap bindings,
87the service specification includes a NodePort declaration to
88expose the service. A random port is assigned by Podman in the
89specification.
90
91The Kubernetes kind to generate in the YAML file. Currently, the
92only supported Kubernetes specifications are Pod, Deployment and
94
95Create Kubernetes Pod YAML for a container called some‐mariadb.
96
97
98$ sudo podman kube generate some‐mariadb
99# Save the output of this file and use kubectl create ‐f to import
100# it into Kubernetes.
101#
102# Created with podman‐0.11.2‐dev
103apiVersion: v1
104kind: Pod
105metadata:
106 creationTimestamp: 2018‐12‐03T19:07:59Z
107 labels:
108 app: some‐mariadb
109 name: some‐mariadb‐libpod
110spec:
111 containers:
112 ‐ command:
113 ‐ docker‐entrypoint.sh
114 ‐ mysqld
115 env:
116 ‐ name: HOSTNAME
117 ‐ name: GOSU_VERSION
118 value: "1.10"
119 ‐ name: GPG_KEYS
120 value: "199369E5404BD5FC7D2FE43BCBCB082A1BB943DB \t177F4010FE56CA3336300305F1656F24C74CD1D8
121 \t430BDF5C56E7C94E848EE60C1C4CBDCDCD2EFD2A \t4D1BB29D63D98E422B2113B19334A25F8507EFA5"
122 ‐ name: MARIADB_MAJOR
123 value: "10.3"
124 ‐ name: MARIADB_VERSION
125 value: 1:10.3.10+maria~bionic
126 ‐ name: MYSQL_ROOT_PASSWORD
127 value: x
128 image: quay.io/baude/demodb:latest
129 name: some‐mariadb
130 ports:
131 ‐ containerPort: 3306
132 hostPort: 36533
133 tty: true
134
135
136Create Kubernetes Deployment YAML with 3 replicas for a container
137called dep‐ctr
138
139
140$ podman kube generate ‐‐type deployment ‐‐replicas 3 dep‐ct
141r
142# Save the output of this file and use kubectl create ‐f to import
143# it into Kubernetes.
144#
145# Created with podman‐4.5.0‐dev
146apiVersion: apps/v1
147kind: Deployment
148metadata:
149 creationTimestamp: "2023‐03‐27T20:45:08Z"
150 labels:
151 app: dep‐ctr‐pod
152 name: dep‐ctr‐pod‐deployment
153spec:
154 replicas: 3
155 selector:
156 matchLabels:
157 app: dep‐ctr‐pod
158 template:
159 metadata:
160 annotations:
161 io.podman.annotations.ulimit: nofile=524288:524288,nproc=127332:127332
162 creationTimestamp: "2023‐03‐27T20:45:08Z"
163 labels:
164 app: dep‐ctr‐pod
165 name: dep‐ctr‐pod
166 spec:
167 containers:
168 ‐ command:
169 ‐ top
170 image: docker.io/library/alpine:latest
171 name: dep‐ctr
172
173
174Create Kubernetes Pod YAML for a container with the directory
177
178
179$ podman kube generate my‐container‐with‐bind‐mounted‐data
180# Save the output of this file and use kubectl create ‐f to import
181# it into Kubernetes.
182#
183# Created with podman‐3.1.0‐dev
184apiVersion: v1
185kind: Pod
186metadata:
187 creationTimestamp: "2021‐03‐18T16:26:08Z"
188 labels:
189 app: my‐container‐with‐bind‐mounted‐data
190 name: my‐container‐with‐bind‐mounted‐data
191spec:
192 containers:
193 ‐ command:
194 ‐ /bin/sh
195 image: docker.io/library/alpine:latest
196 name: test‐bind‐mount
197 volumeMounts:
198 ‐ mountPath: /volume
199 name: home‐user‐my‐data‐host
200 restartPolicy: Never
201 volumes:
202 ‐ hostPath:
203 path: /home/user/my‐data
204 type: Directory
205 name: home‐user‐my‐data‐host
206
207
208Create Kubernetes Pod YAML for a container with the named volume
210
211
212$ podman kube generate my‐container‐using‐priceless‐data
213# Save the output of this file and use kubectl create ‐f to import
214# it into Kubernetes.
215#
216# Created with podman‐3.1.0‐dev
217apiVersion: v1
218kind: Pod
219metadata:
220 creationTimestamp: "2021‐03‐18T16:26:08Z"
221 labels:
222 app: my‐container‐using‐priceless‐data
223 name: my‐container‐using‐priceless‐data
224spec:
225 containers:
226 ‐ command:
227 ‐ /bin/sh
228 image: docker.io/library/alpine:latest
229 name: test‐bind‐mount
230 volumeMounts:
231 ‐ mountPath: /volume
232 name: priceless‐data‐pvc
233 restartPolicy: Never
234 volumes:
235 ‐ name: priceless‐data‐pvc
236 persistentVolumeClaim:
237 claimName: priceless‐data
238
239
240Create Kubernetes Pod YAML for a pod called demoweb and include a
241service.
242
243
244$ sudo podman kube generate ‐s demoweb
245# Save the output of this file and use kubectl create ‐f to import
246# it into Kubernetes.
247#
248# Created with podman‐0.12.2‐dev
249apiVersion: v1
250kind: Pod
251metadata:
252 creationTimestamp: 2018‐12‐18T15:16:06Z
253 labels:
254 app: demoweb
255 name: demoweb‐libpod
256spec:
257 containers:
258 ‐ command:
259 ‐ python3
260 ‐ /root/code/graph.py
261 image: quay.io/baude/demoweb:latest
262 name: practicalarchimedes
263 tty: true
264 workingDir: /root/code
265‐‐‐
266apiVersion: v1
267kind: Service
268metadata:
269 creationTimestamp: 2018‐12‐18T15:16:06Z
270 labels:
271 app: demoweb
272 name: demoweb‐libpod
273spec:
274 ports:
275 ‐ name: "8050"
276 nodePort: 31269
277 port: 8050
278 targetPort: 0
279 selector:
280 app: demoweb
281 type: NodePort
282status:
283 loadBalancer: {}
284
285
288
289December 2018, Originally compiled by Brent Baude (bbaude at
290redhat dot com)
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330