Copy a Kubernetes pod and run commands in its environment

Related tags

DevOps Toolscopypod
Overview

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, copypod will 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 --interactive flag, then the pod will be copied and started as before, but when the pod is running kubectl will be called and connect to the pod where the provided command is then run interactively. When the kubectl program exits the pod will be removed. This is intended for running ad-hoc tasks and processes.

Install

You can either install copypod into a virtual environment directly with:

pip install git+ssh://[email protected]/Memrise/copypod.git

then the program will be available as copypod inside the virtual environment, or you can install it by cloning this repository and then use pipenv to set up a virtual environment where it will get installed into:

git clone [email protected]:Memrise/copypod.git
cd copypod/
pipenv install

Then you can run the program with pipenv run copypod.

Usage

$ copypod --help
usage: copypod [-h] [--context CONTEXT] [-n NAMESPACE] (-l SELECTOR | -p POD) [--container CONTAINER] [-c COMMAND] [-i INTERACTIVE]

Copy a Kubernetes pod and run commands in its environment.

optional arguments:
  -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         Copy the entire environment of the pod but use this Docker image instead (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
[email protected]:/#

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
[email protected]:/# 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
[email protected]:/#

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.

Owner
Memrise
Learn a language. Meet the world.
Memrise
Simple, Pythonic remote execution and deployment.

Welcome to Fabric! Fabric is a high level Python (2.7, 3.4+) library designed to execute shell commands remotely over SSH, yielding useful Python obje

Fabric 13.8k Jan 06, 2023
MagTape is a Policy-as-Code tool for Kubernetes that allows for evaluating Kubernetes resources against a set of defined policies to inform and enforce best practice configurations.

MagTape is a Policy-as-Code tool for Kubernetes that allows for evaluating Kubernetes resources against a set of defined policies to inform and enforce best practice configurations. MagTape includes

T-Mobile 143 Dec 27, 2022
framework providing automatic constructions of vulnerable infrastructures

中文 | English 1 Introduction Metarget = meta- + target, a framework providing automatic constructions of vulnerable infrastructures, used to deploy sim

rambolized 685 Dec 28, 2022
Define and run multi-container applications with Docker

Docker Compose Docker Compose is a tool for running multi-container applications on Docker defined using the Compose file format. A Compose file is us

Docker 28.2k Jan 08, 2023
Containerize a python web application

containerize a python web application introduction this document is part of GDSC at the university of bahrain you don't need to follow along, fell fre

abdullah mosibah 1 Oct 19, 2021
A charmed operator for running PGbouncer on kubernetes.

operator-template Description TODO: Describe your charm in a few paragraphs of Markdown Usage TODO: Provide high-level usage, such as required config

Canonical 1 Dec 01, 2022
Hackergame nc 类题目的 Docker 容器资源限制、动态 flag、网页终端

Hackergame nc 类题目的 Docker 容器资源限制、动态 flag、网页终端 快速入门 配置证书 证书用于验证用户 Token。请确保这里的证书文件(cert.pem)与 Hackergame 平台 配置的证书相同,这样 Hackergame 平台为每个用户生成的 Token 才可以通

USTC Hackergame 68 Nov 09, 2022
Find-Xss - Termux Kurulum Dosyası Eklendi Eğer Hata Alıyorsanız Lütfen Resmini Çekip İnstagramdan Bildiriniz

FindXss Waf Bypass Eklendi !!! PRODUCER: Saep UPDATER: Aser-Vant Download: git c

Aser 2 Apr 17, 2022
Tools for writing awesome Fabric files

About fabtools includes useful functions to help you write your Fabric files. fabtools makes it easier to manage system users, packages, databases, et

1.3k Dec 30, 2022
A declarative Kubeflow Management Tool inspired by Terraform

🍭 KRSH is Alpha version, so many bugs can be reported. If you find a bug, please write an Issue and grow the project together! A declarative Kubeflow

Riiid! 128 Oct 18, 2022
This repository contains useful docker-swarm-tools.

docker-swarm-tools This repository contains useful docker-swarm-tools. swarm-guardian This Docker image is intended to be used in a multihost docker e

NeuroForge GmbH & Co. KG 4 Jan 12, 2022
A little script and trick to make your heroku app run forever without being concerned about dyno hours.

A little script and trick to make your heroku app run forever without being concerned about dyno hours.

Tiararose Biezetta 152 Dec 25, 2022
A Simple script to hunt unused Kubernetes resources.

K8SPurger A Simple script to hunt unused Kubernetes resources. Release History Release 0.3 Added Ingress Added Services Account Adding RoleBindding Re

Yogesh Kunjir 202 Nov 19, 2022
📦 Powerful Package manager which updates plugins & server software for minecraft servers

pluGET A powerful package manager which updates Plugins and Server Software for minecraft servers. Screenshots check all to check installed plugins fo

106 Dec 16, 2022
A Blazing fast Security Auditing tool for Kubernetes

A Blazing fast Security Auditing tool for kubernetes!! Basic Overview Kubestriker performs numerous in depth checks on kubernetes infra to identify th

Vasant Chinnipilli 934 Jan 04, 2023
Play Wordle from any Kubernetes cluster.

wordle-operator 🟩 ⬛ 🟩 🟨 ⬛ Play Wordle from any Kubernetes cluster. Using the power of CustomResourceDefinitions and Kubernetes Operators, now you c

Lucas Melin 1 Jan 15, 2022
Dockerized service to backup all running database containers

Docker Database Backup Dockerized service to automatically backup all of your database containers. Docker Image Tags: docker.io/jandi/database-backup

Jan Dittrich 16 Dec 31, 2022
Ingress patch example by Kustomize

Ingress patch example by Kustomize

Jinu 10 Nov 14, 2022
This project shows how to serve an TF based image classification model as a web service with TFServing, Docker, and Kubernetes(GKE).

Deploying ML models with CPU based TFServing, Docker, and Kubernetes By: Chansung Park and Sayak Paul This project shows how to serve a TensorFlow ima

Chansung Park 104 Dec 28, 2022
strava-offline is a tool to keep a local mirror of Strava activities for further analysis/processing:

strava-offline Overview strava-offline is a tool to keep a local mirror of Strava activities for further analysis/processing: synchronizes metadata ab

Tomáš Janoušek 29 Dec 14, 2022