import ( "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/client/rest" "k8s.io/kubernetes/pkg/labels" ) func main() { config := &rest.Config{...} client := unversioned.New(config) // select the pods to delete by label selector := labels.SelectorFromSet(labels.Set{"app": "myapp"}) // create a pod delete options object with grace period set to 0 deleteOpts := &unversioned.DeleteOptions{GracePeriodSeconds: 0} // delete the pods matching the selector err := client.Pods("").DeleteCollection(deleteOpts, selector) if err != nil { panic(err) } }
import ( "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/client/rest" "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/apis/extensions" ) func main() { config := &rest.Config{...} client := unversioned.New(config) // select the deployments to update by label selector := labels.SelectorFromSet(labels.Set{"app": "myapp"}) // create a deployment update object with 3 replicas and new image update := &extensions.Deployment{ Spec: extensions.DeploymentSpec{ Replicas: 3, Template: &api.PodTemplateSpec{ Spec: api.PodSpec{ Containers: []api.Container{ { Name: "myapp", Image: "myregistry/myapp:latest", }, }, }, }, }, } // update the deployments matching the selector err := client.Deployments("").Update(update, selector) if err != nil { panic(err) } }In this example, we create a Kubernetes client using the provided REST config, then we use a label selector to identify the set of deployments we want to update. We create an update object specifying a new image and 3 replicas for the deployment, then we call the `Update` method on the `Deployments` subresource, passing in our update object and label selector.