import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/apis/extensions" ) rc := &extensions.ReplicationController{ ObjectMeta: api.ObjectMeta{ Name: "my-controller", }, Spec: extensions.ReplicationControllerSpec{ Replicas: 3, Template: &api.PodTemplateSpec{ ObjectMeta: api.ObjectMeta{ Labels: map[string]string{ "app": "my-app", }, }, Spec: api.PodSpec{ Containers: []api.Container{ { Name: "my-container", Image: "my-image", }, }, }, }, }, } controller, err := client.ReplicationControllers("my-namespace").Create(rc)
import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/client/restclient" "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/client/impl/clientcmd" ) config, err := clientcmd.BuildConfigFromFlags("", "") if err != nil { panic(err) } restClient := restclient.New(config) client := unversioned.New(restClient) controllers, err := client.ReplicationControllers("my-namespace").List(api.ListOptions{}) if err != nil { panic(err) } for _, controller := range controllers.Items { fmt.Printf("ReplicationController %s has %d replicas\n", controller.ObjectMeta.Name, *controller.Spec.Replicas) }
import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/client/restclient" "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/client/impl/clientcmd" ) config, err := clientcmd.BuildConfigFromFlags("", "") if err != nil { panic(err) } restClient := restclient.New(config) client := unversioned.New(restClient) controller, err := client.ReplicationControllers("my-namespace").Get("my-controller") if err != nil { panic(err) } controller.Spec.Replicas = 5 _, err = client.ReplicationControllers("my-namespace").Update(controller) if err != nil { panic(err) }This code scales the ReplicationController named "my-controller" in the "my-namespace" namespace to 5 replicas.