Kubernetes: How to apply Horizontal Pod (HPA) autoscaling for a RC which contains multiple containers?

923 views Asked by At

I have tried using HPA for a RC which contains only one container and it works perfectly fine. But when I have a RC with multiple containers (i.e., a pod containing multiple containers), the HPA is unable to scrape the CPU utilization and shows the status as "Unknown", shown below. How can I successfully implement a HPA for a RC with multiple containers. The Kuberentes docs have no information regarding this and also I didnt find any mention of it not being possible. Can anyone please share their experience or a point of view, with regard to this issue. Thanks a lot.

prometheus-watch-ssltargets-hpa   ReplicationController/prometheus   <unknown> / 70%   1         10        0          4s 

Also for your reference, below is my HPA yaml file.

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: prometheus-watch-ssltargets-hpa
  namespace: monitoring
spec:
  scaleTargetRef:
    apiVersion: v1
    kind: ReplicationController
    name: prometheus
  minReplicas: 1
  maxReplicas: 5
  targetCPUUtilizationPercentage: 70 
1

There are 1 answers

1
Suhas Chikkanna On BEST ANSWER

By all means it is possible to set a HPA for an RC/Deployment/Replica-set with multiple containers. In my case the problem was the format of resource limit request. I figured out from this link, that if the pod's containers do not have the relevant resource request set, CPU utilization for the pod will not be defined and the HPA will not take any action for that metric. In my case I was using the resource request as below, which caused the error(But please note that the following resource request format works absolutely fine when I use it with deployments, replication controllers etc. It is only when, in addition I wanted to implement HPA that caused the problem mentioned in the question.)

    resources:
      limits:
        cpu: 2
        memory: 200M
      requests:
        cpu: 1
        memory: 100Mi

But after changing it like below(i.e., with a relevant resource request set that HPA can understand), it works fine.

    resources:
      limits:
        cpu: 2
        memory: 200Mi
      requests:
        cpu: 1
        memory: 100Mi