A lightweight, interactive Kubernetes CLI built using Python and the standard cmd module.
This tool interacts directly with the Kubernetes API (no kubectl dependency) and is designed for learning, automation, and day-to-day DevOps operations.
- Interactive shell (
K8s>>prompt) - Namespace management
- List namespaces
- Create namespace
- Delete namespace
- Pod operations
- List pods in a namespace
- List pods using label selectors
- Deployment operations
- List deployments
- List deployments using labels
- Scale deployments
- Cluster operations
- View cluster information
- List kubeconfig contexts
- Show current context
- Manifest validation
- Server-side validation using Kubernetes API (
dry-run=server)
- Server-side validation using Kubernetes API (
.
├── main.py
├── functions/
│ ├── core/
│ │ └── core_cluster.py
│ ├── namespace/
│ │ └── namespace.py
│ ├── pods/
│ │ └── pod.py
│ ├── deployments/
│ │ └── deployment.py
│ └── custom/
│ └── custom.py
---
## 🚀 Getting Started
### Prerequisites
* Python 3.8+
* Kubernetes cluster access
* Valid `~/.kube/config`
* Python Kubernetes client
```bash
pip install kubernetes
python main.pyYou should see:
Welcome to K8s Cli
K8s>>
| Command | Description |
|---|---|
list_namespace |
List all namespaces |
create_namespace <name> |
Create a new namespace |
delete_namespace <name> |
Delete a namespace |
| Command | Description |
|---|---|
list_pod |
List pods in default namespace |
list_pod -n <namespace> |
List pods in a namespace |
list_pod -n <namespace> -l key=value |
List pods using labels |
Example:
K8s>> list_pod default app=nginx
| Command | Description |
|---|---|
list_deployment |
List deployments |
list_deployment -n <namespace> |
List deployments in a namespace |
list_deployment -l key=value |
List deployments using labels |
scale_deployment -a <name> -r <replicas> |
Scale a deployment |
| Command | Description |
|---|---|
cluster_info |
Show cluster information |
list_context |
List all kubeconfig contexts |
list_context --current |
Show current context |
| Command | Description |
|---|---|
quit |
Exit the CLI |
Each command supports built-in help:
K8s>> help
K8s>> help list_pod
- Built using Python's
cmd.Cmd - Uses Kubernetes Python client (no shelling out to
kubectl) - Easy to extend with new commands
- Context switching support
- Resource describe & delete commands
- YAML apply support
- Autocompletion
- Configurable kubeconfig path
- Error handling & logging
Built by Kamal Acharya — DevOps Engineer