用于 CronJob 的 kubernetes vpa
kubernetes vpa for CronJob
我需要 运行 CronJob 的 VPA。我指的是 this doc。
我想我正确地遵循了它,但它对我不起作用。
- 使用 GKE,1.17
- VPA 版本为
vpa-release-0.8
- 我用这个文件创建了 CronJob 和 VPA。
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app: hello
spec:
containers:
- name: hello
image: busybox
imagePullPolicy: IfNotPresent
args:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: my-vpa
spec:
targetRef:
apiVersion: "batch/v1beta1"
kind: CronJob
name: hello
updatePolicy:
updateMode: "Auto"
当我键入此命令时:
kubectl describe vpa
我得到了这个结果:
Name: my-vpa
Namespace: default
Labels: <none>
Annotations: <none>
API Version: autoscaling.k8s.io/v1
Kind: VerticalPodAutoscaler
Metadata:
Creation Timestamp: 2021-02-08T07:38:23Z
Generation: 2
Resource Version: 3762
Self Link: /apis/autoscaling.k8s.io/v1/namespaces/default/verticalpodautoscalers/my-vpa
UID: 07803254-c549-4568-a062-144c570a8d41
Spec:
Target Ref:
API Version: batch/v1beta1
Kind: CronJob
Name: hello
Update Policy:
Update Mode: Auto
Status:
Conditions:
Last Transition Time: 2021-02-08T07:39:14Z
Status: False
Type: RecommendationProvided
Recommendation:
Events: <none>
@mario oh!! so there was not enough time to get metrics to recommend
resource.... – 변상현 Feb 10 at 2:36
是的,没错。如果您 CronJob
的唯一任务是 echo Hello from the Kubernetes cluster
然后退出,您将不会从 VPA
获得任何建议,因为这不是资源密集型任务。
但是,如果您修改您的命令,使其在您的 CronJob
-managed pods:
中生成人工负载
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app: hello
spec:
containers:
- name: hello
image: busybox
imagePullPolicy: IfNotPresent
args:
- /bin/sh
- -c
- date; dd if=/dev/urandom | gzip -9 >> /dev/null
restartPolicy: OnFailure
几分钟后您将得到预期的结果:
$ kubectl describe vpa my-vpa
Name: my-vpa
Namespace: default
Labels: <none>
Annotations: <none>
API Version: autoscaling.k8s.io/v1
Kind: VerticalPodAutoscaler
Metadata:
Creation Timestamp: 2021-05-22T13:02:27Z
Generation: 8
...
Manager: vpa-recommender
Operation: Update
Time: 2021-05-22T13:29:40Z
Resource Version: 5534471
Self Link: /apis/autoscaling.k8s.io/v1/namespaces/default/verticalpodautoscalers/my-vpa
UID: e37abd79-296d-4f72-8bd5-f2409457e9ff
Spec:
Target Ref:
API Version: batch/v1beta1
Kind: CronJob
Name: hello
Update Policy:
Update Mode: Auto
Status:
Conditions:
Last Transition Time: 2021-05-22T13:39:40Z
Status: False
Type: LowConfidence
Last Transition Time: 2021-05-22T13:29:40Z
Status: True
Type: RecommendationProvided
Recommendation:
Container Recommendations:
Container Name: hello
Lower Bound:
Cpu: 1185m
Memory: 2097152
Target:
Cpu: 1375m
Memory: 2097152
Uncapped Target:
Cpu: 1375m
Memory: 2097152
Upper Bound:
Cpu: 96655m
Memory: 115343360
Events: <none>
❗重要提示:只是不要离开它运行太久,因为你可能会对你的账单感到非常惊讶
我需要 运行 CronJob 的 VPA。我指的是 this doc。 我想我正确地遵循了它,但它对我不起作用。
- 使用 GKE,1.17
- VPA 版本为
vpa-release-0.8
- 我用这个文件创建了 CronJob 和 VPA。
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app: hello
spec:
containers:
- name: hello
image: busybox
imagePullPolicy: IfNotPresent
args:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: my-vpa
spec:
targetRef:
apiVersion: "batch/v1beta1"
kind: CronJob
name: hello
updatePolicy:
updateMode: "Auto"
当我键入此命令时:
kubectl describe vpa
我得到了这个结果:
Name: my-vpa
Namespace: default
Labels: <none>
Annotations: <none>
API Version: autoscaling.k8s.io/v1
Kind: VerticalPodAutoscaler
Metadata:
Creation Timestamp: 2021-02-08T07:38:23Z
Generation: 2
Resource Version: 3762
Self Link: /apis/autoscaling.k8s.io/v1/namespaces/default/verticalpodautoscalers/my-vpa
UID: 07803254-c549-4568-a062-144c570a8d41
Spec:
Target Ref:
API Version: batch/v1beta1
Kind: CronJob
Name: hello
Update Policy:
Update Mode: Auto
Status:
Conditions:
Last Transition Time: 2021-02-08T07:39:14Z
Status: False
Type: RecommendationProvided
Recommendation:
Events: <none>
@mario oh!! so there was not enough time to get metrics to recommend resource.... – 변상현 Feb 10 at 2:36
是的,没错。如果您 CronJob
的唯一任务是 echo Hello from the Kubernetes cluster
然后退出,您将不会从 VPA
获得任何建议,因为这不是资源密集型任务。
但是,如果您修改您的命令,使其在您的 CronJob
-managed pods:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app: hello
spec:
containers:
- name: hello
image: busybox
imagePullPolicy: IfNotPresent
args:
- /bin/sh
- -c
- date; dd if=/dev/urandom | gzip -9 >> /dev/null
restartPolicy: OnFailure
几分钟后您将得到预期的结果:
$ kubectl describe vpa my-vpa
Name: my-vpa
Namespace: default
Labels: <none>
Annotations: <none>
API Version: autoscaling.k8s.io/v1
Kind: VerticalPodAutoscaler
Metadata:
Creation Timestamp: 2021-05-22T13:02:27Z
Generation: 8
...
Manager: vpa-recommender
Operation: Update
Time: 2021-05-22T13:29:40Z
Resource Version: 5534471
Self Link: /apis/autoscaling.k8s.io/v1/namespaces/default/verticalpodautoscalers/my-vpa
UID: e37abd79-296d-4f72-8bd5-f2409457e9ff
Spec:
Target Ref:
API Version: batch/v1beta1
Kind: CronJob
Name: hello
Update Policy:
Update Mode: Auto
Status:
Conditions:
Last Transition Time: 2021-05-22T13:39:40Z
Status: False
Type: LowConfidence
Last Transition Time: 2021-05-22T13:29:40Z
Status: True
Type: RecommendationProvided
Recommendation:
Container Recommendations:
Container Name: hello
Lower Bound:
Cpu: 1185m
Memory: 2097152
Target:
Cpu: 1375m
Memory: 2097152
Uncapped Target:
Cpu: 1375m
Memory: 2097152
Upper Bound:
Cpu: 96655m
Memory: 115343360
Events: <none>
❗重要提示:只是不要离开它运行太久,因为你可能会对你的账单感到非常惊讶