2 minutes
Generate Kubernetes config files
Kubernetes has a wonderful community where individuals and organisations are contributing to it. We are seeing new tools and features being released into the open source world on a daily basis. However I have found a gap in its capabilities. There is no easy way to generate kubeconfig files natively. Default behaviour of kubectl is to look for config file in .kube directory. Various flavours of kubernetes from cloud vendors have implemented their own utilities to generate such config files.
For EKS
aws eks --region <region-code> update-kubeconfig --name <cluster_name>
For GKE
gcloud container clusters get-credentials <cluster-name>
For AKS
az aks get-credentials --resource-group <myResourceGroup> --name <myAKSCluster> --admin
I did not come across a native way to get cluster credentials for a vanilla kubernetes cluster. Hence I built a tool to do just that. I called it KCG short for Kubernetes Config Generator.
What is KCG?
Kubernetes config generator is an interactive command line tool that lets you create kubeconfig file for a service account in a given namespace. The user can interactively chose a namespace and service account from a Kubernetes cluster. The output is a config file with token authentication that has same RBAC permissions assigned to chosen service account.
Prerequisites
Default behaviour of this tool is to look in .kube directory for config file and it should have permissions to read namespaces, secrets, and serviceaccounts at cluster level. It can also look for credentials of Kubernetes cluster you want to work with from Environment variable KUBECONFIG just like kubectl would.
This tool is aimed at kubernetes cluster operators and admins especially if they are hosting isolated tenanats by namespaces.
How to use this tool
For Linux
wget https://github.com/bit-cloner/kcg/releases/download/0.9/linux-amd64-kcg
chmod +x linux-amd64-kcg
./linux-amd64-kcg
One liner
wget https://github.com/bit-cloner/kcg/releases/download/0.9/linux-amd64-kcg && sudo chmod +x ./linux-amd64-kcg && ./linux-amd64-kcg
For Windows
$url = "https://github.com/bit-cloner/kcg/releases/download/0.9/windows-386-kcg.exe"
$output = "kcg.exe"
Invoke-WebRequest -Uri $url -OutFile $output -UseBasicParsing
./kcg
Tested on windows powershell (not PowerShell ISE) and Terminal app
For Mac
wget https://github.com/bit-cloner/kcg/releases/download/0.9/darwin-amd64-kcg
chmod +x darwin-amd64-kcg
./darwin-amd64-kcg
Install it as a kubectl plugin
wget https://github.com/bit-cloner/kcg/releases/download/0.9/kubectl-kcg
sudo cp kubectl-kcg /usr/local/bin
kubectl plugin list
kubectl kcg
344 Words
2020-08-19 00:00 +0000