Running ephemeral containers in Kubernetes

Running ephemeral containers in Kubernetes

How to spawn ephemeral containers within a k8s cluster

kubectl has a run command similar to the run command for docker; however, kubectl run runs a container remotely inside a k8s cluster.

kubectl run NAME --image=image [--env="key=value"] [--port=port]
[--dry-run=server|client] [--overrides=inline-json]
[--command] -- [COMMAND] [args...]

This command will spawn a container using the postgres:16 Docker image, connect you to the terminal and remove the container after exiting the terminal:

kubectl run psql --image=postgres:16 -it --rm -- bash