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
Wiremind Kubernetes helper

Wiremind Kubernetes helper This Python library is a high-level set of Kubernetes Helpers allowing either to manage individual standard Kubernetes cont

Wiremind 3 Oct 09, 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
Automate SSH in python easily!

RedExpect RedExpect makes automating remote machines over SSH very easy to do and is very fast in doing exactly what you ask of it. Based on ssh2-pyth

Red_M 19 Dec 17, 2022
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
Autoscaling volumes for Kubernetes (with the help of Prometheus)

Kubernetes Volume Autoscaler (with Prometheus) This repository contains a service that automatically increases the size of a Persistent Volume Claim i

DevOps Nirvana 142 Dec 28, 2022
Webinar oficial Zabbix Brasil. Uma série de 4 aulas sobre API do Zabbix.

Repositório de scripts do Webinar de API do Zabbix Webinar oficial Zabbix Brasil. Uma série de 4 aulas sobre API do Zabbix. Nossos encontros [x] 04/11

Robert Silva 7 Mar 31, 2022
Coding For Entrepreneurs 100 Jan 01, 2023
DC/OS - The Datacenter Operating System

DC/OS - The Datacenter Operating System The easiest way to run microservices, big data, and containers in production. What is DC/OS? Like traditional

DC/OS 2.3k Jan 06, 2023
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
A repository containing a short tutorial for Docker (with Python).

Docker Tutorial for IFT 6758 Lab In this repository, we examine the advtanges of virtualization, what Docker is and how we can deploy simple programs

Arka Mukherjee 0 Dec 14, 2021
Ansible Collection: A collection of Ansible Modules and Lookup Plugins (MLP) from Linuxfabrik.

ansible_mlp An Ansible collection of Ansible Modules and Lookup Plugins (MLP) from Linuxfabrik. Ansible Bitwarden Item Lookup Plugin Returns a passwor

Linuxfabrik 2 Feb 07, 2022
Dockerized iCloud drive

iCloud-drive-docker is a simple iCloud drive client in Docker environment. It uses pyiCloud python library to interact with iCloud

Mandar Patil 376 Jan 01, 2023
HXVM - Check Host compatibility with the Virtual Machines

HXVM - Check Host compatibility with the Virtual Machines. Features | Installation | Usage Features Takes input from user to compare how many VMs they

Aman Srivastava 4 Oct 15, 2022
🎡 Build Python wheels for all the platforms on CI with minimal configuration.

cibuildwheel Documentation Python wheels are great. Building them across Mac, Linux, Windows, on multiple versions of Python, is not. cibuildwheel is

Python Packaging Authority 1.3k Jan 02, 2023
A colony of interacting processes

NColony Infrastructure for running "colonies" of processes. Hacking $ tox Should DTRT -- if it passes, it means unit tests are passing, and 100% cover

23 Apr 04, 2022
Deploying a production-ready Django project using Nginx and Gunicorn

django-nginx-gunicorn This project is for deploying a production-ready Django project using Nginx and Gunicorn. Running a local server of Django is no

Arash Sayareh 8 Jul 03, 2022
This Docker container is build to run on a server an provide an easy to use interface for every student to vote for their councilors

This Docker container is build to run on a server and provide an easy to use interface for every student to vote for their councilors.

Robin Adelwarth 7 Nov 23, 2022
Let's learn how to build, release and operate your containerized applications to Amazon ECS and AWS Fargate using AWS Copilot.

🚀 Welcome to AWS Copilot Workshop In this workshop, you'll learn how to build, release and operate your containerised applications to Amazon ECS and

Donnie Prakoso 15 Jul 14, 2022
RMRK spy bot for RMRK hackathon

rmrk_spy_bot RMRK spy bot https://t.me/RMRKspyBot for rmrk hacktoberfest https://rmrk.devpost.com/ Birds and items price and rarity estimation Reports

Victor Ryabinin 2 Sep 06, 2022
Supervisor process control system for UNIX

Supervisor Supervisor is a client/server system that allows its users to control a number of processes on UNIX-like operating systems. Supported Platf

Supervisor 7.6k Dec 31, 2022