|
1 | 1 | // Module included in the following assemblies: |
2 | 2 | // |
3 | | -// * nodes/nodes-pods-autoscaling-about.adoc |
| 3 | +// * nodes/nodes-pods-autoscaling.adoc |
4 | 4 |
|
5 | 5 | :_mod-docs-content-type: PROCEDURE |
6 | 6 | [id="nodes-pods-autoscaling-creating-cpu_{context}"] |
7 | | -= Creating a horizontal pod autoscaler for CPU utilization by using the CLI |
| 7 | += Creating a horizontal pod autoscaler by using the CLI |
8 | 8 |
|
9 | | -Using the {product-title} CLI, you can create a horizontal pod autoscaler (HPA) to automatically scale an existing `Deployment`, `DeploymentConfig`, `ReplicaSet`, `ReplicationController`, or `StatefulSet` object. The HPA scales the pods associated with that object to maintain the CPU usage you specify. |
| 9 | +Using the {product-title} CLI, you can create a horizontal pod autoscaler (HPA) to automatically scale an existing `Deployment`, `DeploymentConfig`, `ReplicaSet`, `ReplicationController`, or `StatefulSet` object. The HPA scales the pods associated with that object to maintain the CPU or memory resources that you specify. |
10 | 10 |
|
11 | | -[NOTE] |
12 | | -==== |
13 | | -It is recommended to use a `Deployment` object or `ReplicaSet` object unless you need a specific feature or behavior provided by other objects. |
14 | | -==== |
15 | | - |
16 | | -The HPA increases and decreases the number of replicas between the minimum and maximum numbers to maintain the specified CPU utilization across all pods. |
17 | | - |
18 | | -When autoscaling for CPU utilization, you can use the `oc autoscale` command and specify the minimum and maximum number of pods you want to run at any given time and the average CPU utilization your pods should target. If you do not specify a minimum, the pods are given default values from the {product-title} server. |
19 | | - |
20 | | -To autoscale for a specific CPU value, create a `HorizontalPodAutoscaler` object with the target CPU and pod limits. |
21 | | - |
22 | | -.Prerequisites |
23 | | - |
24 | | -To use horizontal pod autoscalers, your cluster administrator must have properly configured cluster metrics. |
25 | | -You can use the `oc describe PodMetrics <pod-name>` command to determine if metrics are configured. If metrics are |
26 | | -configured, the output appears similar to the following, with `Cpu` and `Memory` displayed under `Usage`. |
27 | | - |
28 | | -[source,terminal] |
29 | | ----- |
30 | | -$ oc describe PodMetrics openshift-kube-scheduler-ip-10-0-135-131.ec2.internal |
31 | | ----- |
32 | | - |
33 | | -.Example output |
34 | | -[source,text,options="nowrap"] |
35 | | ----- |
36 | | -Name: openshift-kube-scheduler-ip-10-0-135-131.ec2.internal |
37 | | -Namespace: openshift-kube-scheduler |
38 | | -Labels: <none> |
39 | | -Annotations: <none> |
40 | | -API Version: metrics.k8s.io/v1beta1 |
41 | | -Containers: |
42 | | - Name: wait-for-host-port |
43 | | - Usage: |
44 | | - Memory: 0 |
45 | | - Name: scheduler |
46 | | - Usage: |
47 | | - Cpu: 8m |
48 | | - Memory: 45440Ki |
49 | | -Kind: PodMetrics |
50 | | -Metadata: |
51 | | - Creation Timestamp: 2019-05-23T18:47:56Z |
52 | | - Self Link: /apis/metrics.k8s.io/v1beta1/namespaces/openshift-kube-scheduler/pods/openshift-kube-scheduler-ip-10-0-135-131.ec2.internal |
53 | | -Timestamp: 2019-05-23T18:47:56Z |
54 | | -Window: 1m0s |
55 | | -Events: <none> |
56 | | ----- |
57 | | - |
58 | | -.Procedure |
59 | | - |
60 | | -To create a horizontal pod autoscaler for CPU utilization: |
61 | | - |
62 | | -. Perform one of the following: |
63 | | - |
64 | | -** To scale based on the percent of CPU utilization, create a `HorizontalPodAutoscaler` object for an existing object: |
65 | | -+ |
66 | | -[source,terminal] |
67 | | ----- |
68 | | -$ oc autoscale <object_type>/<name> \// <1> |
69 | | - --min <number> \// <2> |
70 | | - --max <number> \// <3> |
71 | | - --cpu-percent=<percent> <4> |
72 | | ----- |
73 | | -+ |
74 | | -<1> Specify the type and name of the object to autoscale. The object must exist and be a `Deployment`, `DeploymentConfig`/`dc`, `ReplicaSet`/`rs`, `ReplicationController`/`rc`, or `StatefulSet`. |
75 | | -<2> Optionally, specify the minimum number of replicas when scaling down. |
76 | | -<3> Specify the maximum number of replicas when scaling up. |
77 | | -<4> Specify the target average CPU utilization over all the pods, represented as a percent of requested CPU. If not specified or negative, a default autoscaling policy is used. |
78 | | -+ |
79 | | -For example, the following command shows autoscaling for the `hello-node` deployment object. The initial deployment requires 3 pods. The HPA object increases the minimum to 5. If CPU usage on the pods reaches 75%, the pods will increase to 7: |
80 | | -+ |
81 | | -[source,terminal] |
82 | | ----- |
83 | | -$ oc autoscale deployment/hello-node --min=5 --max=7 --cpu-percent=75 |
84 | | ----- |
85 | | - |
86 | | -** To scale for a specific CPU value, create a YAML file similar to the following for an existing object: |
87 | | -+ |
88 | | -.. Create a YAML file similar to the following: |
89 | | -+ |
90 | | -[source,yaml,options="nowrap"] |
91 | | ----- |
92 | | -apiVersion: autoscaling/v2 <1> |
93 | | -kind: HorizontalPodAutoscaler |
94 | | -metadata: |
95 | | - name: cpu-autoscale <2> |
96 | | - namespace: default |
97 | | -spec: |
98 | | - scaleTargetRef: |
99 | | - apiVersion: apps/v1 <3> |
100 | | - kind: Deployment <4> |
101 | | - name: example <5> |
102 | | - minReplicas: 1 <6> |
103 | | - maxReplicas: 10 <7> |
104 | | - metrics: <8> |
105 | | - - type: Resource |
106 | | - resource: |
107 | | - name: cpu <9> |
108 | | - target: |
109 | | - type: AverageValue <10> |
110 | | - averageValue: 500m <11> |
111 | | ----- |
112 | | -<1> Use the `autoscaling/v2` API. |
113 | | -<2> Specify a name for this horizontal pod autoscaler object. |
114 | | -<3> Specify the API version of the object to scale: |
115 | | -* For a `Deployment`, `ReplicaSet`, `Statefulset` object, use `apps/v1`. |
116 | | -* For a `ReplicationController`, use `v1`. |
117 | | -* For a `DeploymentConfig`, use `apps.openshift.io/v1`. |
118 | | -<4> Specify the type of object. The object must be a `Deployment`, `DeploymentConfig`/`dc`, `ReplicaSet`/`rs`, `ReplicationController`/`rc`, or `StatefulSet`. |
119 | | -<5> Specify the name of the object to scale. The object must exist. |
120 | | -<6> Specify the minimum number of replicas when scaling down. |
121 | | -<7> Specify the maximum number of replicas when scaling up. |
122 | | -<8> Use the `metrics` parameter for memory utilization. |
123 | | -<9> Specify `cpu` for CPU utilization. |
124 | | -<10> Set to `AverageValue`. |
125 | | -<11> Set to `averageValue` with the targeted CPU value. |
126 | | - |
127 | | -.. Create the horizontal pod autoscaler: |
128 | | -+ |
129 | | -[source,terminal] |
130 | | ----- |
131 | | -$ oc create -f <file-name>.yaml |
132 | | ----- |
133 | | - |
134 | | -. Verify that the horizontal pod autoscaler was created: |
135 | | -+ |
136 | | -[source,terminal] |
137 | | ----- |
138 | | -$ oc get hpa cpu-autoscale |
139 | | ----- |
140 | | -+ |
141 | | -.Example output |
142 | | -[source,terminal] |
143 | | ----- |
144 | | -NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE |
145 | | -cpu-autoscale Deployment/example 173m/500m 1 10 1 20m |
146 | | ----- |
| 11 | +You can autoscale based on CPU or memory use by specifying a percentage of resource usage or a specific value, as described in the following sections. |
147 | 12 |
|
| 13 | +The HPA increases and decreases the number of replicas between the minimum and maximum numbers to maintain the specified resource use across all pods. |
0 commit comments