diff --git a/docs/man/man1/kubectl-autoscale.1 b/docs/man/man1/kubectl-autoscale.1 index 0dda920eb76..1d2e5b7f9ca 100644 --- a/docs/man/man1/kubectl-autoscale.1 +++ b/docs/man/man1/kubectl-autoscale.1 @@ -3,7 +3,7 @@ .SH NAME .PP -kubectl autoscale \- Auto\-scale a replication controller +kubectl autoscale \- Auto\-scale a deployment or replication controller .SH SYNOPSIS @@ -16,7 +16,7 @@ kubectl autoscale \- Auto\-scale a replication controller Creates an autoscaler that automatically chooses and sets the number of pods that run in a kubernetes cluster. .PP -Looks up a replication controller by name and creates an autoscaler that uses this replication controller as a reference. +Looks up a deployment or replication controller by name and creates an autoscaler that uses this deployment or replication controller as a reference. An autoscaler can automatically increase or decrease number of pods deployed within the system as needed. @@ -180,8 +180,8 @@ An autoscaler can automatically increase or decrease number of pods deployed wit .RS .nf -# Auto scale a replication controller "foo", with the number of pods between 2 to 10, target CPU utilization at a default value that server applies: -$ kubectl autoscale rc foo \-\-min=2 \-\-max=10 +# Auto scale a deployment "foo", with the number of pods between 2 to 10, target CPU utilization at a default value that server applies: +$ kubectl autoscale deployment foo \-\-min=2 \-\-max=10 # Auto scale a replication controller "foo", with the number of pods between 1 to 5, target CPU utilization at 80%: $ kubectl autoscale rc foo \-\-max=5 \-\-cpu\-percent=80 diff --git a/docs/user-guide/horizontal-pod-autoscaling/hpa-php-apache.yaml b/docs/user-guide/horizontal-pod-autoscaling/hpa-php-apache.yaml index 1a2067714d4..ab46a2ec5a0 100644 --- a/docs/user-guide/horizontal-pod-autoscaling/hpa-php-apache.yaml +++ b/docs/user-guide/horizontal-pod-autoscaling/hpa-php-apache.yaml @@ -8,6 +8,7 @@ spec: kind: ReplicationController name: php-apache namespace: default + subresource: scale minReplicas: 1 maxReplicas: 10 cpuUtilization: diff --git a/docs/user-guide/kubectl/kubectl.md b/docs/user-guide/kubectl/kubectl.md index ec929457c8c..8c02a283b8e 100644 --- a/docs/user-guide/kubectl/kubectl.md +++ b/docs/user-guide/kubectl/kubectl.md @@ -80,7 +80,7 @@ kubectl * [kubectl api-versions](kubectl_api-versions.md) - Print the supported API versions on the server, in the form of "group/version". * [kubectl apply](kubectl_apply.md) - Apply a configuration to a resource by filename or stdin * [kubectl attach](kubectl_attach.md) - Attach to a running container. -* [kubectl autoscale](kubectl_autoscale.md) - Auto-scale a replication controller +* [kubectl autoscale](kubectl_autoscale.md) - Auto-scale a deployment or replication controller * [kubectl cluster-info](kubectl_cluster-info.md) - Display cluster info * [kubectl config](kubectl_config.md) - config modifies kubeconfig files * [kubectl convert](kubectl_convert.md) - Convert config files between different API versions @@ -105,7 +105,7 @@ kubectl * [kubectl stop](kubectl_stop.md) - Deprecated: Gracefully shut down a resource by name or filename. * [kubectl version](kubectl_version.md) - Print the client and server version information. -###### Auto generated by spf13/cobra on 10-Nov-2015 +###### Auto generated by spf13/cobra on 13-Nov-2015 [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl.md?pixel)]() diff --git a/docs/user-guide/kubectl/kubectl_autoscale.md b/docs/user-guide/kubectl/kubectl_autoscale.md index b0dedfff665..bbe12b791dd 100644 --- a/docs/user-guide/kubectl/kubectl_autoscale.md +++ b/docs/user-guide/kubectl/kubectl_autoscale.md @@ -33,14 +33,14 @@ Documentation for other releases can be found at ## kubectl autoscale -Auto-scale a replication controller +Auto-scale a deployment or replication controller ### Synopsis Creates an autoscaler that automatically chooses and sets the number of pods that run in a kubernetes cluster. -Looks up a replication controller by name and creates an autoscaler that uses this replication controller as a reference. +Looks up a deployment or replication controller by name and creates an autoscaler that uses this deployment or replication controller as a reference. An autoscaler can automatically increase or decrease number of pods deployed within the system as needed. ``` @@ -50,8 +50,8 @@ kubectl autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MA ### Examples ``` -# Auto scale a replication controller "foo", with the number of pods between 2 to 10, target CPU utilization at a default value that server applies: -$ kubectl autoscale rc foo --min=2 --max=10 +# Auto scale a deployment "foo", with the number of pods between 2 to 10, target CPU utilization at a default value that server applies: +$ kubectl autoscale deployment foo --min=2 --max=10 # Auto scale a replication controller "foo", with the number of pods between 1 to 5, target CPU utilization at 80%: $ kubectl autoscale rc foo --max=5 --cpu-percent=80 @@ -108,7 +108,7 @@ $ kubectl autoscale rc foo --max=5 --cpu-percent=80 * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager -###### Auto generated by spf13/cobra on 6-Nov-2015 +###### Auto generated by spf13/cobra on 13-Nov-2015 [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_autoscale.md?pixel)]() diff --git a/hack/test-cmd.sh b/hack/test-cmd.sh index 53a3545082e..19286ce2d26 100755 --- a/hack/test-cmd.sh +++ b/hack/test-cmd.sh @@ -168,7 +168,7 @@ KUBE_API_VERSIONS="v1,extensions/v1beta1" "${KUBE_OUTPUT_HOSTBIN}/kube-apiserver --kubelet-port=${KUBELET_PORT} \ --runtime-config=api/v1 \ --cert-dir="${TMPDIR:-/tmp/}" \ - --runtime_config="extensions/v1beta1=true" \ + --runtime_config="extensions/v1beta1/deployments=true" \ --service-cluster-ip-range="10.0.0.0/24" 1>&2 & APISERVER_PID=$! @@ -957,6 +957,19 @@ __EOF__ # Clean up kubectl delete rc frontend "${kube_flags[@]}" + ### Auto scale deployment + # Pre-condition: no deployment is running + kube::test::get_object_assert deployment "{{range.items}}{{$id_field}}:{{end}}" '' + # Command + kubectl create -f examples/extensions/deployment.yaml "${kube_flags[@]}" + kube::test::get_object_assert deployment "{{range.items}}{{$id_field}}:{{end}}" 'nginx-deployment:' + # autoscale 2~3 pods, default CPU utilization (80%) + kubectl autoscale deployment nginx-deployment "${kube_flags[@]}" --min=2 --max=3 + kube::test::get_object_assert 'hpa nginx-deployment' "{{$hpa_min_field}} {{$hpa_max_field}} {{$hpa_cpu_field}}" '2 3 80' + # Clean up + kubectl delete hpa nginx-deployment "${kube_flags[@]}" + kubectl delete deployment nginx-deployment "${kube_flags[@]}" + ###################### # Multiple Resources # ###################### diff --git a/pkg/kubectl/cmd/autoscale.go b/pkg/kubectl/cmd/autoscale.go index c029bf4bcba..e9a578d001b 100644 --- a/pkg/kubectl/cmd/autoscale.go +++ b/pkg/kubectl/cmd/autoscale.go @@ -31,22 +31,21 @@ import ( const ( autoscaleLong = `Creates an autoscaler that automatically chooses and sets the number of pods that run in a kubernetes cluster. -Looks up a replication controller by name and creates an autoscaler that uses this replication controller as a reference. +Looks up a deployment or replication controller by name and creates an autoscaler that uses this deployment or replication controller as a reference. An autoscaler can automatically increase or decrease number of pods deployed within the system as needed.` - autoscaleExample = `# Auto scale a replication controller "foo", with the number of pods between 2 to 10, target CPU utilization at a default value that server applies: -$ kubectl autoscale rc foo --min=2 --max=10 + autoscaleExample = `# Auto scale a deployment "foo", with the number of pods between 2 to 10, target CPU utilization at a default value that server applies: +$ kubectl autoscale deployment foo --min=2 --max=10 # Auto scale a replication controller "foo", with the number of pods between 1 to 5, target CPU utilization at 80%: $ kubectl autoscale rc foo --max=5 --cpu-percent=80` ) -// TODO: support autoscale for deployments func NewCmdAutoscale(f *cmdutil.Factory, out io.Writer) *cobra.Command { filenames := []string{} cmd := &cobra.Command{ Use: "autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]", - Short: "Auto-scale a replication controller", + Short: "Auto-scale a deployment or replication controller", Long: autoscaleLong, Example: autoscaleExample, Run: func(cmd *cobra.Command, args []string) { diff --git a/pkg/kubectl/cmd/util/factory.go b/pkg/kubectl/cmd/util/factory.go index 81711c48a65..360d690d023 100644 --- a/pkg/kubectl/cmd/util/factory.go +++ b/pkg/kubectl/cmd/util/factory.go @@ -295,8 +295,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory { }, CanBeAutoscaled: func(kind string) error { switch kind { - // TODO: support autoscale for deployments - case "ReplicationController": + case "ReplicationController", "Deployment": // nothing to do here default: return fmt.Errorf("cannot autoscale a %s", kind)