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