k8s-helper-cli 0.1.1__tar.gz → 0.2.0__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.
Files changed (21) hide show
  1. k8s_helper_cli-0.2.0/PKG-INFO +978 -0
  2. k8s_helper_cli-0.2.0/README.md +953 -0
  3. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/pyproject.toml +1 -1
  4. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/src/k8s_helper/__init__.py +1 -1
  5. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/src/k8s_helper/cli.py +14 -0
  6. k8s_helper_cli-0.2.0/src/k8s_helper_cli.egg-info/PKG-INFO +978 -0
  7. k8s_helper_cli-0.1.1/PKG-INFO +0 -491
  8. k8s_helper_cli-0.1.1/README.md +0 -466
  9. k8s_helper_cli-0.1.1/src/k8s_helper_cli.egg-info/PKG-INFO +0 -491
  10. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/LICENSE +0 -0
  11. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/setup.cfg +0 -0
  12. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/src/k8s_helper/config.py +0 -0
  13. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/src/k8s_helper/core.py +0 -0
  14. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/src/k8s_helper/utils.py +0 -0
  15. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/src/k8s_helper_cli.egg-info/SOURCES.txt +0 -0
  16. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/src/k8s_helper_cli.egg-info/dependency_links.txt +0 -0
  17. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/src/k8s_helper_cli.egg-info/entry_points.txt +0 -0
  18. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/src/k8s_helper_cli.egg-info/requires.txt +0 -0
  19. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/src/k8s_helper_cli.egg-info/top_level.txt +0 -0
  20. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/tests/test_core.py +0 -0
  21. {k8s_helper_cli-0.1.1 → k8s_helper_cli-0.2.0}/tests/test_integration.py +0 -0
@@ -0,0 +1,978 @@
1
+ Metadata-Version: 2.4
2
+ Name: k8s-helper-cli
3
+ Version: 0.2.0
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
+ # Show version
527
+ k8s-helper --version
528
+
529
+ # Configure settings
530
+ k8s-helper config --namespace my-namespace
531
+ k8s-helper config --output-format yaml
532
+ k8s-helper config --timeout 300
533
+ k8s-helper config --show # Show current configuration
534
+ ```
535
+
536
+ ### Pod Management
537
+
538
+ ```bash
539
+ # Create a pod
540
+ k8s-helper create-pod my-pod nginx:latest --namespace my-namespace
541
+
542
+ # Delete a pod
543
+ k8s-helper delete-pod my-pod --namespace my-namespace
544
+
545
+ # List pods
546
+ k8s-helper list-pods --namespace my-namespace
547
+ k8s-helper list-pods --output yaml
548
+
549
+ # Get pod logs
550
+ k8s-helper logs my-pod --namespace my-namespace
551
+ ```
552
+
553
+ ### Deployment Management
554
+
555
+ ```bash
556
+ # Create a deployment
557
+ k8s-helper create-deployment my-app nginx:latest --replicas 3 --namespace my-namespace
558
+
559
+ # Scale a deployment
560
+ k8s-helper scale-deployment my-app --replicas 5 --namespace my-namespace
561
+
562
+ # Delete a deployment
563
+ k8s-helper delete-deployment my-app --namespace my-namespace
564
+
565
+ # List deployments
566
+ k8s-helper list-deployments --namespace my-namespace
567
+ k8s-helper list-deployments --output yaml
568
+ ```
569
+
570
+ ### Service Management
571
+
572
+ ```bash
573
+ # Create a service
574
+ k8s-helper create-service my-service --port 80 --target-port 8080 --type ClusterIP --namespace my-namespace
575
+
576
+ # Delete a service
577
+ k8s-helper delete-service my-service --namespace my-namespace
578
+
579
+ # List services
580
+ k8s-helper list-services --namespace my-namespace
581
+ k8s-helper list-services --output yaml
582
+ ```
583
+
584
+ ### Monitoring and Events
585
+
586
+ ```bash
587
+ # Get events
588
+ k8s-helper events --namespace my-namespace
589
+
590
+ # Get namespace status
591
+ k8s-helper status --namespace my-namespace
592
+
593
+ # Describe resources
594
+ k8s-helper describe pod my-pod --namespace my-namespace
595
+ k8s-helper describe deployment my-app --namespace my-namespace
596
+ k8s-helper describe service my-service --namespace my-namespace
597
+ ```
598
+
599
+ ### Application Deployment
600
+
601
+ ```bash
602
+ # Deploy a complete application (deployment + service)
603
+ k8s-helper apply my-app nginx:latest --replicas 3 --port 80 --service-type LoadBalancer --namespace my-namespace
604
+
605
+ # Clean up an application (delete deployment + service)
606
+ k8s-helper cleanup my-app --namespace my-namespace
607
+ ```
608
+
609
+ ### Basic Examples
610
+
611
+ #### Deploy a Web Application
612
+ ```bash
613
+ # Deploy nginx with 3 replicas and LoadBalancer service
614
+ k8s-helper apply webapp nginx:latest --replicas 3 --port 80 --service-type LoadBalancer
615
+
616
+ # Check deployment status
617
+ k8s-helper list-deployments
618
+ k8s-helper list-services
619
+ k8s-helper status
620
+ ```
621
+
622
+ #### Deploy a Database
623
+ ```bash
624
+ # Deploy postgres
625
+ k8s-helper create-deployment postgres-db postgres:13 --replicas 1
626
+ k8s-helper create-service postgres-service --port 5432 --target-port 5432 --type ClusterIP
627
+
628
+ # Check logs
629
+ k8s-helper logs postgres-db
630
+ ```
631
+
632
+ #### Scale Applications
633
+ ```bash
634
+ # Scale web application
635
+ k8s-helper scale-deployment webapp --replicas 5
636
+
637
+ # Check scaling
638
+ k8s-helper list-deployments
639
+ ```
640
+
641
+ #### Clean Up
642
+ ```bash
643
+ # Clean up the web application
644
+ k8s-helper cleanup webapp
645
+
646
+ # Or delete components individually
647
+ k8s-helper delete-deployment postgres-db
648
+ k8s-helper delete-service postgres-service
649
+ ```
650
+
651
+ ### Configuration
652
+
653
+ ```bash
654
+ # Set default namespace
655
+ k8s-helper config --namespace production
656
+
657
+ # Set output format
658
+ k8s-helper config --output-format yaml
659
+
660
+ # Show current configuration
661
+ k8s-helper config --show
662
+ ```
663
+
664
+ ### Output Formats
665
+
666
+ The CLI supports different output formats:
667
+
668
+ ```bash
669
+ # Table format (default)
670
+ k8s-helper list-pods
671
+
672
+ # YAML format
673
+ k8s-helper list-pods --output yaml
674
+
675
+ # JSON format
676
+ k8s-helper list-pods --output json
677
+ ```
678
+
679
+ ### Environment Variables
680
+
681
+ ```bash
682
+ # Set default namespace
683
+ export K8S_HELPER_NAMESPACE=my-namespace
684
+
685
+ # Set output format
686
+ export K8S_HELPER_OUTPUT_FORMAT=yaml
687
+
688
+ # Now all commands will use these defaults
689
+ k8s-helper list-pods
690
+ ```
691
+
692
+ ### Shell Completion
693
+
694
+ ```bash
695
+ # Install completion for bash
696
+ k8s-helper --install-completion bash
697
+
698
+ # Install completion for zsh
699
+ k8s-helper --install-completion zsh
700
+
701
+ # Show completion script
702
+ k8s-helper --show-completion bash
703
+ ```
704
+
705
+ ## Real-World Examples
706
+
707
+ ### 1. Simple Web Application
708
+
709
+ ```bash
710
+ # Deploy a web application
711
+ k8s-helper apply webapp nginx:latest --replicas 3 --port 80 --service-type LoadBalancer
712
+
713
+ # Check deployment
714
+ k8s-helper list-deployments
715
+ k8s-helper list-services
716
+ k8s-helper status
717
+ ```
718
+
719
+ ### 2. Database Setup
720
+
721
+ ```bash
722
+ # Deploy PostgreSQL database
723
+ k8s-helper create-deployment postgres-db postgres:13 --replicas 1
724
+ k8s-helper create-service postgres-service --port 5432 --target-port 5432 --type ClusterIP
725
+
726
+ # Check database
727
+ k8s-helper logs postgres-db
728
+ k8s-helper describe deployment postgres-db
729
+ ```
730
+
731
+ ### 3. Multi-Environment Deployment
732
+
733
+ ```bash
734
+ # Production
735
+ k8s-helper config --namespace production
736
+ k8s-helper apply webapp myapp:v1.0.0 --replicas 5 --port 8080 --service-type LoadBalancer
737
+
738
+ # Staging
739
+ k8s-helper config --namespace staging
740
+ k8s-helper apply webapp myapp:v1.1.0-rc1 --replicas 2 --port 8080 --service-type ClusterIP
741
+
742
+ # Development
743
+ k8s-helper config --namespace development
744
+ k8s-helper apply webapp myapp:latest --replicas 1 --port 8080 --service-type NodePort
745
+ ```
746
+
747
+ ### 4. Application Scaling
748
+
749
+ ```bash
750
+ # Scale up for high traffic
751
+ k8s-helper scale-deployment webapp --replicas 10
752
+
753
+ # Monitor scaling
754
+ k8s-helper list-deployments
755
+ k8s-helper events
756
+
757
+ # Scale down after traffic reduces
758
+ k8s-helper scale-deployment webapp --replicas 3
759
+ ```
760
+
761
+ ### 5. Debugging and Monitoring
762
+
763
+ ```bash
764
+ # Get comprehensive status
765
+ k8s-helper status
766
+ k8s-helper list-deployments
767
+ k8s-helper list-pods
768
+ k8s-helper list-services
769
+
770
+ # Check logs
771
+ k8s-helper logs webapp
772
+
773
+ # Get events
774
+ k8s-helper events
775
+
776
+ # Describe resources
777
+ k8s-helper describe deployment webapp
778
+ k8s-helper describe service webapp-service
779
+ ```
780
+
781
+ ### 6. Clean Up
782
+
783
+ ```bash
784
+ # Clean up complete application
785
+ k8s-helper cleanup webapp
786
+
787
+ # Or clean up individual components
788
+ k8s-helper delete-deployment postgres-db
789
+ k8s-helper delete-service postgres-service
790
+ ```
791
+
792
+ ## Best Practices
793
+
794
+ ### 1. Resource Management
795
+ ```bash
796
+ # Use appropriate replica counts for high availability
797
+ k8s-helper apply my-app nginx:latest --replicas 3
798
+
799
+ # Monitor resource usage
800
+ k8s-helper status
801
+ k8s-helper list-deployments
802
+ ```
803
+
804
+ ### 2. Environment Management
805
+ ```bash
806
+ # Use different namespaces for different environments
807
+ k8s-helper config --namespace production
808
+ k8s-helper config --namespace staging
809
+ k8s-helper config --namespace development
810
+ ```
811
+
812
+ ### 3. Service Types
813
+ ```bash
814
+ # Use ClusterIP for internal services
815
+ k8s-helper create-service internal-api --port 8080 --type ClusterIP
816
+
817
+ # Use LoadBalancer for external access
818
+ k8s-helper create-service public-web --port 80 --type LoadBalancer
819
+ ```
820
+
821
+ ### 4. Monitoring and Debugging
822
+ ```bash
823
+ # Regular health checks
824
+ k8s-helper status
825
+ k8s-helper events
826
+
827
+ # Log monitoring
828
+ k8s-helper logs my-app
829
+ ```
830
+
831
+ ### 5. Configuration Management
832
+ ```bash
833
+ # Set sensible defaults
834
+ k8s-helper config --namespace my-app
835
+ k8s-helper config --output-format yaml
836
+ ```
837
+
838
+ ## Limitations
839
+
840
+ **Important**: k8s-helper requires an active Kubernetes cluster connection to function. The CLI and Python API will fail if:
841
+
842
+ - No kubectl configuration is found (`~/.kube/config`)
843
+ - No active Kubernetes cluster is available
844
+ - kubectl is not properly configured
845
+
846
+ ### Current CLI Limitations:
847
+
848
+ - **Resource limits**: `--cpu-limit` and `--memory-limit` options are not implemented
849
+ - **Advanced logging**: `--tail`, `--follow`, `--container` options are not available
850
+ - **Advanced options**: Some documented options like `--env`, `--labels` may not be available in all commands
851
+ - **Batch operations**: Multiple resource operations in single commands are not supported
852
+ - **Advanced monitoring**: `--watch`, `--since`, `--all-namespaces` options are not implemented
853
+
854
+ ### Error Handling:
855
+
856
+ If you see errors like:
857
+ ```
858
+ ConfigException: Invalid kube-config file. No configuration found.
859
+ ConfigException: Service host/port is not set.
860
+ ```
861
+
862
+ This means you need to:
863
+ 1. Install and configure kubectl
864
+ 2. Set up access to a Kubernetes cluster
865
+ 3. Verify with `kubectl cluster-info`
866
+
867
+ The CLI provides core functionality for basic Kubernetes operations. For advanced features, use the Python API directly or kubectl.
868
+
869
+ ## Troubleshooting
870
+
871
+ ### Common Issues
872
+
873
+ #### 1. Kubernetes Configuration Errors
874
+
875
+ **Error**: `ConfigException: Invalid kube-config file. No configuration found.`
876
+
877
+ **Solution**:
878
+ ```bash
879
+ # Check if kubectl is installed
880
+ kubectl version --client
881
+
882
+ # Check if kubectl is configured
883
+ kubectl cluster-info
884
+
885
+ # If not configured, set up a cluster (example with minikube)
886
+ minikube start
887
+ ```
888
+
889
+ #### 2. Cluster Connection Issues
890
+
891
+ **Error**: `ConfigException: Service host/port is not set.`
892
+
893
+ **Solution**:
894
+ ```bash
895
+ # Verify cluster is running
896
+ kubectl get nodes
897
+
898
+ # Check current context
899
+ kubectl config current-context
900
+
901
+ # Switch context if needed
902
+ kubectl config use-context <context-name>
903
+ ```
904
+
905
+ #### 3. Namespace Issues
906
+
907
+ **Error**: `Namespace 'xyz' not found`
908
+
909
+ **Solution**:
910
+ ```bash
911
+ # List all namespaces
912
+ kubectl get namespaces
913
+
914
+ # Create namespace if needed
915
+ kubectl create namespace <namespace-name>
916
+
917
+ # Or use default namespace
918
+ k8s-helper config --namespace default
919
+ ```
920
+
921
+ #### 4. Permission Issues
922
+
923
+ **Error**: `Forbidden: User cannot list pods`
924
+
925
+ **Solution**:
926
+ ```bash
927
+ # Check current user permissions
928
+ kubectl auth can-i list pods
929
+
930
+ # Check RBAC settings
931
+ kubectl get clusterrolebinding
932
+ ```
933
+
934
+ ### Testing Without a Cluster
935
+
936
+ If you want to test the package without a real Kubernetes cluster, you can:
937
+
938
+ 1. **Use minikube** (recommended for development):
939
+ ```bash
940
+ # Install minikube
941
+ # Windows: choco install minikube
942
+ # macOS: brew install minikube
943
+ # Linux: curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
944
+
945
+ # Start minikube
946
+ minikube start
947
+
948
+ # Test k8s-helper
949
+ k8s-helper list-pods
950
+ ```
951
+
952
+ 2. **Use kind** (Kubernetes in Docker):
953
+ ```bash
954
+ # Install kind
955
+ # Windows: choco install kind
956
+ # macOS: brew install kind
957
+ # Linux: curl -Lo kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
958
+
959
+ # Create cluster
960
+ kind create cluster
961
+
962
+ # Test k8s-helper
963
+ k8s-helper list-pods
964
+ ```
965
+
966
+ 3. **Use Docker Desktop** (if you have Docker Desktop):
967
+ ```bash
968
+ # Enable Kubernetes in Docker Desktop settings
969
+ # Then test
970
+ k8s-helper list-pods
971
+ ```
972
+
973
+ ### Getting Help
974
+
975
+ - **Documentation**: Check this README for usage examples
976
+ - **GitHub Issues**: [Report bugs or request features](https://github.com/Harshit1o/k8s-helper/issues)
977
+ - **Kubernetes Docs**: [Official Kubernetes documentation](https://kubernetes.io/docs/)
978
+ - **kubectl Reference**: [kubectl command reference](https://kubernetes.io/docs/reference/kubectl/)