Kubernetes VPA:targetref 选择器问题 + 最少资源

Kubernetes VPA : issue with targetref selector + minimal resources

我有 2 个问题: - 我的 Vertical pod autoscaler 不遵循我的最小资源策略:

Spec:
  Resource Policy:
    Container Policies:
      Min Allowed:
        Cpu:     50m        <==== mini allowed for CPU
        Memory:  75Mi
      Mode:      auto
  Target Ref:
    API Version:  extensions/v1beta1
    Kind:         Deployment
    Name:         hello-world
  Update Policy:
    Update Mode:  Auto
Status:
  Conditions:
    Last Transition Time:  2019-03-19T19:11:36Z
    Status:                True
    Type:                  RecommendationProvided
  Recommendation:
    Container Recommendations:
      Container Name:  hello-world
      Lower Bound:
        Cpu:     25m
        Memory:  262144k
      Target:
        Cpu:     25m       <==== actual CPU configured by the VPA
        Memory:  262144k

这是我的部署配置:

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: hello-world
  namespace: hello-world
  labels:
    name: hello-world
spec:
  selector:
    matchLabels:
      name: hello-world
  replicas: 2
  template:
    metadata:
      labels:
        name: hello-world
    spec:
      securityContext:
        fsGroup: 101
      containers:
        - name: hello-world
          image: xxx/hello-world:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 3000
              protocol: TCP
          resources:
            limits:
              cpu: 500m
              memory: 500Mi
            requests:
              cpu: 100m
              memory: 150Mi
          volumeMounts:
          - mountPath: /u/app/www/images
            name: nfs-volume
      volumes:
      - name: nfs-volume
        persistentVolumeClaim:
          claimName: hello-world

这是我的 VPA 配置:

---
apiVersion: "autoscaling.k8s.io/v1beta2"
kind: VerticalPodAutoscaler
metadata:
  name: hello-world
  namespace: hello-world
spec:
  targetRef:
    apiVersion: "extensions/v1beta1"
    kind: Deployment
    name: hello-world
  resourcePolicy:
    containerPolicies:
    - minAllowed:
        cpu: 50m
        memory: 75Mi
      mode: auto
  updatePolicy:
    updateMode: "Auto"

我是 运行 kubernetes v1.13.2,VPA v0.4,这是他的配置:

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: vpa-recommender
  namespace: kube-system
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: vpa-recommender
    spec:
      serviceAccountName: vpa-recommender
      containers:
      - name: recommender
        image: k8s.gcr.io/vpa-recommender:0.4.0
        imagePullPolicy: Always
        resources:
          limits:
            cpu: 200m
            memory: 1000Mi
          requests:
            cpu: 50m
            memory: 500Mi
        ports:
        - containerPort: 8080
        command:
        - ./recommender
        - --alsologtostderr=false
        - --logtostderr=false
        - --prometheus-address=http://prometheus-service.monitoring:9090/
        - --prometheus-cadvisor-job-name=cadvisor
        - --v=10

谢谢

我认为您没有使用旧的 fetcher。

这是一个code:

legacySelector, fetchLegacyErr := feeder.legacySelectorFetcher.Fetch(vpa)
if fetchLegacyErr != nil {
    glog.Errorf("Error while fetching legacy selector. Reason: %+v", fetchLegacyErr)
}
selector, fetchErr := feeder.selectorFetcher.Fetch(vpa)
if fetchErr != nil {
    glog.Errorf("Cannot get target selector from VPA's targetRef. Reason: %+v", fetchErr)
}

Autoscaler 只是尝试先获取旧版选择器,然后再使用新的。

关于资源限制。

这是源代码中的一个 comment(PodResourcePolicy 是规范中的一个 "resourcePolicy" 块):

PodResourcePolicy controls how autoscaler computes the recommended resources for containers belonging to the pod. There can be at most one entry for every named container and optionally a single wildcard entry with containerName = '*', which handles all containers that don't have individual policies.

我认为,您还应该在规范中设置 ContainerName,因为您需要一个 pod 范围的策略:

apiVersion: "autoscaling.k8s.io/v1beta2"
kind: VerticalPodAutoscaler
metadata:
  name: hello-world
  namespace: hello-world
spec:
  targetRef:
    apiVersion: "extensions/v1beta1"
    kind: Deployment
    name: hello-world
  resourcePolicy:
    containerPolicies:
    - minAllowed:
        cpu: 50m
        memory: 75Mi
      mode: auto
      containerName: "*" # Added line
  updatePolicy:
    updateMode: "Auto"

出现以下错误:

Error while fetching legacy selector. Reason: v1beta1 selector not found"

已在 VPA v0.7 中修复。请参阅 this commit 以供参考。