Merge pull request #17269 from janetkuo/autoscale-deployments

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot 2015-11-21 22:23:23 -08:00
commit 6d2b92a0be
7 changed files with 31 additions and 19 deletions

View File

@ -3,7 +3,7 @@
.SH NAME .SH NAME
.PP .PP
kubectl autoscale \- Auto\-scale a replication controller kubectl autoscale \- Auto\-scale a deployment or replication controller
.SH SYNOPSIS .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. Creates an autoscaler that automatically chooses and sets the number of pods that run in a kubernetes cluster.
.PP .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. 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 .RS
.nf .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: # 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 rc foo \-\-min=2 \-\-max=10 $ 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%: # 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 $ kubectl autoscale rc foo \-\-max=5 \-\-cpu\-percent=80

View File

@ -8,6 +8,7 @@ spec:
kind: ReplicationController kind: ReplicationController
name: php-apache name: php-apache
namespace: default namespace: default
subresource: scale
minReplicas: 1 minReplicas: 1
maxReplicas: 10 maxReplicas: 10
cpuUtilization: cpuUtilization:

View File

@ -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 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 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 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 cluster-info](kubectl_cluster-info.md) - Display cluster info
* [kubectl config](kubectl_config.md) - config modifies kubeconfig files * [kubectl config](kubectl_config.md) - config modifies kubeconfig files
* [kubectl convert](kubectl_convert.md) - Convert config files between different API versions * [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 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. * [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
<!-- BEGIN MUNGE: GENERATED_ANALYTICS --> <!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl.md?pixel)]()

View File

@ -33,14 +33,14 @@ Documentation for other releases can be found at
## kubectl autoscale ## kubectl autoscale
Auto-scale a replication controller Auto-scale a deployment or replication controller
### Synopsis ### Synopsis
Creates an autoscaler that automatically chooses and sets the number of pods that run in a kubernetes cluster. 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. 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 ### 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: # 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 rc foo --min=2 --max=10 $ 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%: # 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 $ 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 * [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
<!-- BEGIN MUNGE: GENERATED_ANALYTICS --> <!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_autoscale.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_autoscale.md?pixel)]()

View File

@ -168,7 +168,7 @@ KUBE_API_VERSIONS="v1,extensions/v1beta1" "${KUBE_OUTPUT_HOSTBIN}/kube-apiserver
--kubelet-port=${KUBELET_PORT} \ --kubelet-port=${KUBELET_PORT} \
--runtime-config=api/v1 \ --runtime-config=api/v1 \
--cert-dir="${TMPDIR:-/tmp/}" \ --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 & --service-cluster-ip-range="10.0.0.0/24" 1>&2 &
APISERVER_PID=$! APISERVER_PID=$!
@ -957,6 +957,19 @@ __EOF__
# Clean up # Clean up
kubectl delete rc frontend "${kube_flags[@]}" 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 # # Multiple Resources #
###################### ######################

View File

@ -31,22 +31,21 @@ import (
const ( const (
autoscaleLong = `Creates an autoscaler that automatically chooses and sets the number of pods that run in a kubernetes cluster. 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.` 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: 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 rc foo --min=2 --max=10 $ 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%: # 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` $ kubectl autoscale rc foo --max=5 --cpu-percent=80`
) )
// TODO: support autoscale for deployments
func NewCmdAutoscale(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdAutoscale(f *cmdutil.Factory, out io.Writer) *cobra.Command {
filenames := []string{} filenames := []string{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]", 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, Long: autoscaleLong,
Example: autoscaleExample, Example: autoscaleExample,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {

View File

@ -295,8 +295,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}, },
CanBeAutoscaled: func(kind string) error { CanBeAutoscaled: func(kind string) error {
switch kind { switch kind {
// TODO: support autoscale for deployments case "ReplicationController", "Deployment":
case "ReplicationController":
// nothing to do here // nothing to do here
default: default:
return fmt.Errorf("cannot autoscale a %s", kind) return fmt.Errorf("cannot autoscale a %s", kind)