Skip to content

Commit 5da64e8

Browse files
committed
README/user-case: too many clustesr
1 parent e421342 commit 5da64e8

File tree

1 file changed

+43
-36
lines changed

1 file changed

+43
-36
lines changed

README.md

+43-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
![icy](https://github.com/icy/gk8s/workflows/icy/badge.svg)
22

3+
## TOC
4+
5+
* [Description](#description)
6+
* [Ideas](#ideas)
7+
* [Why](#why)
8+
* [Why don't just use kubectl config](#seriously-why-dont-just-use-kubectl-config)
9+
* [Getting started](#getting-started)
10+
* [Examples](#examples)
11+
* [Too many clusters](#too-many-clusters)
12+
* [How it works](#how-it-works)
13+
314
## Description
415

516
Scripting-friendly tool to work with multiple k8s clusters, with ability to provide a concise way
@@ -105,6 +116,38 @@ How to get list of nodes from multiple clusters?
105116
$ parallel 'gk8s {} get nodes' ::: :cluster1 :cluster2 :cluster3
106117
```
107118

119+
## Too many clusters
120+
121+
When you have multiple clusters, you can have multile configurations
122+
and it isn't convenient to have all configuration in the same file
123+
and/or same directory.
124+
125+
It's very easy to organize multiple cluster configurations with `gk8s`.
126+
Let's say you're using the default configuration path `$HOME/.config/gk8s`.
127+
You can have directory structre as below
128+
129+
```
130+
$HOME/.config/gk8s/
131+
org1/
132+
cluster1
133+
cluster2
134+
org2/
135+
cluster1
136+
cluster2
137+
all
138+
cluster11 --> ../org1/cluster1 (symlink)
139+
cluster12 --> ../org1/cluster2 (symlink)
140+
cluster21 --> ../org2/cluster1 (symlink)
141+
cluster22 --> ../org2/cluster2 (symlink)
142+
```
143+
144+
Now everything is quite trivial with `gk8s`
145+
146+
```
147+
$ gk8s :cluster1/cluster1 get nodes
148+
$ gk8s :all/cluster11 get nodes
149+
```
150+
108151
## How it works
109152

110153
Each cluster/context has their own configuration file under
@@ -128,42 +171,6 @@ If `cluster` is `local`, the command will set `KUBECONFIG=$HOME/.kube/config`.
128171

129172
If `KUBECONFIG` file not found, the tool exits immediately.
130173

131-
## Using this program as a script
132-
133-
Read more at https://blog.rapid7.com/2016/08/04/build-a-simple-cli-tool-with-golang/
134-
135-
```
136-
$ go get github.com/erning/gorun
137-
$ sudo mv ~/go/bin/gorun /usr/local/bin/
138-
$ echo ':golang:E::go::/usr/local/bin/gorun:OC' | sudo tee /proc/sys/fs/binfmt_misc/register
139-
:golang:E::go::/usr/local/bin/gorun:OC
140-
```
141-
142-
## Alternatives
143-
144-
You can use some shell script, some aliases, bla bla.
145-
You can also write a simple function to update `KUBECONFIG` variable
146-
for your cluster before getting started, for example, in `.bash`.
147-
148-
(Note, the following script doesn't have advanced feature as the golang tool.)
149-
150-
```
151-
$ my_gk8s() {
152-
cluster="${1:-}"
153-
if [[ "${cluster:0:1}" == ":" ]]; then
154-
cluster="${cluster:1}"
155-
shift
156-
else
157-
echo >&2 ":: Missing cluster name."
158-
return
159-
fi
160-
export KUBECONFIG="$HOME/.config/gk8s/$cluster"
161-
kubectl "$@"
162-
}
163-
164-
$ my_gk8s :my-cluster get pods
165-
```
166-
167174
## Authors. License. Misc
168175

169176
The author is Ky-Anh Huynh.

0 commit comments

Comments
 (0)