Thursday, March 8, 2018

Creating a kubeconfig file for a service

When deploying a service outside Kubernetes that uses the Kubernetes API as a service account, it's generally required to use a kubeconfig file. Instructions that I've found elsewhere involve copying the user's ~/.kube/config file but that contains potentially many cluster configurations and also provides the credentials of the admin user.

I wrote a small shell script that will generate a new kubeconfig file for a service account on a Kubernetes cluster. It takes the certificate authority from the user's current config, and retrieves the service account's authentication token.

For example, to create a kubeconfig file for a service account user named "spinnaker", in a kubernetes cluster called "cluster-1":

Download the shell script here.