k8s-helper-cli 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- k8s_helper_cli-0.1.2/PKG-INFO +975 -0
- k8s_helper_cli-0.1.2/README.md +950 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/pyproject.toml +1 -1
- k8s_helper_cli-0.1.2/src/k8s_helper_cli.egg-info/PKG-INFO +975 -0
- k8s_helper_cli-0.1.1/PKG-INFO +0 -491
- k8s_helper_cli-0.1.1/README.md +0 -466
- k8s_helper_cli-0.1.1/src/k8s_helper_cli.egg-info/PKG-INFO +0 -491
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/LICENSE +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/setup.cfg +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/src/k8s_helper/__init__.py +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/src/k8s_helper/cli.py +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/src/k8s_helper/config.py +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/src/k8s_helper/core.py +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/src/k8s_helper/utils.py +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/src/k8s_helper_cli.egg-info/SOURCES.txt +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/src/k8s_helper_cli.egg-info/dependency_links.txt +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/src/k8s_helper_cli.egg-info/entry_points.txt +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/src/k8s_helper_cli.egg-info/requires.txt +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/src/k8s_helper_cli.egg-info/top_level.txt +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/tests/test_core.py +0 -0
- {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.1.2}/tests/test_integration.py +0 -0
@@ -0,0 +1,975 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: k8s-helper-cli
|
3
|
+
Version: 0.1.2
|
4
|
+
Summary: A simplified Python wrapper for common Kubernetes operations
|
5
|
+
Author-email: Harshit Chatterjee <harshitchatterjee50@gmail.com>
|
6
|
+
License-Expression: MIT
|
7
|
+
Project-URL: Homepage, https://github.com/Harshit1o/k8s-helper
|
8
|
+
Project-URL: Repository, https://github.com/Harshit1o/k8s-helper
|
9
|
+
Project-URL: Bug Tracker, https://github.com/Harshit1o/k8s-helper/issues
|
10
|
+
Requires-Python: >=3.8
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
License-File: LICENSE
|
13
|
+
Requires-Dist: kubernetes>=26.1.0
|
14
|
+
Requires-Dist: typer>=0.9.0
|
15
|
+
Requires-Dist: rich>=13.0.0
|
16
|
+
Requires-Dist: pyyaml>=6.0
|
17
|
+
Provides-Extra: dev
|
18
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
19
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
|
20
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
21
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
22
|
+
Requires-Dist: flake8>=4.0.0; extra == "dev"
|
23
|
+
Requires-Dist: mypy>=0.991; extra == "dev"
|
24
|
+
Dynamic: license-file
|
25
|
+
|
26
|
+
# k8s-helper
|
27
|
+
|
28
|
+
A simplified Python wrapper for common Kubernetes operations that makes it easy to manage pods, deployments, services, and more.
|
29
|
+
|
30
|
+
## Features
|
31
|
+
|
32
|
+
- ✅ **Pod Management**: Create, delete, and list pods
|
33
|
+
- ✅ **Deployment Management**: Create, delete, scale, and list deployments
|
34
|
+
- ✅ **Service Management**: Create, delete, and list services
|
35
|
+
- ✅ **Resource Monitoring**: Get logs, events, and resource descriptions
|
36
|
+
- ✅ **Easy Configuration**: Simple configuration management
|
37
|
+
- ✅ **Formatted Output**: Beautiful table, YAML, and JSON output formats
|
38
|
+
- ✅ **Error Handling**: Comprehensive error handling with helpful messages
|
39
|
+
- ✅ **Quick Functions**: Convenience functions for common tasks
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
```bash
|
44
|
+
pip install k8s-helper-cli
|
45
|
+
```
|
46
|
+
|
47
|
+
### Development Installation
|
48
|
+
|
49
|
+
```bash
|
50
|
+
git clone https://github.com/Harshit1o/k8s-helper.git
|
51
|
+
cd k8s-helper
|
52
|
+
pip install -e .
|
53
|
+
```
|
54
|
+
|
55
|
+
## Prerequisites
|
56
|
+
|
57
|
+
- Python 3.8+
|
58
|
+
- kubectl configured with access to a Kubernetes cluster
|
59
|
+
- Kubernetes cluster (local or remote)
|
60
|
+
|
61
|
+
**Important**: k8s-helper requires an active Kubernetes cluster connection. Without a properly configured kubectl and accessible cluster, the commands will fail with configuration errors.
|
62
|
+
|
63
|
+
### Setting up Kubernetes (Choose one):
|
64
|
+
|
65
|
+
1. **Local Development**:
|
66
|
+
- [minikube](https://minikube.sigs.k8s.io/docs/start/)
|
67
|
+
- [kind](https://kind.sigs.k8s.io/docs/user/quick-start/)
|
68
|
+
- [Docker Desktop](https://docs.docker.com/desktop/kubernetes/) (Enable Kubernetes)
|
69
|
+
|
70
|
+
2. **Cloud Providers**:
|
71
|
+
- [Google Kubernetes Engine (GKE)](https://cloud.google.com/kubernetes-engine)
|
72
|
+
- [Amazon Elastic Kubernetes Service (EKS)](https://aws.amazon.com/eks/)
|
73
|
+
- [Azure Kubernetes Service (AKS)](https://azure.microsoft.com/en-us/services/kubernetes-service/)
|
74
|
+
|
75
|
+
3. **Verify Setup**:
|
76
|
+
```bash
|
77
|
+
# Check if kubectl is configured
|
78
|
+
kubectl cluster-info
|
79
|
+
|
80
|
+
# List nodes to verify cluster access
|
81
|
+
kubectl get nodes
|
82
|
+
```
|
83
|
+
|
84
|
+
## Quick Start
|
85
|
+
|
86
|
+
```python
|
87
|
+
from k8s_helper import K8sClient
|
88
|
+
|
89
|
+
# Initialize client with default namespace
|
90
|
+
client = K8sClient()
|
91
|
+
|
92
|
+
# Or specify a namespace
|
93
|
+
client = K8sClient(namespace="my-namespace")
|
94
|
+
|
95
|
+
# Create a deployment
|
96
|
+
client.create_deployment(
|
97
|
+
name="my-app",
|
98
|
+
image="nginx:latest",
|
99
|
+
replicas=3,
|
100
|
+
container_port=80
|
101
|
+
)
|
102
|
+
|
103
|
+
# Create a service
|
104
|
+
client.create_service(
|
105
|
+
name="my-app-service",
|
106
|
+
port=80,
|
107
|
+
target_port=80,
|
108
|
+
service_type="ClusterIP"
|
109
|
+
)
|
110
|
+
|
111
|
+
# Scale deployment
|
112
|
+
client.scale_deployment("my-app", replicas=5)
|
113
|
+
|
114
|
+
# Get logs
|
115
|
+
logs = client.get_logs("my-app-pod-12345")
|
116
|
+
|
117
|
+
# List resources
|
118
|
+
pods = client.list_pods()
|
119
|
+
deployments = client.list_deployments()
|
120
|
+
services = client.list_services()
|
121
|
+
```
|
122
|
+
|
123
|
+
## Detailed Usage
|
124
|
+
|
125
|
+
### Pod Management
|
126
|
+
|
127
|
+
```python
|
128
|
+
# Create a pod
|
129
|
+
client.create_pod(
|
130
|
+
name="my-pod",
|
131
|
+
image="nginx:latest",
|
132
|
+
container_port=80,
|
133
|
+
env_vars={"ENV": "production", "DEBUG": "false"},
|
134
|
+
labels={"app": "my-app", "version": "v1.0"}
|
135
|
+
)
|
136
|
+
|
137
|
+
# Delete a pod
|
138
|
+
client.delete_pod("my-pod")
|
139
|
+
|
140
|
+
# List all pods
|
141
|
+
pods = client.list_pods()
|
142
|
+
print(format_pod_list(pods))
|
143
|
+
|
144
|
+
# Describe a pod
|
145
|
+
pod_info = client.describe_pod("my-pod")
|
146
|
+
```
|
147
|
+
|
148
|
+
### Deployment Management
|
149
|
+
|
150
|
+
```python
|
151
|
+
# Create a deployment with environment variables
|
152
|
+
client.create_deployment(
|
153
|
+
name="my-app",
|
154
|
+
image="nginx:latest",
|
155
|
+
replicas=3,
|
156
|
+
container_port=80,
|
157
|
+
env_vars={"ENV": "production"},
|
158
|
+
labels={"app": "my-app", "tier": "frontend"}
|
159
|
+
)
|
160
|
+
|
161
|
+
# Scale deployment
|
162
|
+
client.scale_deployment("my-app", replicas=5)
|
163
|
+
|
164
|
+
# Delete deployment
|
165
|
+
client.delete_deployment("my-app")
|
166
|
+
|
167
|
+
# List deployments
|
168
|
+
deployments = client.list_deployments()
|
169
|
+
print(format_deployment_list(deployments))
|
170
|
+
|
171
|
+
# Wait for deployment to be ready
|
172
|
+
client.wait_for_deployment_ready("my-app", timeout=300)
|
173
|
+
```
|
174
|
+
|
175
|
+
### Service Management
|
176
|
+
|
177
|
+
```python
|
178
|
+
# Create a ClusterIP service
|
179
|
+
client.create_service(
|
180
|
+
name="my-app-service",
|
181
|
+
port=80,
|
182
|
+
target_port=8080,
|
183
|
+
service_type="ClusterIP"
|
184
|
+
)
|
185
|
+
|
186
|
+
# Create a LoadBalancer service
|
187
|
+
client.create_service(
|
188
|
+
name="my-app-lb",
|
189
|
+
port=80,
|
190
|
+
target_port=80,
|
191
|
+
service_type="LoadBalancer",
|
192
|
+
selector={"app": "my-app"}
|
193
|
+
)
|
194
|
+
|
195
|
+
# Delete service
|
196
|
+
client.delete_service("my-app-service")
|
197
|
+
|
198
|
+
# List services
|
199
|
+
services = client.list_services()
|
200
|
+
print(format_service_list(services))
|
201
|
+
```
|
202
|
+
|
203
|
+
### Logs and Events
|
204
|
+
|
205
|
+
```python
|
206
|
+
# Get pod logs
|
207
|
+
logs = client.get_logs("my-pod")
|
208
|
+
|
209
|
+
# Get logs with tail
|
210
|
+
logs = client.get_logs("my-pod", tail_lines=100)
|
211
|
+
|
212
|
+
# Get logs from specific container
|
213
|
+
logs = client.get_logs("my-pod", container_name="nginx")
|
214
|
+
|
215
|
+
# Get events
|
216
|
+
events = client.get_events()
|
217
|
+
print(format_events(events))
|
218
|
+
|
219
|
+
# Get events for specific resource
|
220
|
+
events = client.get_events("my-pod")
|
221
|
+
```
|
222
|
+
|
223
|
+
### Resource Description
|
224
|
+
|
225
|
+
```python
|
226
|
+
# Describe pod
|
227
|
+
pod_info = client.describe_pod("my-pod")
|
228
|
+
print(format_yaml_output(pod_info))
|
229
|
+
|
230
|
+
# Describe deployment
|
231
|
+
deployment_info = client.describe_deployment("my-app")
|
232
|
+
print(format_json_output(deployment_info))
|
233
|
+
|
234
|
+
# Describe service
|
235
|
+
service_info = client.describe_service("my-service")
|
236
|
+
```
|
237
|
+
|
238
|
+
## Quick Functions
|
239
|
+
|
240
|
+
For simple operations, use the convenience functions:
|
241
|
+
|
242
|
+
```python
|
243
|
+
from k8s_helper import (
|
244
|
+
quick_deployment,
|
245
|
+
quick_service,
|
246
|
+
quick_scale,
|
247
|
+
quick_logs,
|
248
|
+
quick_delete_deployment,
|
249
|
+
quick_delete_service
|
250
|
+
)
|
251
|
+
|
252
|
+
# Quick deployment
|
253
|
+
quick_deployment("my-app", "nginx:latest", replicas=3)
|
254
|
+
|
255
|
+
# Quick service
|
256
|
+
quick_service("my-service", port=80)
|
257
|
+
|
258
|
+
# Quick scaling
|
259
|
+
quick_scale("my-app", replicas=5)
|
260
|
+
|
261
|
+
# Quick logs
|
262
|
+
logs = quick_logs("my-pod")
|
263
|
+
|
264
|
+
# Quick cleanup
|
265
|
+
quick_delete_deployment("my-app")
|
266
|
+
quick_delete_service("my-service")
|
267
|
+
```
|
268
|
+
|
269
|
+
## Configuration
|
270
|
+
|
271
|
+
k8s-helper supports configuration through files and environment variables:
|
272
|
+
|
273
|
+
```python
|
274
|
+
from k8s_helper import get_config
|
275
|
+
|
276
|
+
# Get configuration
|
277
|
+
config = get_config()
|
278
|
+
|
279
|
+
# Set default namespace
|
280
|
+
config.set_namespace("my-namespace")
|
281
|
+
|
282
|
+
# Set output format
|
283
|
+
config.set_output_format("yaml") # table, yaml, json
|
284
|
+
|
285
|
+
# Set timeout
|
286
|
+
config.set_timeout(600)
|
287
|
+
|
288
|
+
# Save configuration
|
289
|
+
config.save_config()
|
290
|
+
```
|
291
|
+
|
292
|
+
### Environment Variables
|
293
|
+
|
294
|
+
- `K8S_HELPER_NAMESPACE`: Default namespace
|
295
|
+
- `K8S_HELPER_OUTPUT_FORMAT`: Output format (table, yaml, json)
|
296
|
+
- `K8S_HELPER_TIMEOUT`: Default timeout in seconds
|
297
|
+
- `K8S_HELPER_VERBOSE`: Enable verbose output (true/false)
|
298
|
+
- `KUBECONFIG`: Path to kubectl config file
|
299
|
+
|
300
|
+
## Output Formatting
|
301
|
+
|
302
|
+
The library provides several output formats:
|
303
|
+
|
304
|
+
```python
|
305
|
+
from k8s_helper.utils import (
|
306
|
+
format_pod_list,
|
307
|
+
format_deployment_list,
|
308
|
+
format_service_list,
|
309
|
+
format_events,
|
310
|
+
format_yaml_output,
|
311
|
+
format_json_output
|
312
|
+
)
|
313
|
+
|
314
|
+
# Format as table
|
315
|
+
pods = client.list_pods()
|
316
|
+
print(format_pod_list(pods))
|
317
|
+
|
318
|
+
# Format as YAML
|
319
|
+
pod_info = client.describe_pod("my-pod")
|
320
|
+
print(format_yaml_output(pod_info))
|
321
|
+
|
322
|
+
# Format as JSON
|
323
|
+
deployment_info = client.describe_deployment("my-app")
|
324
|
+
print(format_json_output(deployment_info))
|
325
|
+
```
|
326
|
+
|
327
|
+
## Error Handling
|
328
|
+
|
329
|
+
The library provides comprehensive error handling:
|
330
|
+
|
331
|
+
```python
|
332
|
+
# All operations return None/False on failure
|
333
|
+
result = client.create_deployment("my-app", "nginx:latest")
|
334
|
+
if result is None:
|
335
|
+
print("Failed to create deployment")
|
336
|
+
|
337
|
+
# Boolean operations return True/False
|
338
|
+
success = client.delete_deployment("my-app")
|
339
|
+
if not success:
|
340
|
+
print("Failed to delete deployment")
|
341
|
+
|
342
|
+
# Use try-except for custom error handling
|
343
|
+
try:
|
344
|
+
client.create_deployment("my-app", "nginx:latest")
|
345
|
+
except Exception as e:
|
346
|
+
print(f"Error: {e}")
|
347
|
+
```
|
348
|
+
|
349
|
+
## Advanced Usage
|
350
|
+
|
351
|
+
### Using YAML Manifests
|
352
|
+
|
353
|
+
```python
|
354
|
+
from k8s_helper.utils import create_deployment_manifest, create_service_manifest
|
355
|
+
|
356
|
+
# Create deployment manifest
|
357
|
+
deployment_manifest = create_deployment_manifest(
|
358
|
+
name="my-app",
|
359
|
+
image="nginx:latest",
|
360
|
+
replicas=3,
|
361
|
+
port=80,
|
362
|
+
env_vars={"ENV": "production"},
|
363
|
+
labels={"app": "my-app"}
|
364
|
+
)
|
365
|
+
|
366
|
+
# Create service manifest
|
367
|
+
service_manifest = create_service_manifest(
|
368
|
+
name="my-app-service",
|
369
|
+
port=80,
|
370
|
+
target_port=80,
|
371
|
+
service_type="ClusterIP",
|
372
|
+
selector={"app": "my-app"}
|
373
|
+
)
|
374
|
+
|
375
|
+
print(format_yaml_output(deployment_manifest))
|
376
|
+
```
|
377
|
+
|
378
|
+
### Working with Multiple Namespaces
|
379
|
+
|
380
|
+
```python
|
381
|
+
# Create clients for different namespaces
|
382
|
+
prod_client = K8sClient(namespace="production")
|
383
|
+
dev_client = K8sClient(namespace="development")
|
384
|
+
|
385
|
+
# Deploy to production
|
386
|
+
prod_client.create_deployment("my-app", "nginx:1.20", replicas=5)
|
387
|
+
|
388
|
+
# Deploy to development
|
389
|
+
dev_client.create_deployment("my-app", "nginx:latest", replicas=1)
|
390
|
+
```
|
391
|
+
|
392
|
+
### Monitoring and Health Checks
|
393
|
+
|
394
|
+
```python
|
395
|
+
# Check namespace resources
|
396
|
+
resources = client.get_namespace_resources()
|
397
|
+
print(f"Pods: {resources['pods']}")
|
398
|
+
print(f"Deployments: {resources['deployments']}")
|
399
|
+
print(f"Services: {resources['services']}")
|
400
|
+
|
401
|
+
# Wait for deployment to be ready
|
402
|
+
if client.wait_for_deployment_ready("my-app", timeout=300):
|
403
|
+
print("Deployment is ready!")
|
404
|
+
else:
|
405
|
+
print("Deployment failed to become ready")
|
406
|
+
```
|
407
|
+
|
408
|
+
## Examples
|
409
|
+
|
410
|
+
### Complete Application Deployment
|
411
|
+
|
412
|
+
```python
|
413
|
+
from k8s_helper import K8sClient
|
414
|
+
|
415
|
+
# Initialize client
|
416
|
+
client = K8sClient(namespace="my-app")
|
417
|
+
|
418
|
+
# Create deployment
|
419
|
+
client.create_deployment(
|
420
|
+
name="web-app",
|
421
|
+
image="nginx:latest",
|
422
|
+
replicas=3,
|
423
|
+
container_port=80,
|
424
|
+
env_vars={"ENV": "production"},
|
425
|
+
labels={"app": "web-app", "tier": "frontend"}
|
426
|
+
)
|
427
|
+
|
428
|
+
# Create service
|
429
|
+
client.create_service(
|
430
|
+
name="web-app-service",
|
431
|
+
port=80,
|
432
|
+
target_port=80,
|
433
|
+
service_type="LoadBalancer",
|
434
|
+
selector={"app": "web-app"}
|
435
|
+
)
|
436
|
+
|
437
|
+
# Wait for deployment to be ready
|
438
|
+
if client.wait_for_deployment_ready("web-app"):
|
439
|
+
print("✅ Application deployed successfully!")
|
440
|
+
|
441
|
+
# Show status
|
442
|
+
print("\nDeployments:")
|
443
|
+
print(format_deployment_list(client.list_deployments()))
|
444
|
+
|
445
|
+
print("\nServices:")
|
446
|
+
print(format_service_list(client.list_services()))
|
447
|
+
|
448
|
+
print("\nPods:")
|
449
|
+
print(format_pod_list(client.list_pods()))
|
450
|
+
else:
|
451
|
+
print("❌ Deployment failed!")
|
452
|
+
```
|
453
|
+
|
454
|
+
### Cleanup Script
|
455
|
+
|
456
|
+
```python
|
457
|
+
from k8s_helper import K8sClient
|
458
|
+
|
459
|
+
client = K8sClient(namespace="my-app")
|
460
|
+
|
461
|
+
# Clean up resources
|
462
|
+
resources_to_clean = [
|
463
|
+
"web-app",
|
464
|
+
"database",
|
465
|
+
"cache"
|
466
|
+
]
|
467
|
+
|
468
|
+
for resource in resources_to_clean:
|
469
|
+
print(f"Cleaning up {resource}...")
|
470
|
+
client.delete_deployment(resource)
|
471
|
+
client.delete_service(f"{resource}-service")
|
472
|
+
|
473
|
+
print("✅ Cleanup completed!")
|
474
|
+
```
|
475
|
+
|
476
|
+
## Contributing
|
477
|
+
|
478
|
+
1. Fork the repository
|
479
|
+
2. Create a feature branch
|
480
|
+
3. Make your changes
|
481
|
+
4. Add tests
|
482
|
+
5. Submit a pull request
|
483
|
+
|
484
|
+
## Testing
|
485
|
+
|
486
|
+
```bash
|
487
|
+
# Install test dependencies
|
488
|
+
pip install pytest pytest-mock
|
489
|
+
|
490
|
+
# Run tests
|
491
|
+
pytest tests/
|
492
|
+
|
493
|
+
# Run tests with coverage
|
494
|
+
pytest --cov=k8s_helper tests/
|
495
|
+
```
|
496
|
+
|
497
|
+
## License
|
498
|
+
|
499
|
+
MIT License - see LICENSE file for details.
|
500
|
+
|
501
|
+
## Support
|
502
|
+
|
503
|
+
- GitHub Issues: [Report bugs or request features](https://github.com/Harshit1o/k8s-helper/issues)
|
504
|
+
- Documentation: [Full documentation](https://github.com/Harshit1o/k8s-helper)
|
505
|
+
|
506
|
+
## Changelog
|
507
|
+
|
508
|
+
### v0.1.0
|
509
|
+
- Initial release
|
510
|
+
- Basic pod, deployment, and service management
|
511
|
+
- Configuration management
|
512
|
+
- Comprehensive error handling
|
513
|
+
- Multiple output formats
|
514
|
+
- Quick convenience functions
|
515
|
+
|
516
|
+
## CLI Usage
|
517
|
+
|
518
|
+
k8s-helper provides a command-line interface for Kubernetes operations. After installation, you can use the `k8s-helper` command directly in your terminal.
|
519
|
+
|
520
|
+
### Available Commands
|
521
|
+
|
522
|
+
```bash
|
523
|
+
# Show help
|
524
|
+
k8s-helper --help
|
525
|
+
|
526
|
+
# Configure settings
|
527
|
+
k8s-helper config --namespace my-namespace
|
528
|
+
k8s-helper config --output-format yaml
|
529
|
+
k8s-helper config --timeout 300
|
530
|
+
k8s-helper config --show # Show current configuration
|
531
|
+
```
|
532
|
+
|
533
|
+
### Pod Management
|
534
|
+
|
535
|
+
```bash
|
536
|
+
# Create a pod
|
537
|
+
k8s-helper create-pod my-pod nginx:latest --namespace my-namespace
|
538
|
+
|
539
|
+
# Delete a pod
|
540
|
+
k8s-helper delete-pod my-pod --namespace my-namespace
|
541
|
+
|
542
|
+
# List pods
|
543
|
+
k8s-helper list-pods --namespace my-namespace
|
544
|
+
k8s-helper list-pods --output yaml
|
545
|
+
|
546
|
+
# Get pod logs
|
547
|
+
k8s-helper logs my-pod --namespace my-namespace
|
548
|
+
```
|
549
|
+
|
550
|
+
### Deployment Management
|
551
|
+
|
552
|
+
```bash
|
553
|
+
# Create a deployment
|
554
|
+
k8s-helper create-deployment my-app nginx:latest --replicas 3 --namespace my-namespace
|
555
|
+
|
556
|
+
# Scale a deployment
|
557
|
+
k8s-helper scale-deployment my-app --replicas 5 --namespace my-namespace
|
558
|
+
|
559
|
+
# Delete a deployment
|
560
|
+
k8s-helper delete-deployment my-app --namespace my-namespace
|
561
|
+
|
562
|
+
# List deployments
|
563
|
+
k8s-helper list-deployments --namespace my-namespace
|
564
|
+
k8s-helper list-deployments --output yaml
|
565
|
+
```
|
566
|
+
|
567
|
+
### Service Management
|
568
|
+
|
569
|
+
```bash
|
570
|
+
# Create a service
|
571
|
+
k8s-helper create-service my-service --port 80 --target-port 8080 --type ClusterIP --namespace my-namespace
|
572
|
+
|
573
|
+
# Delete a service
|
574
|
+
k8s-helper delete-service my-service --namespace my-namespace
|
575
|
+
|
576
|
+
# List services
|
577
|
+
k8s-helper list-services --namespace my-namespace
|
578
|
+
k8s-helper list-services --output yaml
|
579
|
+
```
|
580
|
+
|
581
|
+
### Monitoring and Events
|
582
|
+
|
583
|
+
```bash
|
584
|
+
# Get events
|
585
|
+
k8s-helper events --namespace my-namespace
|
586
|
+
|
587
|
+
# Get namespace status
|
588
|
+
k8s-helper status --namespace my-namespace
|
589
|
+
|
590
|
+
# Describe resources
|
591
|
+
k8s-helper describe pod my-pod --namespace my-namespace
|
592
|
+
k8s-helper describe deployment my-app --namespace my-namespace
|
593
|
+
k8s-helper describe service my-service --namespace my-namespace
|
594
|
+
```
|
595
|
+
|
596
|
+
### Application Deployment
|
597
|
+
|
598
|
+
```bash
|
599
|
+
# Deploy a complete application (deployment + service)
|
600
|
+
k8s-helper apply my-app nginx:latest --replicas 3 --port 80 --service-type LoadBalancer --namespace my-namespace
|
601
|
+
|
602
|
+
# Clean up an application (delete deployment + service)
|
603
|
+
k8s-helper cleanup my-app --namespace my-namespace
|
604
|
+
```
|
605
|
+
|
606
|
+
### Basic Examples
|
607
|
+
|
608
|
+
#### Deploy a Web Application
|
609
|
+
```bash
|
610
|
+
# Deploy nginx with 3 replicas and LoadBalancer service
|
611
|
+
k8s-helper apply webapp nginx:latest --replicas 3 --port 80 --service-type LoadBalancer
|
612
|
+
|
613
|
+
# Check deployment status
|
614
|
+
k8s-helper list-deployments
|
615
|
+
k8s-helper list-services
|
616
|
+
k8s-helper status
|
617
|
+
```
|
618
|
+
|
619
|
+
#### Deploy a Database
|
620
|
+
```bash
|
621
|
+
# Deploy postgres
|
622
|
+
k8s-helper create-deployment postgres-db postgres:13 --replicas 1
|
623
|
+
k8s-helper create-service postgres-service --port 5432 --target-port 5432 --type ClusterIP
|
624
|
+
|
625
|
+
# Check logs
|
626
|
+
k8s-helper logs postgres-db
|
627
|
+
```
|
628
|
+
|
629
|
+
#### Scale Applications
|
630
|
+
```bash
|
631
|
+
# Scale web application
|
632
|
+
k8s-helper scale-deployment webapp --replicas 5
|
633
|
+
|
634
|
+
# Check scaling
|
635
|
+
k8s-helper list-deployments
|
636
|
+
```
|
637
|
+
|
638
|
+
#### Clean Up
|
639
|
+
```bash
|
640
|
+
# Clean up the web application
|
641
|
+
k8s-helper cleanup webapp
|
642
|
+
|
643
|
+
# Or delete components individually
|
644
|
+
k8s-helper delete-deployment postgres-db
|
645
|
+
k8s-helper delete-service postgres-service
|
646
|
+
```
|
647
|
+
|
648
|
+
### Configuration
|
649
|
+
|
650
|
+
```bash
|
651
|
+
# Set default namespace
|
652
|
+
k8s-helper config --namespace production
|
653
|
+
|
654
|
+
# Set output format
|
655
|
+
k8s-helper config --output-format yaml
|
656
|
+
|
657
|
+
# Show current configuration
|
658
|
+
k8s-helper config --show
|
659
|
+
```
|
660
|
+
|
661
|
+
### Output Formats
|
662
|
+
|
663
|
+
The CLI supports different output formats:
|
664
|
+
|
665
|
+
```bash
|
666
|
+
# Table format (default)
|
667
|
+
k8s-helper list-pods
|
668
|
+
|
669
|
+
# YAML format
|
670
|
+
k8s-helper list-pods --output yaml
|
671
|
+
|
672
|
+
# JSON format
|
673
|
+
k8s-helper list-pods --output json
|
674
|
+
```
|
675
|
+
|
676
|
+
### Environment Variables
|
677
|
+
|
678
|
+
```bash
|
679
|
+
# Set default namespace
|
680
|
+
export K8S_HELPER_NAMESPACE=my-namespace
|
681
|
+
|
682
|
+
# Set output format
|
683
|
+
export K8S_HELPER_OUTPUT_FORMAT=yaml
|
684
|
+
|
685
|
+
# Now all commands will use these defaults
|
686
|
+
k8s-helper list-pods
|
687
|
+
```
|
688
|
+
|
689
|
+
### Shell Completion
|
690
|
+
|
691
|
+
```bash
|
692
|
+
# Install completion for bash
|
693
|
+
k8s-helper --install-completion bash
|
694
|
+
|
695
|
+
# Install completion for zsh
|
696
|
+
k8s-helper --install-completion zsh
|
697
|
+
|
698
|
+
# Show completion script
|
699
|
+
k8s-helper --show-completion bash
|
700
|
+
```
|
701
|
+
|
702
|
+
## Real-World Examples
|
703
|
+
|
704
|
+
### 1. Simple Web Application
|
705
|
+
|
706
|
+
```bash
|
707
|
+
# Deploy a web application
|
708
|
+
k8s-helper apply webapp nginx:latest --replicas 3 --port 80 --service-type LoadBalancer
|
709
|
+
|
710
|
+
# Check deployment
|
711
|
+
k8s-helper list-deployments
|
712
|
+
k8s-helper list-services
|
713
|
+
k8s-helper status
|
714
|
+
```
|
715
|
+
|
716
|
+
### 2. Database Setup
|
717
|
+
|
718
|
+
```bash
|
719
|
+
# Deploy PostgreSQL database
|
720
|
+
k8s-helper create-deployment postgres-db postgres:13 --replicas 1
|
721
|
+
k8s-helper create-service postgres-service --port 5432 --target-port 5432 --type ClusterIP
|
722
|
+
|
723
|
+
# Check database
|
724
|
+
k8s-helper logs postgres-db
|
725
|
+
k8s-helper describe deployment postgres-db
|
726
|
+
```
|
727
|
+
|
728
|
+
### 3. Multi-Environment Deployment
|
729
|
+
|
730
|
+
```bash
|
731
|
+
# Production
|
732
|
+
k8s-helper config --namespace production
|
733
|
+
k8s-helper apply webapp myapp:v1.0.0 --replicas 5 --port 8080 --service-type LoadBalancer
|
734
|
+
|
735
|
+
# Staging
|
736
|
+
k8s-helper config --namespace staging
|
737
|
+
k8s-helper apply webapp myapp:v1.1.0-rc1 --replicas 2 --port 8080 --service-type ClusterIP
|
738
|
+
|
739
|
+
# Development
|
740
|
+
k8s-helper config --namespace development
|
741
|
+
k8s-helper apply webapp myapp:latest --replicas 1 --port 8080 --service-type NodePort
|
742
|
+
```
|
743
|
+
|
744
|
+
### 4. Application Scaling
|
745
|
+
|
746
|
+
```bash
|
747
|
+
# Scale up for high traffic
|
748
|
+
k8s-helper scale-deployment webapp --replicas 10
|
749
|
+
|
750
|
+
# Monitor scaling
|
751
|
+
k8s-helper list-deployments
|
752
|
+
k8s-helper events
|
753
|
+
|
754
|
+
# Scale down after traffic reduces
|
755
|
+
k8s-helper scale-deployment webapp --replicas 3
|
756
|
+
```
|
757
|
+
|
758
|
+
### 5. Debugging and Monitoring
|
759
|
+
|
760
|
+
```bash
|
761
|
+
# Get comprehensive status
|
762
|
+
k8s-helper status
|
763
|
+
k8s-helper list-deployments
|
764
|
+
k8s-helper list-pods
|
765
|
+
k8s-helper list-services
|
766
|
+
|
767
|
+
# Check logs
|
768
|
+
k8s-helper logs webapp
|
769
|
+
|
770
|
+
# Get events
|
771
|
+
k8s-helper events
|
772
|
+
|
773
|
+
# Describe resources
|
774
|
+
k8s-helper describe deployment webapp
|
775
|
+
k8s-helper describe service webapp-service
|
776
|
+
```
|
777
|
+
|
778
|
+
### 6. Clean Up
|
779
|
+
|
780
|
+
```bash
|
781
|
+
# Clean up complete application
|
782
|
+
k8s-helper cleanup webapp
|
783
|
+
|
784
|
+
# Or clean up individual components
|
785
|
+
k8s-helper delete-deployment postgres-db
|
786
|
+
k8s-helper delete-service postgres-service
|
787
|
+
```
|
788
|
+
|
789
|
+
## Best Practices
|
790
|
+
|
791
|
+
### 1. Resource Management
|
792
|
+
```bash
|
793
|
+
# Use appropriate replica counts for high availability
|
794
|
+
k8s-helper apply my-app nginx:latest --replicas 3
|
795
|
+
|
796
|
+
# Monitor resource usage
|
797
|
+
k8s-helper status
|
798
|
+
k8s-helper list-deployments
|
799
|
+
```
|
800
|
+
|
801
|
+
### 2. Environment Management
|
802
|
+
```bash
|
803
|
+
# Use different namespaces for different environments
|
804
|
+
k8s-helper config --namespace production
|
805
|
+
k8s-helper config --namespace staging
|
806
|
+
k8s-helper config --namespace development
|
807
|
+
```
|
808
|
+
|
809
|
+
### 3. Service Types
|
810
|
+
```bash
|
811
|
+
# Use ClusterIP for internal services
|
812
|
+
k8s-helper create-service internal-api --port 8080 --type ClusterIP
|
813
|
+
|
814
|
+
# Use LoadBalancer for external access
|
815
|
+
k8s-helper create-service public-web --port 80 --type LoadBalancer
|
816
|
+
```
|
817
|
+
|
818
|
+
### 4. Monitoring and Debugging
|
819
|
+
```bash
|
820
|
+
# Regular health checks
|
821
|
+
k8s-helper status
|
822
|
+
k8s-helper events
|
823
|
+
|
824
|
+
# Log monitoring
|
825
|
+
k8s-helper logs my-app
|
826
|
+
```
|
827
|
+
|
828
|
+
### 5. Configuration Management
|
829
|
+
```bash
|
830
|
+
# Set sensible defaults
|
831
|
+
k8s-helper config --namespace my-app
|
832
|
+
k8s-helper config --output-format yaml
|
833
|
+
```
|
834
|
+
|
835
|
+
## Limitations
|
836
|
+
|
837
|
+
**Important**: k8s-helper requires an active Kubernetes cluster connection to function. The CLI and Python API will fail if:
|
838
|
+
|
839
|
+
- No kubectl configuration is found (`~/.kube/config`)
|
840
|
+
- No active Kubernetes cluster is available
|
841
|
+
- kubectl is not properly configured
|
842
|
+
|
843
|
+
### Current CLI Limitations:
|
844
|
+
|
845
|
+
- **Resource limits**: `--cpu-limit` and `--memory-limit` options are not implemented
|
846
|
+
- **Advanced logging**: `--tail`, `--follow`, `--container` options are not available
|
847
|
+
- **Advanced options**: Some documented options like `--env`, `--labels` may not be available in all commands
|
848
|
+
- **Batch operations**: Multiple resource operations in single commands are not supported
|
849
|
+
- **Advanced monitoring**: `--watch`, `--since`, `--all-namespaces` options are not implemented
|
850
|
+
|
851
|
+
### Error Handling:
|
852
|
+
|
853
|
+
If you see errors like:
|
854
|
+
```
|
855
|
+
ConfigException: Invalid kube-config file. No configuration found.
|
856
|
+
ConfigException: Service host/port is not set.
|
857
|
+
```
|
858
|
+
|
859
|
+
This means you need to:
|
860
|
+
1. Install and configure kubectl
|
861
|
+
2. Set up access to a Kubernetes cluster
|
862
|
+
3. Verify with `kubectl cluster-info`
|
863
|
+
|
864
|
+
The CLI provides core functionality for basic Kubernetes operations. For advanced features, use the Python API directly or kubectl.
|
865
|
+
|
866
|
+
## Troubleshooting
|
867
|
+
|
868
|
+
### Common Issues
|
869
|
+
|
870
|
+
#### 1. Kubernetes Configuration Errors
|
871
|
+
|
872
|
+
**Error**: `ConfigException: Invalid kube-config file. No configuration found.`
|
873
|
+
|
874
|
+
**Solution**:
|
875
|
+
```bash
|
876
|
+
# Check if kubectl is installed
|
877
|
+
kubectl version --client
|
878
|
+
|
879
|
+
# Check if kubectl is configured
|
880
|
+
kubectl cluster-info
|
881
|
+
|
882
|
+
# If not configured, set up a cluster (example with minikube)
|
883
|
+
minikube start
|
884
|
+
```
|
885
|
+
|
886
|
+
#### 2. Cluster Connection Issues
|
887
|
+
|
888
|
+
**Error**: `ConfigException: Service host/port is not set.`
|
889
|
+
|
890
|
+
**Solution**:
|
891
|
+
```bash
|
892
|
+
# Verify cluster is running
|
893
|
+
kubectl get nodes
|
894
|
+
|
895
|
+
# Check current context
|
896
|
+
kubectl config current-context
|
897
|
+
|
898
|
+
# Switch context if needed
|
899
|
+
kubectl config use-context <context-name>
|
900
|
+
```
|
901
|
+
|
902
|
+
#### 3. Namespace Issues
|
903
|
+
|
904
|
+
**Error**: `Namespace 'xyz' not found`
|
905
|
+
|
906
|
+
**Solution**:
|
907
|
+
```bash
|
908
|
+
# List all namespaces
|
909
|
+
kubectl get namespaces
|
910
|
+
|
911
|
+
# Create namespace if needed
|
912
|
+
kubectl create namespace <namespace-name>
|
913
|
+
|
914
|
+
# Or use default namespace
|
915
|
+
k8s-helper config --namespace default
|
916
|
+
```
|
917
|
+
|
918
|
+
#### 4. Permission Issues
|
919
|
+
|
920
|
+
**Error**: `Forbidden: User cannot list pods`
|
921
|
+
|
922
|
+
**Solution**:
|
923
|
+
```bash
|
924
|
+
# Check current user permissions
|
925
|
+
kubectl auth can-i list pods
|
926
|
+
|
927
|
+
# Check RBAC settings
|
928
|
+
kubectl get clusterrolebinding
|
929
|
+
```
|
930
|
+
|
931
|
+
### Testing Without a Cluster
|
932
|
+
|
933
|
+
If you want to test the package without a real Kubernetes cluster, you can:
|
934
|
+
|
935
|
+
1. **Use minikube** (recommended for development):
|
936
|
+
```bash
|
937
|
+
# Install minikube
|
938
|
+
# Windows: choco install minikube
|
939
|
+
# macOS: brew install minikube
|
940
|
+
# Linux: curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
|
941
|
+
|
942
|
+
# Start minikube
|
943
|
+
minikube start
|
944
|
+
|
945
|
+
# Test k8s-helper
|
946
|
+
k8s-helper list-pods
|
947
|
+
```
|
948
|
+
|
949
|
+
2. **Use kind** (Kubernetes in Docker):
|
950
|
+
```bash
|
951
|
+
# Install kind
|
952
|
+
# Windows: choco install kind
|
953
|
+
# macOS: brew install kind
|
954
|
+
# Linux: curl -Lo kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
|
955
|
+
|
956
|
+
# Create cluster
|
957
|
+
kind create cluster
|
958
|
+
|
959
|
+
# Test k8s-helper
|
960
|
+
k8s-helper list-pods
|
961
|
+
```
|
962
|
+
|
963
|
+
3. **Use Docker Desktop** (if you have Docker Desktop):
|
964
|
+
```bash
|
965
|
+
# Enable Kubernetes in Docker Desktop settings
|
966
|
+
# Then test
|
967
|
+
k8s-helper list-pods
|
968
|
+
```
|
969
|
+
|
970
|
+
### Getting Help
|
971
|
+
|
972
|
+
- **Documentation**: Check this README for usage examples
|
973
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/Harshit1o/k8s-helper/issues)
|
974
|
+
- **Kubernetes Docs**: [Official Kubernetes documentation](https://kubernetes.io/docs/)
|
975
|
+
- **kubectl Reference**: [kubectl command reference](https://kubernetes.io/docs/reference/kubectl/)
|