Created
June 25, 2025 18:43
-
-
Save lovemycodesnippets/a5fe48764425ce110092645c1579eece to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"flag" | |
"fmt" | |
"path/filepath" | |
"k8s.io/client-go/kubernetes" | |
"k8s.io/client-go/tools/clientcmd" | |
"k8s.io/client-go/util/homedir" | |
) | |
func main() { | |
var kubeconfig string | |
if home := homedir.HomeDir(); home != "" { | |
kubeconfig = filepath.Join(home, ".kube", "config") | |
} | |
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig) | |
if err != nil { | |
panic(err.Error()) | |
} | |
clientset, err := kubernetes.NewForConfig(config) | |
if err != nil { | |
panic(err.Error()) | |
} | |
fmt.Println("Kubernetes client configured successfully!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment