-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
title: "Using multiple kubeconfig files" | ||
date: 2024-08-20 | ||
--- | ||
|
||
On a daily basis I'm working with multiple Kuberetes cluster. I also use [Kubernetes tools VSCode extension](https://marketplace.visualstudio.com/items?itemName=ms-kubernetes-tools.vscode-kubernetes-tools). Extension allows to easily change current context from within VSCode. | ||
|
||
## Generating common kubeconfig | ||
|
||
In order to switch contexts you need to merge multiple kubeconfig files into single yaml file. To do that I have created a script at `/home/guntis/.kube/merge.sh` that looks something like: | ||
```sh | ||
KUBECONFIG=\ | ||
~/.kube/abc-test.yaml:\ | ||
~/.kube/abc-staging.yaml:\ | ||
~/.kube/abc-prod.yaml:\ | ||
kubectl config view --flatten > ~/.kube/config | ||
``` | ||
|
||
When you run this script it will merge all listed files into one. | ||
|
||
Important rule is that each kubeconfig must have unique keys. For example `abc-test.yaml` file would look like this: | ||
```yaml | ||
apiVersion: v1 | ||
clusters: | ||
- cluster: | ||
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JS...ZJQ0FURS0tLS0tCg== | ||
server: https://kubernetes.docker.internal:6443 | ||
name: abc-test | ||
contexts: | ||
- context: | ||
cluster: abc-test | ||
user: abc-test | ||
name: abc-test | ||
current-context: abc-test | ||
kind: Config | ||
preferences: {} | ||
users: | ||
- name: abc-test | ||
user: | ||
client-certificate-data: LS0tLS...S0tCg== | ||
client-key-data: LS0tL..0tCg== | ||
``` | ||
## Switch contexts using VSCode | ||
 | ||
## Switch contexts using k9s | ||
K9s is super convenvient utility that also allows switching contexts, by typing `:ctx` command. | ||
 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.