import ( "fmt" k8s "k8s.io/kubernetes/pkg/client/unversioned" ) func main() { config := &k8s.Config{ Host: "https://my-kubernetes-cluster.com", Username: "admin", Password: "secret", } client, err := k8s.New(config) if err != nil { panic(err) } rcList, err := client.ReplicationControllers("").List(k8s.ListOptions{}) if err != nil { panic(err) } for _, rc := range rcList.Items { fmt.Printf("%s\n", rc.ObjectMeta.Name) } }
import ( "github.com/golang/glog" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/client/unversioned" ) func createReplicationController(client *unversioned.Client, rc *api.ReplicationController) { existing, err := client.ReplicationControllers(api.NamespaceDefault).Get(rc.Name) if err == nil { if existing.Spec.Replicas != rc.Spec.Replicas { glog.Infof("Updating rc: %s\n", rc.Name) _, err := client.ReplicationControllers(api.NamespaceDefault).Update(rc) if err != nil { glog.Fatal("Unable to update rc:", err) } } return } glog.Infof("Creating rc: %s\n", rc.Name) _, err = client.ReplicationControllers(api.NamespaceDefault).Create(rc) if err != nil { glog.Fatal("Unable to create rc:", err) } }This code creates a new Replication Controller in the `NamespaceDefault`. Overall, the go k8s.io.kubernetes.pkg.client.unversioned Interface ReplicationControllers is a very useful package library for developers who work with Kubernetes clusters and want to manage Replication Controllers.