import ( "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/fields" "k8s.io/kubernetes/pkg/labels" ) config := &unversioned.Config{ Host: "http://localhost:8001", Username: "", Password: "", } client, err := unversioned.New(config) if err != nil { panic(err) } podList, err := client.Pods("mynamespace").List(api.ListOptions{ LabelSelector: labels.Everything(), FieldSelector: fields.Everything(), }) if err != nil { panic(err) } for _, pod := range podList.Items { fmt.Println("Name:", pod.Name) }
import ( "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/api" ) config := &unversioned.Config{ Host: "http://localhost:8001", Username: "", Password: "", } client, err := unversioned.New(config) if err != nil { panic(err) } pod := &api.Pod{ ObjectMeta: api.ObjectMeta{ Name: "my-pod", Namespace: "mynamespace", }, Spec: api.PodSpec{ Containers: []api.Container{ { Name: "my-container", Image: "nginx", }, }, }, } newPod, err := client.Pods("mynamespace").Create(pod) if err != nil { panic(err) } fmt.Println("Created Pod Name:", newPod.Name)In the above examples, we use the unversioned Client Services provided by the k8s.io/kubernetes/pkg/client/unversioned package to list all the pods in a namespace and to create a new pod in a namespace. The Package Library is k8s.io/kubernetes/pkg/client/unversioned.