Copy a Kubernetes pod and run commands in its environment
Project description
copypod
Utility for copying a running Kubernetes pod so you can run commands in a copy of its environment, without worrying about it the pod potentially being removed due to a deploy.
copypod can work in two different modes, depending on if the --interactive
flag is provided:
- If the flag is left out,
copypodwill copy the specified pod and start it. When the pod reaches the "Running" state the name of the pod will be outputted as the only output. This is intended for use in automation scenarios. - If a command is provided with the
--interactiveflag, then the pod will be copied and started as before, but when the pod is runningkubectlwill be called and connect to the pod where the provided command is then run interactively. When thekubectlprogram exits the pod will be removed. This is intended for running ad-hoc tasks and processes.
Install
copypod is available on PyPI. You can install it via pipx:
$ pipx install copypod
Usage
$ copypod --help
usage: copypod [-h] [--context CONTEXT] [-n NAMESPACE] (-l SELECTOR | -p POD) [--container CONTAINER] [-c COMMAND] [-i INTERACTIVE] [--image IMAGE] [--cap-add CAP_ADD]
Copy a Kubernetes pod and run commands in its environment.
options:
-h, --help show this help message and exit
--context CONTEXT Kubectl context to use for configuration (default: None)
-n NAMESPACE, --namespace NAMESPACE
Namespace for where the source pod is located (default: default)
-l SELECTOR, --selector SELECTOR
Label selector of pod to copy (default: None)
-p POD, --pod POD Name of the pod to copy (default: None)
--container CONTAINER
Name of container to copy, only needed if the pod has more than one container (default: None)
-c COMMAND, --command COMMAND
Initial command to run in the copied pod (default: sleep infinity)
-i INTERACTIVE, --interactive INTERACTIVE
Command to run in an interactive console (default: None)
--image IMAGE Set to alternate Docker image to use for copied pod (default: None)
--cap-add CAP_ADD Capabilities to add for the copied pod (default: None)
If the `--interactive` flag is provided, the copied pod will be removed immediately after the command exits, otherwise the name of the pod will be printed.
Examples
Say you wanted to copy the pod named my-great-pod and have the copied pod run
until you specifically remove it, you could run:
$ copypod -p my-great-pod
pod-copy-girwak
pod-copy-girwak is then the name of the new pod created for you, and it will
by default run sleep infinity as the starting command, meaning it will keep
running forever until it's deleted.
At this point you can enter the pod and run commands as you'd like, for instance start a shell inside the pod with:
$ kubectl exec -it pod-copy-girwak -- bash
root@pod-copy-girwak:/#
When you are done you can remove the copied pod again with kubectl:
$ kubectl delete pod pod-copy-girwak
pod "pod-copy-girwak" deleted
Say you instead would like to copy a pod, start a shell in the copied pod and
have the pod be deleted when you exit the shell, you can do that by supplying
the --interactive flag like this:
$ copypod -p my-great-pod -i bash
root@pod-copy-i41u04:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 10:43 ? 00:00:00 sleep infinity
root 7 0 0 10:43 ? 00:00:00 bash
root 13 7 0 10:43 ? 00:00:00 ps -ef
When you are done doing what you needed the pod for, you can exit the shell and the pod will be removed immediately.
The value for the --interactive flag is the command you'd like to start
inside the pod.
Instead of having to look up the name of a pod before running copypod, you
can also specify labels which match one or more pods that you'd like to copy.
copypod will then pick the first pod matching the lables and copy that for
you. This can be done with the --selector flag. It works the same way as for
the kubectl command.
If we for example have one or more pods with the label app: my-great-service
we can copy any of those pods without having to know the exact pod name by
running:
$ copypod -l app=my-great-service -i bash
root@pod-copy-1gk57f:/#
Note regarding Alpine Linux
The sleep command in images based on Alpine Linux does not
support "infinity" as an argument unless the "coreutils" package is installed.
As a work around you can instead specify --command "sleep 1d" as an argument
to copypod to change the command run in the new pod.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file copypod-0.3.0.tar.gz.
File metadata
- Download URL: copypod-0.3.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
985e2f25cb67db89d52049d2a71498c21f39259b2340ff7b1e0df095797f9f24
|
|
| MD5 |
6e9f462be17fba7c17ea9d4832757a01
|
|
| BLAKE2b-256 |
fbe189a76ad7bb34f5f99db2a1b86352dfa38a4c2d7e79c5cde96b4575a82cfc
|
Provenance
The following attestation bundles were made for copypod-0.3.0.tar.gz:
Publisher:
release-to-pypi.yml on Memrise/copypod
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
copypod-0.3.0.tar.gz -
Subject digest:
985e2f25cb67db89d52049d2a71498c21f39259b2340ff7b1e0df095797f9f24 - Sigstore transparency entry: 529118068
- Sigstore integration time:
-
Permalink:
Memrise/copypod@60b01b6cc55b931e308ed60b5e4acac56d05117a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/Memrise
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-to-pypi.yml@60b01b6cc55b931e308ed60b5e4acac56d05117a -
Trigger Event:
push
-
Statement type:
File details
Details for the file copypod-0.3.0-py3-none-any.whl.
File metadata
- Download URL: copypod-0.3.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e49041a864ef397ca51b604aa5f2433a09fd35d7725ff145106881854402bfe
|
|
| MD5 |
8f2ce17ffb7adfb2420666cf0a34f651
|
|
| BLAKE2b-256 |
32d06daaf1e87916eb132bec221567bc458eb8720521d09d23122d57814fa102
|
Provenance
The following attestation bundles were made for copypod-0.3.0-py3-none-any.whl:
Publisher:
release-to-pypi.yml on Memrise/copypod
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
copypod-0.3.0-py3-none-any.whl -
Subject digest:
6e49041a864ef397ca51b604aa5f2433a09fd35d7725ff145106881854402bfe - Sigstore transparency entry: 529118078
- Sigstore integration time:
-
Permalink:
Memrise/copypod@60b01b6cc55b931e308ed60b5e4acac56d05117a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/Memrise
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-to-pypi.yml@60b01b6cc55b931e308ed60b5e4acac56d05117a -
Trigger Event:
push
-
Statement type: