Kubernetes VPA:与targetref选择器+最小资源有关的问题

问题描述 投票:0回答:1

我有两个问题: - 我的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
  • 我将VPA配置为使用targetref使用新类型的标签选择器,但在推荐日志中它说我正在使用传统的: Error while fetching legacy selector. Reason: v1beta1 selector not found

这是我的部署配置:

---
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

谢谢

kubernetes autoscaling
1个回答
2
投票

我认为你没有使用旧的抓取器。

这是一个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控制autoscaler如何计算属于pod的容器的推荐资源。每个命名容器最多只能有一个条目,并且可选择使用containerName ='*'的单个通配符条目,它可以处理所有没有单独策略的容器。

我想,您还应该在规范中设置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"
© www.soinside.com 2019 - 2024. All rights reserved.