import ( "k8s.io/kubernetes/pkg/client/rest" unversioned "k8s.io/kubernetes/pkg/client/unversioned" ) func main() { config := &rest.Config{ Host: "http://127.0.0.1:8080", Insecure: true, } // creates the clientset clientset, err := unversioned.New(config) if err != nil { panic(err.Error()) } // fetch a particular pod by name pod, err := clientset.Pods("default").Get("my-pod", metav1.GetOptions{}) if err != nil { panic(err.Error()) } fmt.Println(pod) }
import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" ) func main() { config, err := rest.InClusterConfig() if err != nil { panic(err.Error()) } // creates the clientset clientset, err := kubernetes.NewForConfig(config) if err != nil { panic(err.Error()) } // get the list of pods in a specific namespace pods, err := clientset.CoreV1().Pods("default").List(metav1.ListOptions{}) if err != nil { panic(err.Error()) } fmt.Println(pods) }Brief Description: This code example gets the list of pods in a specific namespace using the kubernetes clientset from the unversioned package.