Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support autoscale deployments #17269

Merged
merged 1 commit into from
Nov 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/man/man1/kubectl-autoscale.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.


Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spec:
kind: ReplicationController
name: php-apache
namespace: default
subresource: scale
minReplicas: 1
maxReplicas: 10
cpuUtilization:
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/kubectl/kubectl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl.md?pixel)]()
Expand Down
10 changes: 5 additions & 5 deletions docs/user-guide/kubectl/kubectl_autoscale.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

```
Expand All @@ -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
Expand Down Expand Up @@ -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

<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_autoscale.md?pixel)]()
Expand Down
15 changes: 14 additions & 1 deletion hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=$!

Expand Down Expand Up @@ -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 #
######################
Expand Down
9 changes: 4 additions & 5 deletions pkg/kubectl/cmd/autoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubectl/cmd/util/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down