Skip to content

Commit

Permalink
Update usage documentation: Add PowerShell and Krew plugin usage exam…
Browse files Browse the repository at this point in the history
…ples

Signed-off-by: PixelRobots <22979170+PixelRobots@users.noreply.github.com>
  • Loading branch information
PixelRobots committed Oct 3, 2024
1 parent 41aa77d commit 8b1cafa
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 74 deletions.
Binary file added docs/assets/images/summary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 0 additions & 70 deletions docs/docs/usage.md

This file was deleted.

14 changes: 14 additions & 0 deletions docs/docs/usage/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
title: Usage
parent: Documentation
nav_order: 3
layout: default
---

# Usage

KubeTidy can be used across different platforms using either PowerShell (Windows/Linux/macOS) or as a `kubectl` plugin via Krew (Linux/macOS). Choose the instructions that match your environment:

- [PowerShell Usage](docs/powershell-usage)
- [Krew Plugin Usage](docs/krew-usage)

If you want to see detailed logging examples and summaries, head over to the [Logging and Output](docs/logging-output) page.
59 changes: 59 additions & 0 deletions docs/docs/usage/krew-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: Krew Plugin Usage
parent: Usage
nav_order: 2
layout: default
---

# Krew Plugin Usage

If you're using **KubeTidy** via Krew as a `kubectl` plugin (Linux/macOS), here are the usage examples to help you manage your `kubeconfig` files.

## Clean Up Unreachable Clusters

To clean up unreachable clusters from your `kubeconfig`, use the following command:

```bash
kubectl kubetidy -kubeconfig "$HOME/.kube/config" -exclusionlist "cluster1,cluster2"
```

## Merging Kubeconfig Files

To merge multiple `kubeconfig` files into a single one:

```bash
kubectl kubetidy -mergeconfigs "config1.yaml" "config2.yaml" -destinationconfig "$HOME/.kube/config"
```

## Listing Clusters

To list all clusters in your `kubeconfig` without making changes:

```bash
kubectl kubetidy -kubeconfig "$HOME/.kube/config" -listclusters
```

## Listing Contexts

To list all contexts in your `kubeconfig`:

```bash
kubectl kubetidy -kubeconfig "$HOME/.kube/config" -listcontexts
```

## Dry Run Mode

Use the `-dryrun` option to simulate the cleanup process without modifying your `kubeconfig`:

```bash
kubectl kubetidy -kubeconfig "$HOME/.kube/config" -exclusionlist "cluster1" -dryrun
```

The Dry Run Mode also works for merging multiple kubeconfig files. This allows you to preview a summary of the merge without making any actual changes to the destination file.

```bash
kubectl kubetidy -mergeconfigs "config1.yaml" "config2.yaml" -destinationconfig "$HOME/.kube/config" -dryrun
```


For detailed logging examples, check out our [Logging and Output](docs/logging-output) page.
44 changes: 44 additions & 0 deletions docs/docs/usage/logging-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Logging and Output
parent: Usage
nav_order: 3
layout: default
---

# Logging and Output

KubeTidy provides detailed output and logging for each operation. You can use the `-Verbose` flag to see detailed information about cluster reachability, user and context removal, and more.

## Verbose Logging Example

Use the `-Verbose` flag for detailed logging during the cleanup process:

```powershell
Invoke-KubeTidy -KubeConfigPath "$HOME\.kube\config" -Verbose
```

### Verbose Output Example

```
VERBOSE: Checking reachability for cluster: aks-prod-cluster at https://example-cluster-url
VERBOSE: Cluster aks-prod-cluster is reachable via HTTPS.
VERBOSE: Removing unreachable cluster: aks-old-cluster
VERBOSE: Removed associated user: aks-old-user
VERBOSE: Backup of kubeconfig created: C:\Users\username\.kube\config.backup
```

## Summary Output

After running KubeTidy, a summary is displayed showing how many clusters were checked, removed, or retained:

```
╔════════════════════════════════════════════════╗
║ KubeTidy Summary ║
╠════════════════════════════════════════════════╣
║ Clusters Checked: 26 ║
║ Clusters Removed: 2 ║
║ Clusters Kept: 24 ║
╚════════════════════════════════════════════════╝
```

![KubeTidy Cleanup Summary](../../assets/images/summary.png)
58 changes: 58 additions & 0 deletions docs/docs/usage/powershell-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: PowerShell Usage
parent: Usage
nav_order: 1
layout: default
---

# PowerShell Usage

If you're using **KubeTidy** via PowerShell, here are the usage examples to help you clean up or manage your `kubeconfig` files.

## Clean Up Unreachable Clusters

To remove unreachable clusters from your `kubeconfig`, use the following command:

```powershell
Invoke-KubeTidy -KubeConfigPath "$HOME\.kube\config" -ExclusionList "cluster1,cluster2"
```

## Merging Kubeconfig Files

To merge multiple `kubeconfig` files into a single file:

```powershell
Invoke-KubeTidy -MergeConfigs "config1.yaml","config2.yaml" -DestinationConfig "$HOME\.kube\config"
```

## Listing Clusters

To list all clusters in your `kubeconfig` without making any changes:

```powershell
Invoke-KubeTidy -KubeConfigPath "$HOME\.kube\config" -ListClusters
```

## Listing Contexts

To list all contexts in your `kubeconfig`:

```powershell
Invoke-KubeTidy -KubeConfigPath "$HOME\.kube\config" -ListContexts
```

## Dry Run Mode

Use the `-DryRun` option to simulate the cleanup process without modifying your `kubeconfig`:

```powershell
Invoke-KubeTidy -KubeConfigPath "$HOME\.kube\config" -ExclusionList "cluster1" -DryRun
```

The Dry Run Mode also works for merging multiple kubeconfig files. This allows you to preview a summary of the merge without making any actual changes to the destination file.

```PowerShell
Invoke-KubeTidy -MergeConfigs "config1.yaml","config2.yaml" -DestinationConfig "$HOME\\.kube\\config" -DryRun
```

For detailed logging examples, check out our [Logging and Output](docs/logging-output) page.
12 changes: 8 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ KubeTidy is a PowerShell tool that simplifies managing your Kubernetes `kubeconf

## Key Features

- **Cluster Reachability Check**: Remove clusters that are unreachable.
- **User and Context Cleanup**: Clean up users and contexts that are no longer needed.
- **Backup Creation**: Create backups of your original `kubeconfig` before making changes.
- **Cluster Reachability Check**: Automatically removes unreachable clusters and their associated users and contexts.
- **Exclusion List**: Keep specific clusters even if they are temporarily unreachable.
- **Merge Kubeconfig Files**: Combine multiple `kubeconfig` files into one.
- **Dry Run Mode**: Simulate cleanup or merging before making actual changes.
- **Backup & Summary**: Automatically back up your original `kubeconfig` and get a summary of the changes made.
- **Force Cleanup**: Remove all clusters, even if unreachable, with the `-Force` parameter.
- **List & Export Options**: List or export clusters and contexts without making changes.
- **Dry Run Mode**: Simulate cleanup or merging operations to preview the results.
- **Verbose Logging**: Get detailed logs for all operations using the `-Verbose` flag.


Check out our [Installation Guide](docs/installation) to get started or [Usage Documentation](docs/usage) to explore how you can use KubeTidy.

Expand Down

0 comments on commit 8b1cafa

Please sign in to comment.