kubernetes vpa for CronJob



我需要为CronJob运行VPA。我指的是这个医生。我认为我正确地遵循了它,但它不适合我。

  • using 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哦!!所以我们没有足够的时间去获得推荐的指标资源……- 10 at 2:36

是的,没错。如果CronJob的唯一任务是进入echo Hello from the Kubernetes cluster并退出,那么VPA将不会给出任何建议,因为这不是一个资源密集型任务。

但是,如果修改命令以生成人工负载CronJob管理的pod中:

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>

重要:只是不要让它运行太久,否则你可能会对你的账单感到非常惊讶😉

相关内容

  • 没有找到相关文章

最新更新