Skip to content

ciuliene/kubernetes_tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubernetes Tools

Python application codecov

Kubernetes Tools can connect to Kubernetes (K8S) and execute some commands without using the command line interface.

Table of Contents

Prerequisites

This tool uses python (version 3.11.x or higher) and kubectl to connect to a K8S cluster. Both softwares must be installed and properly configured. For more information, please visit these links:

Setup for cloud providers

If you want to use this tool with a cloud provider (like Azure, AWS or Google Cloud) you must have the proper CLI installed and configured.

Here is an example for Azure: To connect to an Azure Kubernetes Service (AKS) cluster, you must have the azure-cli installed and properly configured. To configure the K8S context, issue this command:

az aks get-credentials --resource-group <resource-group> --name <cluster-name>

This command must be issued for each cluster you want to manage.

Description

This project aims to simplify operations with K8S containers. Here is the list of developed features:

Feature Description Command
Bash Execute a bash shell in a container kubectl exec <pod> --stdin --tty shell-demo -- /bin/bash
Log Get the log of a container in real-time kubectl logs <pod>

Other useful features are:

  • Set the current K8S context (if there are more than one):
  • Set the the number of replicas of a deployment (deployment scaling)

Usage

NOTE: It is recommended to use this tool inside a virtual environment.

To do this, create a virtual environment:

python -m venv <virtual-env-name> # .gitignore is already set to ignore folder called "venv"

and activate it (for Linux and MacOS) with this command:

source <virtual-env-name>/bin/activate

For more information see this link

Install required packages:

python -m pip install -r requirements.txt

Arguments

Argument Flag Description
Pods Run the main script to management your pods
Filter -f or --filter Run the main script getting filtered pods list
Clusters -c or --clusters List all clusters and set the active one
Deployments -d or --deployments List all deployments and set the number of replicas
Namespaces -ns or --namespaces List all namespaces and set the active one

Run the script with the desired argument. For example, to list all clusters and set the active one:

python main.py --clusters # or -c

To list all deployments and set the number of replicas:

python main.py --deployments # or -d

To list all namespaces and set the active one:

python main.py --namespaces # or -ns

To manage your pods:

python main.py

To manage filtered pod list:

python main.py -f <filters-separated-by-comma> # or --filter

Pods

Once the script is started, it tries to get the list of available pods inside the selected K8S (kubectl get pods). Using arrow keys up and down for moving and enter key to select, the user can choose a pod and then run one of these command:

  • Execute the bash shell of the container
  • See the log of the container in real-time

To stop the script use the escape sequence CTRL+C.

Execute the bash shell of the container

Using this command, the user will be able to execute the shell of a container and run shell commands within it.

Get the log of a container in real-time

For this action, the user will be ask for two other arguments:

Argument Flag Description Type
Tail --tail Get the tail of the log (default is 10) Integer
Follow -f Follow the log (default is false) Bool

Clusters

This command lists all clusters and set the active one. The user can choose a cluster using arrow keys up and down for moving and enter key to select.

Deployments

This command lists all deployments and set the number of replicas. The user can choose a deployment using arrow keys up and down for moving and enter key to select. Then the user will be asked for the number of replicas (greater than or equal to zero).

About

Kubernetes tools

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages