Suraj Narwade
Suraj Narwade
~1 min read



With reference to the previous blog post, we are importing clientcmd package to work on kubeconfig which contains essential information like cluster URL, namespace, auth details to talk to cluster.


BuildConfigFromFlags function from clientcmd creates config from either master URL or kubeconfig filepath.

config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)

if nothing (master URL or kubeconfig file path) is provided, then it will fallback to inClusterConfig which we will see in the next blog post.

if err is occurred that means, kubeconfig is not parsed properly or kubeconfigPath is not correct.

config is of type rest.Config (coming from which then used to create actual clientsets. we will see that in upcoming blog posts.

if you just want to play around kubeconfig, you can also use,

config, err := clientcmd.LoadFromFile(kubeConfigPath)

where config is of type clientcmdapi.Config which is go struct for kubeconfig.

sample kubeconfig:

apiVersion: v1
- cluster:
    certificate-authority-data: REDACTED
  name: 192-168-42-120:8443
- context:
    cluster: 192-168-42-120:8443
    namespace: myproject
    user: developer/192-168-42-120:8443
  name: minishift
current-context: minishift
kind: Config
preferences: {}
- name: developer/192-168-42-120:8443
    token: <token>