Skip to content

Commit b32c204

Browse files
committed
VPA switches to 0.4.0
Change default version Update docs
1 parent 7f77136 commit b32c204

File tree

9 files changed

+179
-47
lines changed

9 files changed

+179
-47
lines changed

vertical-pod-autoscaler/README.md

Lines changed: 98 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,113 @@ It can both down-scale pods that are over-requesting resources, and also up-scal
1212

1313
Autoscaling is configured with a
1414
[Custom Resource Definition object](https://kubernetes.io/docs/concepts/api-extension/custom-resources/)
15-
called [VerticalPodAutoscaler](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta1/types.go).
15+
called [VerticalPodAutoscaler](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta2/types.go).
1616
It allows to specify which pods should be under vertically autoscaled as well as if/how the
1717
resource recommendations are applied.
1818

1919
To enable vertical pod autoscaling on your cluster please follow the installation
2020
procedure described below.
2121

22-
2322
# Installation
2423

25-
### Notice on switching from alpha to beta (<0.3.0 to >=0.3.0)
24+
The current default version is Verical Pod Autoscaler 0.4.0
25+
26+
**NOTE:** version 0.4 requires at least Kubernetes 1.11 to work (needs certain
27+
Custom Resource Definition capabilities). With older Kubernetes versions we
28+
suggest using the [latest 0.3 version](https://github.com/kubernetes/autoscaler/blob/vpa-release-0.3/vertical-pod-autoscaler/README.md)
29+
30+
### Notice on switching to v1beta2 version (0.3.X to >=0.4.0)
2631

27-
Between versions 0.2.x and 0.3.x there is an alpha to beta switch which includes
28-
a change of VPA apiVersion from `poc.autoscaling.k8s.io/v1alpha1` to `autoscaling.k8s.io/v1beta1`.
29-
The safest way to switch is to use `vpa-down.sh` script to tear down
30-
the old installation of VPA first. This will delete your old VPA objects that
31-
have been defined with `poc.autoscaling.k8s.io/v1alpha1` apiVersion.
32-
Then use `vpa-up.sh` to bring up the new version of VPA and create you VPA
33-
objects from the scratch, passing apiVersion `autoscaling.k8s.io/v1beta1`
34-
(See [example](./examples/hamster.yaml)).
32+
In 0.4.0 we introduced a new version of the API - `autoscaling.k8s.io/v1beta2`.
33+
Full API is accessible [here](https://github.com/kubernetes/autoscaler/blob/master/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta2/types.go).
3534

36-
If you want to migrate your objects between versions, you can use the [object conversion script](./hack/convert-alpha-objects.sh).
37-
It will save your VPA objects into temporary yaml files with the new apiVersion.
38-
After running the script:
39-
1. disable alpha VPA via vpa-down.sh script
40-
1. enable beta VPA via vpa-up.sh script
41-
1. re-create VPA objects following the instructions from the script.
35+
The change introduced is in the way you express what pods should be scaled by a
36+
given Vertical Pod Autoscaler. In short we are moving from label selectors to
37+
controller references. Let's start with an example to ilustrate the change:
4238

43-
**NOTE: ** The script is experimental. Please check that the yaml files it generates are correct.
44-
When switching between alpha and beta, VPA recommendations will NOT be kept and there
45-
will be a brief disruption period until the new VPA computes new recommendations.
39+
**[DEPRECATED]** In `v1beta1` pods to scale by VPA are specified by a
40+
[kubernetes label selector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors).
4641

47-
To use the script:
42+
```yaml
43+
apiVersion: "autoscaling.k8s.io/v1beta1"
44+
kind: VerticalPodAutoscaler
45+
metadata:
46+
name: hamster-vpa
47+
spec:
48+
selector: # selector is the deprecated way
49+
matchLabels:
50+
app: hamster
51+
```
52+
53+
**[RECOMMENDED]** In `v1beta2` pods to scale by VPA are specified by a
54+
target reference. This target will usually be a Deployment, as configured in the
55+
example below.
56+
57+
```yaml
58+
apiVersion: "autoscaling.k8s.io/v1beta1"
59+
kind: VerticalPodAutoscaler
60+
metadata:
61+
name: hamster-vpa
62+
spec:
63+
targetRef:
64+
apiVersion: "extensions/v1beta1"
65+
kind: Deployment
66+
name: hamster
4867
```
49-
./hack/convert-alpha-objects.sh
68+
69+
The target object can be a well known controller (Deployment, ReplicaSet, DaemonSet, StatefulSet etc.)
70+
or any object that implements the scale subresource. VPA uses ScaleStatus to
71+
retrieve the pod set controlled by this objetc.
72+
If VerticalPodAutoscaler cannot use specified target it will report
73+
ConfigUnsupported condition.
74+
75+
Note that VerticalPodAutoscaler does not require full implementation
76+
of scale subresource - it will not use it to modify the replica count.
77+
The only thing retrieved is a label selector matching pods grouped by this controller.
78+
79+
See complete examples:
80+
* [v1beta2](./examples/hamster.yaml)
81+
* [v1beta1](./examples/hamster-deprecated.yaml)
82+
83+
You can perform a 0.3 to 0.4 upgrade without losing your VPA objects.
84+
The recommended way is as follows:
85+
86+
1. Run `./hack/vpa-apply-upgrade.sh` - this will restart your VPA installation with
87+
a new version, add the new API and keep all your VPA objects.
88+
1. Your `v1beta1` objects will be marked as deprecated but still work
89+
1. Switch your VPA definition to
90+
`apiVersion: "autoscaling.k8s.io/v1beta2"`
91+
1. Modify the VPA spec to:
92+
```yaml
93+
spec:
94+
# Note the empty selector field - this is needed to remove previously defined selector
95+
selector:
96+
targetRef:
97+
apiVersion: "extensions/v1beta1"
98+
kind: "Deployment"
99+
name: "<deployment_name>" # This matches the deployment name
50100
```
101+
5. Kubectl apply -f the above
102+
103+
You can also first try the new API in the `"Off"` mode.
104+
105+
### Notice on switching from alpha to beta (<0.3.0 to 0.4.0+)
106+
107+
**NOTE:** We highly recommend switching to the 0.4.X version. However,
108+
for instructions on switching to 0.3.X see the [0.3 version README](https://github.com/kubernetes/autoscaler/blob/vpa-release-0.3/vertical-pod-autoscaler/README.md)
109+
110+
Between versions 0.2.x and 0.4.x there is an alpha to beta switch which includes
111+
a change of VPA apiVersion. The safest way to switch is to use `vpa-down.sh`
112+
script to tear down the old installation of VPA first. This will delete your old
113+
VPA objects that have been defined with `poc.autoscaling.k8s.io/v1alpha1`
114+
apiVersion. Then use `vpa-up.sh` to bring up the new version of VPA and create
115+
your VPA objects from the scratch, passing apiVersion
116+
`autoscaling.k8s.io/v1beta2` and switching from selector to targetRef, as
117+
described in the prevous section.
51118

52119
### Prerequisites
53120

54-
* It is strongly recommended to use Kubernetes 1.9 or greater.
55-
Your cluster must support MutatingAdmissionWebhooks, which are enabled by default
56-
since 1.9 ([#58255](https://github.com/kubernetes/kubernetes/pull/58255)).
57-
Read more about [VPA Admission Webhook](./pkg/admission-controller/README.md#running).
121+
* VPA version 0.4+ requires Kubernetes 1.11. For older versions see [latest 0.3 version](https://github.com/kubernetes/autoscaler/blob/vpa-release-0.3/vertical-pod-autoscaler/README.md)
58122
* `kubectl` should be connected to the cluster you want to install VPA in.
59123
* The metrics server must be deployed in your cluster. Read more about [Metrics Server](https://github.com/kubernetes-incubator/metrics-server).
60124
* If you are using a GKE Kubernetes cluster, you will need to grant your current Google
@@ -97,9 +161,8 @@ with the API server.
97161
After [installation](#installation) the system is ready to recommend and set
98162
resource requests for your pods.
99163
In order to use it you need to insert a *Vertical Pod Autoscaler* resource for
100-
each logical group of pods that have similar resource requirements.
101-
We recommend to insert a *VPA* per each *Deployment* you want to control
102-
automatically and use the same label selector as the *Deployment* uses.
164+
each controller that you want to have automatically computed resource requirements.
165+
This will be most commonly a **Deployment**.
103166
There are three modes in which *VPAs* operate:
104167

105168
* `"Auto"`: VPA assigns resource requests on pod creation as well as updates
@@ -130,7 +193,7 @@ kubectl create -f examples/hamster.yaml
130193

131194
The above command creates a deployment with 2 pods, each running a single container
132195
that requests 100 millicores and tries to utilize slightly above 500 millicores.
133-
The command also creates a VPA config with selector that matches the pods in the deployment.
196+
The command also creates a VPA config point at the deployment.
134197
VPA will observe the behavior of the pods and after about 5 minutes they should get
135198
updated with a higher CPU request
136199
(note that VPA does not modify the template in the deployment, but the actual requests
@@ -151,9 +214,10 @@ kind: VerticalPodAutoscaler
151214
metadata:
152215
name: my-app-vpa
153216
spec:
154-
selector:
155-
matchLabels:
156-
app: my-app
217+
targetRef:
218+
apiVersion: "extensions/v1beta1"
219+
kind: Deployment
220+
name: my-app
157221
updatePolicy:
158222
updateMode: "Auto"
159223
```
@@ -242,4 +306,4 @@ kubectl delete clusterrolebinding myname-cluster-admin-binding
242306
* [Design
243307
proposal](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/autoscaling/vertical-pod-autoscaler.md)
244308
* [API
245-
definition](pkg/apis/autoscaling.k8s.io/v1beta1/types.go)
309+
definition](pkg/apis/autoscaling.k8s.io/v1beta2/types.go)

vertical-pod-autoscaler/deploy/admission-controller-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
serviceAccountName: vpa-admission-controller
1515
containers:
1616
- name: admission-controller
17-
image: k8s.gcr.io/vpa-admission-controller:0.3.1
17+
image: k8s.gcr.io/vpa-admission-controller:0.4.0
1818
imagePullPolicy: Always
1919
env:
2020
- name: NAMESPACE

vertical-pod-autoscaler/deploy/recommender-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
serviceAccountName: vpa-recommender
2121
containers:
2222
- name: recommender
23-
image: k8s.gcr.io/vpa-recommender:0.3.1
23+
image: k8s.gcr.io/vpa-recommender:0.4.0
2424
imagePullPolicy: Always
2525
resources:
2626
limits:

vertical-pod-autoscaler/deploy/updater-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
serviceAccountName: vpa-updater
2121
containers:
2222
- name: updater
23-
image: k8s.gcr.io/vpa-updater:0.3.1
23+
image: k8s.gcr.io/vpa-updater:0.4.0
2424
imagePullPolicy: Always
2525
resources:
2626
limits:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This config creates a deployment with two pods, each requesting 100 millicores
2+
# and trying to utilize slightly above 500 millicores (repeatedly using CPU for
3+
# 0.5s and sleeping 0.5s).
4+
# It also creates a corresponding Vertical Pod Autoscaler that adjusts the requests.
5+
# Note that the update mode is left unset, so it defaults to "Auto" mode.
6+
apiVersion: "autoscaling.k8s.io/v1beta1"
7+
kind: VerticalPodAutoscaler
8+
metadata:
9+
name: hamster-vpa
10+
spec:
11+
selector:
12+
matchLabels:
13+
app: hamster
14+
---
15+
apiVersion: extensions/v1beta1
16+
kind: Deployment
17+
metadata:
18+
name: hamster
19+
spec:
20+
replicas: 2
21+
template:
22+
metadata:
23+
labels:
24+
app: hamster
25+
spec:
26+
containers:
27+
- name: hamster
28+
image: k8s.gcr.io/ubuntu-slim:0.1
29+
resources:
30+
requests:
31+
cpu: 100m
32+
memory: 50Mi
33+
command: ["/bin/sh"]
34+
args: ["-c", "while true; do timeout 0.5s yes >/dev/null; sleep 0.5s; done"]

vertical-pod-autoscaler/examples/hamster.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
# 0.5s and sleeping 0.5s).
44
# It also creates a corresponding Vertical Pod Autoscaler that adjusts the requests.
55
# Note that the update mode is left unset, so it defaults to "Auto" mode.
6-
apiVersion: "autoscaling.k8s.io/v1beta1"
6+
apiVersion: "autoscaling.k8s.io/v1beta2"
77
kind: VerticalPodAutoscaler
88
metadata:
9-
name: hamster-vpa
9+
name: hamster-vpa-beta2
1010
spec:
11-
selector:
12-
matchLabels:
13-
app: hamster
11+
targetRef:
12+
apiVersion: "extensions/v1beta1"
13+
kind: Deployment
14+
name: hamster
1415
---
1516
apiVersion: extensions/v1beta1
1617
kind: Deployment
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: autoscaling.k8s.io/v1beta1
2+
kind: VerticalPodAutoscaler
3+
metadata:
4+
name: redis-vpa
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: redis
9+
---
10+
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
11+
kind: Deployment
12+
metadata:
13+
name: redis-master
14+
spec:
15+
selector:
16+
matchLabels:
17+
app: redis
18+
replicas: 3
19+
template:
20+
metadata:
21+
labels:
22+
app: redis
23+
spec:
24+
containers:
25+
- name: master
26+
image: k8s.gcr.io/redis:e2e # or just image: redis
27+
resources:
28+
requests:
29+
cpu: 100m
30+
memory: 100Mi
31+
ports:
32+
- containerPort: 6379

vertical-pod-autoscaler/examples/redis.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
apiVersion: autoscaling.k8s.io/v1beta1
1+
apiVersion: autoscaling.k8s.io/v1beta2
22
kind: VerticalPodAutoscaler
33
metadata:
44
name: redis-vpa
55
spec:
6-
selector:
7-
matchLabels:
8-
app: redis
6+
targetRef:
7+
apiVersion: "extensions/v1beta1"
8+
kind: Deployment
9+
name: redis-master
910
---
1011
apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
1112
kind: Deployment

vertical-pod-autoscaler/hack/vpa-process-yaml.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if [ $# -eq 0 ]; then
3232
fi
3333

3434
DEFAULT_REGISTRY="k8s.gcr.io"
35-
DEFAULT_TAG="0.3.1"
35+
DEFAULT_TAG="0.4.0"
3636

3737
REGISTRY_TO_APPLY=${REGISTRY-$DEFAULT_REGISTRY}
3838
TAG_TO_APPLY=${TAG-$DEFAULT_TAG}

0 commit comments

Comments
 (0)