A CLI tool that automatically discovers all AKS clusters across your Azure subscriptions and fetches their credentials for kubectl access.
- Automatically discovers all Azure subscriptions you have access to
- Finds all AKS clusters in each subscription
- Fetches credentials for each cluster using
az aks get-credentials - Converts kubeconfig to use Azure CLI authentication with
kubelogin - Supports dry-run mode to preview actions
- Comprehensive logging and error handling
- Azure CLI (
az) installed and authenticated kubelogininstalled for Azure authentication- Python 3.6+ (if using the Python version)
# macOS
brew install Azure/kubelogin/kubelogin
# Or download from https://github.com/Azure/kubelogin/releases# macOS
brew install azure-cli./aks-credential-loader./aks-credential-loader --dry-run./aks-credential-loader --subscription 12345678-1234-1234-1234-123456789abc./aks-credential-loader --verboseFor each AKS cluster found, the tool executes:
az account set --subscription <subscription-id>az aks get-credentials --resource-group <rg-name> --name <cluster-name> --overwrite-existingkubelogin convert-kubeconfig -l azurecli
The tool will update your ~/.kube/config file with contexts for all discovered AKS clusters, ready for use with kubectl.
# macOS with Homebrew
brew install azure-cli
brew install Azure/kubelogin/kubelogin
brew install jq
# Login to Azure
az logingit clone <repo-url>
cd azure-kubernetes-crdential-loader
# Test with dry-run first (recommended)
./aks-credential-loader --dry-run --verbose
# Run for real
./aks-credential-loader --verbose# Preview what would be executed (always run this first!)
./aks-credential-loader --dry-run --verbose
# Fetch credentials for all clusters
./aks-credential-loader
# Target specific subscription(s)
./aks-credential-loader --subscription 12345678-1234-1234-1234-123456789abc
# Multiple subscriptions
./aks-credential-loader -s sub1 -s sub2
# Verbose output
./aks-credential-loader --verbose# Preview what would be executed
./aks-credential-loader --dry-run --verbose
# Fetch credentials for all clusters
./aks-credential-loader
# Target specific subscription
./aks-credential-loader --subscription 12345678-1234-1234-1234-123456789abcFor each AKS cluster discovered, the tool executes these three commands:
-
Set subscription context:
az account set --subscription <subscription-id>
-
Fetch AKS credentials:
az aks get-credentials --resource-group <rg-name> --name <cluster-name> --overwrite-existing
-
Convert to Azure CLI authentication:
kubelogin convert-kubeconfig -l azurecli
π§ Checking prerequisites...
β
Azure CLI found
β
kubelogin found
β¨ Ready to go!
======================================================================
π Azure Kubernetes Credential Loader
======================================================================
π Starting Azure Kubernetes Credential Loader
π Finding your Azure subscriptions...
π Found 26 subscription(s)
β’ mock-subscription-01
β’ mock-subsription-02
..
============================================================
π’ mock-subscription-01
============================================================
π Looking for AKS clusters...
π― Found 2 cluster(s):
mock-aks-cluster-01
mock-aks-cluster-02
..
π Getting credentials for: mock-aks-cluster-01
β
Ready: mock-aks-cluster-01
============================================================
π Summary
============================================================
Subscriptions: 26
Clusters found: 22
Configured: 22/22
π All clusters ready to use!
- β
Updates your
~/.kube/configfile with contexts for all discovered AKS clusters - β
All clusters ready for use with
kubectl - β
Switch between clusters:
kubectl config use-context <cluster-name> - β
List all contexts:
kubectl config get-contexts
| Option | Description |
|---|---|
--dry-run |
Preview actions without executing them |
--verbose, -v |
Enable detailed logging |
--subscription, -s |
Process specific subscription(s) only |
--help, -h |
Show help message |
make help # Show available commands
make install # Install prerequisites via Homebrew
make check-prereqs # Verify all tools are installed
make test # Test both versions with dry-run
make dry-run # Run Python version in dry-run mode
make run # Run Python version
make clean # Clean up temporary files"Not logged in to Azure CLI"
az login"kubelogin not found"
brew install Azure/kubelogin/kubelogin"jq not found" (Bash version)
brew install jq"Failed to set subscription context"
- You may not have access to all listed subscriptions
- Use
--subscriptionto target specific subscriptions you have access to
Always test with dry-run first:
./aks-credential-loader --dry-run --verboseβββ README.md # This documentation
βββ aks-credential-loader # Main CLI entry point
βββ src/
β βββ aks_credential_loader.py # Core Python implementation
βββ scripts/
β βββ aks_credential_loader.sh # Bash implementation
β βββ run_tests.sh # Test runner
βββ tests/ # Comprehensive test suite
βββ docs/
β βββ EXAMPLES.md # Usage examples
β βββ PROJECT_STRUCTURE.md # Detailed project structure
βββ CONTRIBUTING.md # Contribution guidelines
βββ SECURITY.md # Security policy
βββ CHANGELOG.md # Version history
βββ pyproject.toml # Modern Python packaging
βββ Makefile # Development commands
βββ .vscode/ # VS Code configuration
βββ .devcontainer/ # Development container setup
βββ .github/ # GitHub Actions and templates
- Click the badge above or "Code" β "Codespaces" β "Create codespace"
- Wait for automatic setup (Azure CLI, kubectl, kubelogin pre-installed)
- Start coding with GitHub Copilot enabled!
git clone <repo-url>
cd azure-kubernetes-crdential-loader
code . # Opens with full VS Code configuration
make install # Install prerequisitesOpen in VS Code and use "Dev Containers: Reopen in Container" for a consistent development environment.
This project is optimized for GitHub Copilot development! See .github/copilot-instructions.md for:
- AI-powered development workflows
- Copilot best practices for this project
- Prompt examples for common tasks
- Advanced techniques and tips
Contributions are welcome! Please see CONTRIBUTING.md for:
- Development setup instructions
- Code style guidelines
- Pull request process
- GitHub Copilot usage tips
This project is open source and available under the MIT License.