Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/carlpett/gke-config-helper
A small utility to generate a kubectl configuration file for all clusters you have access to in GKE.
https://github.com/carlpett/gke-config-helper
gke kubectl kubernetes
Last synced: 2 months ago
JSON representation
A small utility to generate a kubectl configuration file for all clusters you have access to in GKE.
- Host: GitHub
- URL: https://github.com/carlpett/gke-config-helper
- Owner: carlpett
- License: mit
- Created: 2022-02-01T20:21:25.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-17T21:20:14.000Z (about 1 year ago)
- Last Synced: 2024-10-31T06:41:51.382Z (3 months ago)
- Topics: gke, kubectl, kubernetes
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gke-config-helper
A small utility to generate a `kubectl` configuration file for all clusters you have access to in GKE.
# Usage
```shell
$ gke-config-helper
```The basic invocation will check each project you have access to, list clusters and output a kubeconfig with a `cluster` and a `context` entry for each of them to stdout.
## Multiple config files
Since you might call this utility on a semi-regular basis, when there are new clusters to interact with, it is suggested to store the output in a separate configuration file if you also connect to non-GKE clusters (eg minikube). `kubectl` supports merging multiple configuration files by using the `KUBECONFIG` environment variable:
```shell
$ gke-config-helper > ~/.kube/gke-config
$ export KUBECONFIG=~/.kube/config:~/.kube/gke-config
```In this way, other cluster, context and user configurations are not affected by updating the GKE configuration. `kubectl` also stores written values in the first of the files, meaning that `current-context` will remain in the default file and be preserved when regenerating the `gke-config` file.
## Restricting projects
If you have access to a lot of projects, iterating over all of them might be slow. The flag `--search-root` allows you to restrict the search to projects that are children of a folder.
```shell
$ gke-config-helper --search-root my-folder
```This works to any depth, not only direct decendants of `my-folder`.
## Controlling the context name
By default, the name of each context will be `-`. You can control this with the `--context-name-template` flag, which takes a Go template as an argument. Both the [built-in Go functions](https://pkg.go.dev/text/template#hdr-Functions) as well as the [sprig library functions](https://masterminds.github.io/sprig/) are available.
The properties available for templating are:
- `ProjectId`: The project id
- `Name`: Name of the cluster
- `Location`: Region nameFor example:
```shell
$ gke-config-helper --context-name-template '{{ slice (.Name | splitList "-") 0 2 | join "-" }}_{{ .Location | substr 0 2 }}'
```With a cluster `foo-bar-baz` in `europe-west3`, this would generate a context name of `foo-bar_eu`.