github.com/containers/podman/v5@v5.1.0-rc1/docs/source/markdown/podman-kube-generate.1.md (about)

     1  % podman-kube-generate 1
     2  
     3  ## NAME
     4  podman-kube-generate - Generate Kubernetes YAML based on containers, pods or volumes
     5  
     6  ## SYNOPSIS
     7  **podman kube generate** [*options*] *container...* | *pod...* | *volume...*
     8  
     9  ## DESCRIPTION
    10  **podman kube generate** generates Kubernetes YAML (v1 specification) from Podman containers, pods or volumes. Regardless of whether
    11  the input is for containers or pods, Podman generates the specification as a Pod by default. The input may be in the form
    12  of one or more containers, pods or volumes names or IDs.
    13  
    14  `Podman Containers or Pods`
    15  
    16  Volumes appear in the generated YAML according to two different volume types. Bind-mounted volumes become *hostPath* volume types and named volumes become *persistentVolumeClaim* volume types. Generated *hostPath* volume types are one of three subtypes depending on the state of the host path: *DirectoryOrCreate* when no file or directory exists at the host, *Directory* when host path is a directory, or *File* when host path is a file. The value for *claimName* for a *persistentVolumeClaim* is the name of the named volume registered in Podman.
    17  
    18  Potential name conflicts between volumes are avoided by using a standard naming scheme for each volume type. The *hostPath* 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, `/`, translates to the name `root`. Additionally, the name is suffixed with `-host` to avoid naming conflicts with *persistentVolumeClaim* volumes. Each *persistentVolumeClaim* volume type uses the name of its associated named volume suffixed with `-pvc`.
    19  
    20  Note that if an init container is created with type `once` and the pod has been started, it does not show up in the generated kube YAML as `once` 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.
    21  Init containers created with type `always` are always generated in the kube YAML as they are never deleted, even after running to completion.
    22  
    23  *Note*: When using volumes and generating a Kubernetes YAML for an unprivileged and rootless podman container on an **SELinux enabled system**,  one of the following options must be completed:
    24    * Add the "privileged: true" option to the pod spec
    25    * Add `type: spc_t` under the `securityContext` `seLinuxOptions` in the pod spec
    26    * Relabel the volume via the CLI command `chcon -t container_file_t -R <directory>`
    27  
    28  Once completed, the correct permissions are in place to access the volume when the pod/container is created in a Kubernetes cluster.
    29  
    30  Note that the generated Kubernetes YAML file can be used to re-run the deployment via podman-play-kube(1).
    31  
    32  Note that if the pod being generated was created with the **--infra-name** flag set, then the generated kube yaml will have the **io.podman.annotations.infra.name** set where the value is the name of the infra container set by the user.
    33  
    34  Also note that both Deployment and DaemonSet can only have `restartPolicy` set to `Always`.
    35  
    36  ## OPTIONS
    37  
    38  #### **--filename**, **-f**=*filename*
    39  
    40  Output to the given file instead of STDOUT. If the file already exists, `kube generate` refuses to replace it and returns an error.
    41  
    42  #### **--podman-only**
    43  
    44  Add podman-only reserved annotations in generated YAML file (Cannot be used by Kubernetes)
    45  
    46  #### **--replicas**, **-r**=*replica count*
    47  
    48  The value to set `replicas` to when generating a **Deployment** kind.
    49  Note: this can only be set with the option `--type=deployment`.
    50  
    51  #### **--service**, **-s**
    52  
    53  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.
    54  
    55  #### **--type**, **-t**=*pod* | *deployment* | *daemonset*
    56  
    57  The Kubernetes kind to generate in the YAML file. Currently, the only supported Kubernetes specifications are `Pod`, `Deployment` and `DaemonSet`. By default, the `Pod` specification is generated.
    58  
    59  ## EXAMPLES
    60  
    61  Create Kubernetes Pod YAML for the specified container.
    62  ```
    63  $ podman kube generate some-mariadb
    64  # Save the output of this file and use kubectl create -f to import
    65  # it into Kubernetes.
    66  #
    67  # Created with podman-4.8.2
    68  
    69  # NOTE: If you generated this yaml from an unprivileged and rootless podman container on an SELinux
    70  # enabled system, check the podman generate kube man page for steps to follow to ensure that your pod/container
    71  # has the right permissions to access the volumes added.
    72  ---
    73  apiVersion: v1
    74  kind: Pod
    75  metadata:
    76    creationTimestamp: "2024-01-09T02:24:55Z"
    77    labels:
    78      app: some-mariadb-pod
    79    name: some-mariadb-pod
    80  spec:
    81    containers:
    82    - args:
    83      - mariadbd
    84      env:
    85      - name: MARIADB_ROOT_PASSWORD
    86        value: x
    87      image: docker.io/library/mariadb:10.11
    88      name: some-mariadb
    89      ports:
    90      - containerPort: 3306
    91        hostPort: 34891
    92      volumeMounts:
    93      - mountPath: /var/lib/mysql
    94        name: mariadb_data-pvc
    95    volumes:
    96    - name: mariadb_data-pvc
    97      persistentVolumeClaim:
    98        claimName: mariadb_data
    99  ```
   100  
   101  Create Kubernetes Deployment YAML with 3 replicas for the specified container.
   102  ```
   103  $ podman kube generate --type deployment --replicas 3 dep-ct
   104  r
   105  # Save the output of this file and use kubectl create -f to import
   106  # it into Kubernetes.
   107  #
   108  # Created with podman-4.5.0-dev
   109  apiVersion: apps/v1
   110  kind: Deployment
   111  metadata:
   112    creationTimestamp: "2023-03-27T20:45:08Z"
   113    labels:
   114      app: dep-ctr-pod
   115    name: dep-ctr-pod-deployment
   116  spec:
   117    replicas: 3
   118    selector:
   119      matchLabels:
   120        app: dep-ctr-pod
   121    template:
   122      metadata:
   123        annotations:
   124          io.podman.annotations.ulimit: nofile=524288:524288,nproc=127332:127332
   125        creationTimestamp: "2023-03-27T20:45:08Z"
   126        labels:
   127          app: dep-ctr-pod
   128        name: dep-ctr-pod
   129      spec:
   130        containers:
   131        - command:
   132          - top
   133          image: docker.io/library/alpine:latest
   134          name: dep-ctr
   135  ```
   136  
   137  
   138  Create Kubernetes Pod YAML for the specified container with the host directory `/home/user/my-data` bind-mounted onto the container path `/volume`.
   139  ```
   140  $ podman kube generate my-container-with-bind-mounted-data
   141  # Save the output of this file and use kubectl create -f to import
   142  # it into Kubernetes.
   143  #
   144  # Created with podman-3.1.0-dev
   145  apiVersion: v1
   146  kind: Pod
   147  metadata:
   148    creationTimestamp: "2021-03-18T16:26:08Z"
   149    labels:
   150      app: my-container-with-bind-mounted-data
   151    name: my-container-with-bind-mounted-data
   152  spec:
   153    containers:
   154    - command:
   155      - /bin/sh
   156      image: docker.io/library/alpine:latest
   157      name: test-bind-mount
   158      volumeMounts:
   159      - mountPath: /volume
   160        name: home-user-my-data-host
   161    restartPolicy: Never
   162    volumes:
   163    - hostPath:
   164        path: /home/user/my-data
   165        type: Directory
   166      name: home-user-my-data-host
   167  ```
   168  
   169  Create Kubernetes Pod YAML for the specified container with named volume `priceless-data` mounted onto the container path `/volume`.
   170  ```
   171  $ podman kube generate my-container-using-priceless-data
   172  # Save the output of this file and use kubectl create -f to import
   173  # it into Kubernetes.
   174  #
   175  # Created with podman-3.1.0-dev
   176  apiVersion: v1
   177  kind: Pod
   178  metadata:
   179    creationTimestamp: "2021-03-18T16:26:08Z"
   180    labels:
   181      app: my-container-using-priceless-data
   182    name: my-container-using-priceless-data
   183  spec:
   184    containers:
   185    - command:
   186      - /bin/sh
   187      image: docker.io/library/alpine:latest
   188      name: test-bind-mount
   189      volumeMounts:
   190      - mountPath: /volume
   191        name: priceless-data-pvc
   192    restartPolicy: Never
   193    volumes:
   194    - name: priceless-data-pvc
   195      persistentVolumeClaim:
   196        claimName: priceless-data
   197  ```
   198  
   199  Create Kubernetes Pod YAML for the specified pod and include a service.
   200  ```
   201  $ sudo podman kube generate -s demoweb
   202  # Save the output of this file and use kubectl create -f to import
   203  # it into Kubernetes.
   204  #
   205  # Created with podman-0.12.2-dev
   206  apiVersion: v1
   207  kind: Pod
   208  metadata:
   209    creationTimestamp: 2018-12-18T15:16:06Z
   210    labels:
   211      app: demoweb
   212    name: demoweb-libpod
   213  spec:
   214    containers:
   215    - command:
   216      - python3
   217      - /root/code/graph.py
   218      image: quay.io/baude/demoweb:latest
   219      name: practicalarchimedes
   220      tty: true
   221      workingDir: /root/code
   222  ---
   223  apiVersion: v1
   224  kind: Service
   225  metadata:
   226    creationTimestamp: 2018-12-18T15:16:06Z
   227    labels:
   228      app: demoweb
   229    name: demoweb-libpod
   230  spec:
   231    ports:
   232    - name: "8050"
   233      nodePort: 31269
   234      port: 8050
   235      targetPort: 0
   236    selector:
   237      app: demoweb
   238    type: NodePort
   239  status:
   240    loadBalancer: {}
   241  ```
   242  
   243  ## SEE ALSO
   244  **[podman(1)](podman.1.md)**, **[podman-container(1)](podman-container.1.md)**, **[podman-pod(1)](podman-pod.1.md)**, **[podman-kube-play(1)](podman-kube-play.1.md)**, **[podman-kube-down(1)](podman-kube-down.1.md)**
   245  
   246  ## HISTORY
   247  December 2018, Originally compiled by Brent Baude (bbaude at redhat dot com)