Skip to content

Instantly share code, notes, and snippets.

@rajatsing
Created August 30, 2020 08:15
Show Gist options
  • Save rajatsing/af7dddfabd3087e72998a3b3be935f7b to your computer and use it in GitHub Desktop.
Save rajatsing/af7dddfabd3087e72998a3b3be935f7b to your computer and use it in GitHub Desktop.
go k8 client for minikube
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