.nh .TH podman-kube-generate 1 .SH NAME .PP podman-kube-generate - Generate Kubernetes YAML based on containers, pods or volumes .SH SYNOPSIS .PP \fBpodman kube generate\fP [\fIoptions\fP] \fIcontainer...\fP | \fIpod...\fP | \fIvolume...\fP .SH DESCRIPTION .PP \fBpodman kube generate\fP generates Kubernetes YAML (v1 specification) from Podman containers, pods or volumes. Regardless of whether the input is for containers or pods, Podman generates the specification as a Pod by default. The input may be in the form of one or more containers, pods or volumes names or IDs. .PP \fBPodman Containers or Pods\fR .PP Volumes appear in the generated YAML according to two different volume types. Bind-mounted volumes become \fIhostPath\fP volume types and named volumes become \fIpersistentVolumeClaim\fP volume types. Generated \fIhostPath\fP volume types are one of three subtypes depending on the state of the host path: \fIDirectoryOrCreate\fP when no file or directory exists at the host, \fIDirectory\fP when host path is a directory, or \fIFile\fP when host path is a file. The value for \fIclaimName\fP for a \fIpersistentVolumeClaim\fP is the name of the named volume registered in Podman. .PP Potential name conflicts between volumes are avoided by using a standard naming scheme for each volume type. The \fIhostPath\fP volume types are named according to the path on the host machine, replacing forward slashes with hyphens less any leading and trailing forward slashes. The special case of the filesystem root, \fB/\fR, translates to the name \fBroot\fR\&. Additionally, the name is suffixed with \fB-host\fR to avoid naming conflicts with \fIpersistentVolumeClaim\fP volumes. Each \fIpersistentVolumeClaim\fP volume type uses the name of its associated named volume suffixed with \fB-pvc\fR\&. .PP Note that if an init container is created with type \fBonce\fR and the pod has been started, it does not show up in the generated kube YAML as \fBonce\fR type init containers are deleted after they are run. If the pod has only been created and not started, it is in the generated kube YAML. Init containers created with type \fBalways\fR are always generated in the kube YAML as they are never deleted, even after running to completion. .PP \fINote\fP: When using volumes and generating a Kubernetes YAML for an unprivileged and rootless podman container on an \fBSELinux enabled system\fP, one of the following options must be completed: * Add the "privileged: true" option to the pod spec * Add \fBtype: spc_t\fR under the \fBsecurityContext\fR \fBseLinuxOptions\fR in the pod spec * Relabel the volume via the CLI command \fBchcon -t container_file_t -R \fR .PP Once completed, the correct permissions are in place to access the volume when the pod/container is created in a Kubernetes cluster. .PP Note that the generated Kubernetes YAML file can be used to re-run the deployment via podman-play-kube(1). .PP Note that if the pod being generated was created with the \fB--infra-name\fP flag set, then the generated kube yaml will have the \fBio.podman.annotations.infra.name\fP set where the value is the name of the infra container set by the user. .PP Also note that both Deployment and DaemonSet can only have \fBrestartPolicy\fR set to \fBAlways\fR\&. .SH OPTIONS .SS \fB--filename\fP, \fB-f\fP=\fIfilename\fP .PP Output to the given file instead of STDOUT. If the file already exists, \fBkube generate\fR refuses to replace it and returns an error. .SS \fB--no-trunc\fP .PP Don't truncate annotations to the Kubernetes maximum length of 63 characters. Note: enabling this flag means the generated YAML file is not Kubernetes compatible and can only be used with \fBpodman kube play\fR .SS \fB--podman-only\fP .PP Add podman-only reserved annotations in generated YAML file (Cannot be used by Kubernetes) .SS \fB--replicas\fP, \fB-r\fP=\fIreplica count\fP .PP The value to set \fBreplicas\fR to when generating a \fBDeployment\fP kind. Note: this can only be set with the option \fB--type=deployment\fR\&. .SS \fB--service\fP, \fB-s\fP .PP Generate a Kubernetes service object in addition to the Pods. Used to generate a Service specification for the corresponding Pod output. In particular, if the object has portmap bindings, the service specification includes a NodePort declaration to expose the service. A random port is assigned by Podman in the specification. .SS \fB--type\fP, \fB-t\fP=\fIpod\fP | \fIdeployment\fP | \fIdaemonset\fP .PP The Kubernetes kind to generate in the YAML file. Currently, the only supported Kubernetes specifications are \fBPod\fR, \fBDeployment\fR and \fBDaemonSet\fR\&. By default, the \fBPod\fR specification is generated. .SH EXAMPLES .PP Create Kubernetes Pod YAML for a container called \fBsome-mariadb\fR\&. .EX $ sudo podman kube generate some-mariadb # Save the output of this file and use kubectl create -f to import # it into Kubernetes. # # Created with podman-0.11.2-dev apiVersion: v1 kind: Pod metadata: creationTimestamp: 2018-12-03T19:07:59Z labels: app: some-mariadb name: some-mariadb-libpod spec: containers: - command: - docker-entrypoint.sh - mysqld env: - name: HOSTNAME - name: GOSU_VERSION value: "1.10" - name: GPG_KEYS value: "199369E5404BD5FC7D2FE43BCBCB082A1BB943DB \\t177F4010FE56CA3336300305F1656F24C74CD1D8 \\t430BDF5C56E7C94E848EE60C1C4CBDCDCD2EFD2A \\t4D1BB29D63D98E422B2113B19334A25F8507EFA5" - name: MARIADB_MAJOR value: "10.3" - name: MARIADB_VERSION value: 1:10.3.10+maria~bionic - name: MYSQL_ROOT_PASSWORD value: x image: quay.io/baude/demodb:latest name: some-mariadb ports: - containerPort: 3306 hostPort: 36533 tty: true .EE .PP Create Kubernetes Deployment YAML with 3 replicas for a container called \fBdep-ctr\fR .EX $ podman kube generate --type deployment --replicas 3 dep-ct r # Save the output of this file and use kubectl create -f to import # it into Kubernetes. # # Created with podman-4.5.0-dev apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: "2023-03-27T20:45:08Z" labels: app: dep-ctr-pod name: dep-ctr-pod-deployment spec: replicas: 3 selector: matchLabels: app: dep-ctr-pod template: metadata: annotations: io.podman.annotations.ulimit: nofile=524288:524288,nproc=127332:127332 creationTimestamp: "2023-03-27T20:45:08Z" labels: app: dep-ctr-pod name: dep-ctr-pod spec: containers: - command: - top image: docker.io/library/alpine:latest name: dep-ctr .EE .PP Create Kubernetes Pod YAML for a container with the directory \fB/home/user/my-data\fR on the host bind-mounted in the container to \fB/volume\fR\&. .EX $ podman kube generate my-container-with-bind-mounted-data # Save the output of this file and use kubectl create -f to import # it into Kubernetes. # # Created with podman-3.1.0-dev apiVersion: v1 kind: Pod metadata: creationTimestamp: "2021-03-18T16:26:08Z" labels: app: my-container-with-bind-mounted-data name: my-container-with-bind-mounted-data spec: containers: - command: - /bin/sh image: docker.io/library/alpine:latest name: test-bind-mount volumeMounts: - mountPath: /volume name: home-user-my-data-host restartPolicy: Never volumes: - hostPath: path: /home/user/my-data type: Directory name: home-user-my-data-host .EE .PP Create Kubernetes Pod YAML for a container with the named volume \fBpriceless-data\fR mounted in the container at \fB/volume\fR\&. .EX $ podman kube generate my-container-using-priceless-data # Save the output of this file and use kubectl create -f to import # it into Kubernetes. # # Created with podman-3.1.0-dev apiVersion: v1 kind: Pod metadata: creationTimestamp: "2021-03-18T16:26:08Z" labels: app: my-container-using-priceless-data name: my-container-using-priceless-data spec: containers: - command: - /bin/sh image: docker.io/library/alpine:latest name: test-bind-mount volumeMounts: - mountPath: /volume name: priceless-data-pvc restartPolicy: Never volumes: - name: priceless-data-pvc persistentVolumeClaim: claimName: priceless-data .EE .PP Create Kubernetes Pod YAML for a pod called \fBdemoweb\fR and include a service. .EX $ sudo podman kube generate -s demoweb # Save the output of this file and use kubectl create -f to import # it into Kubernetes. # # Created with podman-0.12.2-dev apiVersion: v1 kind: Pod metadata: creationTimestamp: 2018-12-18T15:16:06Z labels: app: demoweb name: demoweb-libpod spec: containers: - command: - python3 - /root/code/graph.py image: quay.io/baude/demoweb:latest name: practicalarchimedes tty: true workingDir: /root/code --- apiVersion: v1 kind: Service metadata: creationTimestamp: 2018-12-18T15:16:06Z labels: app: demoweb name: demoweb-libpod spec: ports: - name: "8050" nodePort: 31269 port: 8050 targetPort: 0 selector: app: demoweb type: NodePort status: loadBalancer: {} .EE .SH SEE ALSO .PP \fBpodman(1)\fP, \fBpodman-container(1)\fP, \fBpodman-pod(1)\fP, \fBpodman-kube-play(1)\fP, \fBpodman-kube-down(1)\fP .SH HISTORY .PP December 2018, Originally compiled by Brent Baude (bbaude at redhat dot com)