github.com/containers/podman/v5@v5.1.0-rc1/docs/source/markdown/podman-kube-play.1.md.in (about) 1 % podman-kube-play 1 2 3 ## NAME 4 podman-kube-play - Create containers, pods and volumes based on Kubernetes YAML 5 6 ## SYNOPSIS 7 **podman kube play** [*options*] *file.yml|-|https://website.io/file.yml* 8 9 ## DESCRIPTION 10 **podman kube play** reads in a structured file of Kubernetes YAML. It recreates the containers, pods, or volumes described in the YAML. Containers within a pod are then started, and the ID of the new Pod or the name of the new Volume is output. If the YAML file is specified as "-", then `podman kube play` reads the YAML file from stdin. 11 The input can also be a URL that points to a YAML file such as https://podman.io/demo.yml. `podman kube play` reads the YAML from the URL and create pods and containers from it. 12 13 Using the `--down` command line option, it is also capable of tearing down the pods created by a previous run of `podman kube play`. 14 15 Using the `--replace` command line option, it tears down the pods(if any) created by a previous run of `podman kube play` and recreate the pods with the Kubernetes YAML file. 16 17 Ideally the input file is created by the Podman command (see podman-kube-generate(1)). This guarantees a smooth import and expected results. 18 19 Currently, the supported Kubernetes kinds are: 20 21 - Pod 22 - Deployment 23 - PersistentVolumeClaim 24 - ConfigMap 25 - Secret 26 - DaemonSet 27 28 `Kubernetes Pods or Deployments` 29 30 Only three volume types are supported by kube play, the *hostPath*, *emptyDir*, and *persistentVolumeClaim* volume types. 31 32 - When using the *hostPath* volume type, only the *default (empty)*, *DirectoryOrCreate*, *Directory*, *FileOrCreate*, *File*, *Socket*, *CharDevice* and *BlockDevice* subtypes are supported. Podman interprets the value of *hostPath* *path* as a file path when it contains at least one forward slash, otherwise Podman treats the value as the name of a named volume. 33 - When using a *persistentVolumeClaim*, the value for *claimName* is the name for the Podman named volume. 34 - When using an *emptyDir* volume, Podman creates an anonymous volume that is attached the containers running inside the pod and is deleted once the pod is removed. 35 36 Note: The default restart policy for containers is `always`. You can change the default by setting the `restartPolicy` field in the spec. 37 38 Note: When playing a kube YAML with init containers, the init container is created with init type value `once`. To change the default type, use the `io.podman.annotations.init.container.type` annotation to set the type to `always`. 39 40 Note: *hostPath* volume types created by kube play is given an SELinux shared label (z), bind mounts are not relabeled (use `chcon -t container_file_t -R <directory>`). 41 42 Note: To set userns of a pod, use the **io.podman.annotations.userns** annotation in the pod/deployment definition. For example, **io.podman.annotations.userns=keep-id** annotation tells Podman to create a user namespace where the current rootless user's UID:GID are mapped to the same values in the container. This can be overridden with the `--userns` flag. 43 44 Note: Use the **io.podman.annotations.volumes-from** annotation to bind mount volumes of one container to another. You can mount volumes from multiple source containers to a target container. The source containers that belong to the same pod must be defined before the source container in the kube YAML. The annotation format is `io.podman.annotations.volumes-from/targetContainer: "sourceContainer1:mountOpts1;sourceContainer2:mountOpts2"`. 45 46 Note: If the `:latest` tag is used, Podman attempts to pull the image from a registry. If the image was built locally with Podman or Buildah, it has `localhost` as the domain, in that case, Podman uses the image from the local store even if it has the `:latest` tag. 47 48 Note: The command `podman play kube` is an alias of `podman kube play`, and performs the same function. 49 50 Note: The command `podman kube down` can be used to stop and remove pods or containers based on the same Kubernetes YAML used 51 by `podman kube play` to create them. 52 53 Note: To customize the name of the infra container created during `podman kube play`, use the **io.podman.annotations.infra.name** annotation in the pod definition. This annotation is automatically set when generating a kube yaml from a pod that was created with the `--infra-name` flag set. 54 55 `Kubernetes PersistentVolumeClaims` 56 57 A Kubernetes PersistentVolumeClaim represents a Podman named volume. Only the PersistentVolumeClaim name is required by Podman to create a volume. Kubernetes annotations can be used to make use of the available options for Podman volumes. 58 59 - volume.podman.io/driver 60 - volume.podman.io/device 61 - volume.podman.io/type 62 - volume.podman.io/uid 63 - volume.podman.io/gid 64 - volume.podman.io/mount-options 65 - volume.podman.io/import-source 66 - volume.podman.io/image 67 68 Use `volume.podman.io/import-source` to import the contents of the tarball (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) specified in the annotation's value into the created Podman volume 69 70 Kube play is capable of building images on the fly given the correct directory layout and Containerfiles. This 71 option is not available for remote clients, including Mac and Windows (excluding WSL2) machines, yet. Consider the following excerpt from a YAML file: 72 ``` 73 apiVersion: v1 74 kind: Pod 75 metadata: 76 ... 77 spec: 78 containers: 79 - name: container 80 image: foobar 81 ... 82 ``` 83 84 If there is a directory named `foobar` in the current working directory with a file named `Containerfile` or `Dockerfile`, 85 Podman kube play builds that image and name it `foobar`. An example directory structure for this example looks 86 like: 87 ``` 88 |- mykubefiles 89 |- myplayfile.yaml 90 |- foobar 91 |- Containerfile 92 ``` 93 94 The build considers `foobar` to be the context directory for the build. If there is an image in local storage 95 called `foobar`, the image is not built unless the `--build` flag is used. Use `--build=false` to completely 96 disable builds. 97 98 `Kubernetes ConfigMap` 99 100 Kubernetes ConfigMap can be referred as a source of environment variables or volumes in Pods or Deployments. 101 ConfigMaps aren't a standalone object in Podman; instead, when a container uses a ConfigMap, Podman creates environment variables or volumes as needed. 102 103 For example, the following YAML document defines a ConfigMap and then uses it in a Pod: 104 105 ``` 106 apiVersion: v1 107 kind: ConfigMap 108 metadata: 109 name: foo 110 data: 111 FOO: bar 112 --- 113 apiVersion: v1 114 kind: Pod 115 metadata: 116 name: foobar 117 spec: 118 containers: 119 - name: container-1 120 image: foobar 121 envFrom: 122 - configMapRef: 123 name: foo 124 optional: false 125 ``` 126 127 and as a result environment variable `FOO` is set to `bar` for container `container-1`. 128 129 `Kubernetes Secret` 130 131 Kubernetes Secret represents a Podman named secret. The Kubernetes Secret is saved as a whole and may be referred to as a source of environment variables or volumes in Pods or Deployments. 132 133 For example, the following YAML document defines a Secret and then uses it in a Pod: 134 135 ``` 136 kind: Secret 137 apiVersion: v1 138 metadata: 139 name: foo 140 data: 141 foo: YmFy # base64 for bar 142 --- 143 apiVersion: v1 144 kind: Pod 145 metadata: 146 name: foobar 147 spec: 148 containers: 149 - name: container-1 150 image: foobar 151 env: 152 - name: FOO 153 valueFrom: 154 secretKeyRef: 155 name: foo 156 key: foo 157 ``` 158 159 and as a result environment variable `FOO` is set to `bar` for container `container-1`. 160 161 `Automounting Volumes` 162 163 An image can be automatically mounted into a container if the annotation `io.podman.annotations.kube.image.automount/$ctrname` is given. The following rules apply: 164 165 - The image must already exist locally. 166 - The image must have at least 1 volume directive. 167 - The path given by the volume directive will be mounted from the image into the container. For example, an image with a volume at `/test/test_dir` will have `/test/test_dir` in the image mounted to `/test/test_dir` in the container. 168 - Multiple images can be specified. If multiple images have a volume at a specific path, the last image specified trumps. 169 - The images are always mounted read-only. 170 - Images to mount are defined in the annotation "io.podman.annotations.kube.image.automount/$ctrname" as a semicolon-separated list. They are mounted into a single container in the pod, not the whole pod. The annotation can be specified for additional containers if additional mounts are required. 171 172 ## OPTIONS 173 174 @@option annotation.container 175 176 @@option authfile 177 178 #### **--build** 179 180 Build images even if they are found in the local storage. Use `--build=false` to completely disable builds. (This option is not available with the remote Podman client) 181 182 Note: You can also override the default isolation type by setting the BUILDAH_ISOLATION environment variable. export BUILDAH_ISOLATION=oci. See podman-build.1.md for more information. 183 184 @@option cert-dir 185 186 #### **--configmap**=*path* 187 188 Use Kubernetes configmap YAML at path to provide a source for environment variable values within the containers of the pod. (This option is not available with the remote Podman client) 189 190 Note: The *--configmap* option can be used multiple times or a comma-separated list of paths can be used to pass multiple Kubernetes configmap YAMLs. 191 The YAML file may be in a multi-doc YAML format. But, it must container only configmaps 192 193 #### **--context-dir**=*path* 194 195 Use *path* as the build context directory for each image. Requires --build option be true. (This option is not available with the remote Podman client) 196 197 @@option creds 198 199 #### **--force** 200 201 Tear down the volumes linked to the PersistentVolumeClaims as part of --down 202 203 #### **--help**, **-h** 204 205 Print usage statement 206 207 #### **--ip**=*IP address* 208 209 Assign a static ip address to the pod. This option can be specified several times when kube play creates more than one pod. 210 Note: When joining multiple networks use the **--network name:ip=\<ip\>** syntax. 211 212 #### **--log-driver**=*driver* 213 214 Set logging driver for all created containers. 215 216 @@option log-opt 217 218 #### **--mac-address**=*MAC address* 219 220 Assign a static mac address to the pod. This option can be specified several times when kube play creates more than one pod. 221 Note: When joining multiple networks use the **--network name:mac=\<mac\>** syntax. 222 223 @@option network 224 225 When no network option is specified and *host* network mode is not configured in the YAML file, a new network stack is created and pods are attached to it making possible pod to pod communication. 226 227 @@option no-hosts 228 229 This option conflicts with host added in the Kubernetes YAML. 230 231 #### **--publish**=*[[ip:][hostPort]:]containerPort[/protocol]* 232 233 Define or override a port definition in the YAML file. 234 235 The lists of ports in the YAML file and the command line are merged. Matching is done by using the **containerPort** field. 236 If **containerPort** exists in both the YAML file and the option, the latter takes precedence. 237 238 #### **--publish-all** 239 240 Setting this option to `true` will expose all ports to the host, 241 even if only specified via **containerPort** in the K8 YAML. 242 In terms of which port will be exposed, **--publish** has higher priority than **hostPort**, has higher priority than 243 **containerPort**. 244 245 If set to `false` (which is the default), only ports defined via **hostPort** 246 or **--publish** are published on the host. 247 248 #### **--quiet**, **-q** 249 250 Suppress output information when pulling images 251 252 #### **--replace** 253 254 Tears down the pods created by a previous run of `kube play` and recreates the pods. This option is used to keep the existing pods up to date based upon the Kubernetes YAML. 255 256 #### **--seccomp-profile-root**=*path* 257 258 Directory path for seccomp profiles (default: "/var/lib/kubelet/seccomp"). (This option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines) 259 260 #### **--start** 261 262 Start the pod after creating it, set to false to only create it. 263 264 @@option tls-verify 265 266 @@option userns.container 267 268 #### **--wait**, **-w** 269 270 Run pods and containers in the foreground. Default is false. 271 272 At any time you can run `podman pod ps` in another shell to view a list of 273 the running pods and containers. 274 275 When attached in the tty mode, you can kill the pods and containers by pressing 276 Ctrl-C or receiving any other interrupt signals. 277 278 All pods, containers, and volumes created with `podman kube play` is removed 279 upon exit. 280 281 ## EXAMPLES 282 283 Recreate the pod and containers described in the specified host YAML file. 284 ``` 285 $ podman kube play demo.yml 286 52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 287 ``` 288 289 Recreate the pod and containers specified in a YAML file sent to stdin. 290 ``` 291 $ cat demo.yml | podman kube play - 292 52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 293 ``` 294 295 Tear down the pod and containers as described in the specified YAML file. 296 ``` 297 $ podman kube play --down demo.yml 298 Pods stopped: 299 52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 300 Pods removed: 301 52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 302 ``` 303 304 Provide multiple configmap files as sources for environment variables within the specified pods and containers. 305 ``` 306 $ podman kube play demo.yml --configmap configmap-foo.yml,configmap-bar.yml 307 52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 308 309 $ podman kube play demo.yml --configmap configmap-foo.yml --configmap configmap-bar.yml 310 52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 311 ``` 312 313 Create a pod connected to two networks with a static ip on each. 314 ``` 315 $ podman kube play demo.yml --network net1:ip=10.89.1.5 --network net2:ip=10.89.10.10 316 52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 317 ``` 318 Please take into account that networks must be created first using podman-network-create(1). 319 320 Create and teardown from a URL pointing to a YAML file. 321 ``` 322 $ podman kube play https://podman.io/demo.yml 323 52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 324 325 $ podman kube play --down https://podman.io/demo.yml 326 Pods stopped: 327 52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 328 Pods removed: 329 52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 330 ``` 331 `podman kube play --down` does not work with a URL if the YAML file the URL points to 332 has been changed or altered. 333 334 @@include ../../kubernetes_support.md 335 336 ## SEE ALSO 337 **[podman(1)](podman.1.md)**, **[podman-kube(1)](podman-kube.1.md)**, **[podman-kube-down(1)](podman-kube-down.1.md)**, **[podman-network-create(1)](podman-network-create.1.md)**, **[podman-kube-generate(1)](podman-kube-generate.1.md)**, **[podman-build(1)](podman-build.1.md)**, **[containers-certs.d(5)](https://github.com/containers/image/blob/main/docs/containers-certs.d.5.md)**