-
-
Save rajatsing/af7dddfabd3087e72998a3b3be935f7b to your computer and use it in GitHub Desktop.
go k8 client for minikube
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
package minikube | |
import ( | |
"fmt" | |
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |
"k8s.io/client-go/kubernetes" | |
"k8s.io/client-go/tools/clientcmd" | |
) | |
func main() { | |
// uses the current context in kubeconfig | |
// path-to-kubeconfig -- for example, /root/.kube/config | |
config, _ := clientcmd.BuildConfigFromFlags("", "~/auth/kubeconfig") | |
// creates the clientset | |
clientset, _ := kubernetes.NewForConfig(config) | |
// access the API to list pods | |
pods, _ := clientset.CoreV1().Pods("").List(v1.ListOptions{}) | |
fmt.Printf("There are %d pods in the cluster\n", len(pods.Items)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment