podTemplate := &v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Name: "my-pod-template", Namespace: "default", }, Spec: v1.PodSpec{ Containers: []v1.Container{ { Name: "my-container", Image: "my-image:latest", }, }, }, }
rc := &v1.ReplicationController{ ObjectMeta: metav1.ObjectMeta{ Name: "my-replication-controller", }, Spec: v1.ReplicationControllerSpec{ Replicas: int32(3), Template: *podTemplate, Selector: map[string]string{ "app": "my-app", }, }, }
rcClient := client.ReplicationControllers("default") createdRC, err := rcClient.Create(rc) if err != nil { log.Fatalf("Failed to create ReplicationController: %v", err) }In this example, we use the go k8s.io/kubernetes/pkg/client/unversioned package library to create a ReplicationController in the "default" namespace of the Kubernetes cluster. We specify a Pod template with a single container running the "my-image:latest" image, and set the number of replicas we want to run to 3. We also specify a label selector to ensure only Pods with the "app=my-app" label are managed by this ReplicationController.