title: kubernetes HPA - Unauthorized has prevented the request from succeeding
body: <p>I am trying to deploy HPA for my application but I have been getting the Unauthorized error</p>
  <pre><code>kubectl desribe hpa homekitchen:
  </code></pre>
  <pre><code>Events:
    Type     Reason                   Age                   From                       Message
    ----     ------                   ----                  ----                       -------
    Warning  FailedGetResourceMetric  13s (x488 over 130m)  horizontal-pod-autoscaler  unable to get metrics for resource memory: unable to fetch metrics from resource metrics API: an error on the server (&quot;Internal Server Error: \&quot;/apis/metrics.k8s.io/v1beta1/namespaces/default/pods?labelSelector=app%3Dhomekitchen\&quot;: Unauthorized&quot;) has prevented the request from succeeding (get pods.metrics.k8s.io)
  </code></pre>
  <p>kubectl get hpa:</p>
  <pre><code>NAME          REFERENCE                TARGETS                        MINPODS   MAXPODS   REPLICAS   AGE
  homekitchen   Deployment/homekitchen   &lt;unknown&gt;/75%, &lt;unknown&gt;/85%   2         3         2          169m
  </code></pre>
  <p>My HPA config:</p>
  <pre><code>---
  apiVersion: autoscaling/v2beta2
  kind: HorizontalPodAutoscaler
  metadata:
    name: homekitchen
    namespace: default
  spec:
    scaleTargetRef:
      apiVersion: apps/v1
      kind: Deployment
      name: homekitchen
    minReplicas: 2
    maxReplicas: 4
    behavior:
      scaleUp:
        policies:
          - type: Pods
            value: 1
            periodSeconds: 70
      scaleDown:
        policies:
          - type: Percent
            value: 10
            periodSeconds: 70
    metrics:
      - type: Resource
        resource:
          name: cpu
          target:
            type: Utilization
            averageUtilization: 85
      - type: Resource
        resource:
          name: memory
          target:
            type: Utilization
            averageUtilization: 75
  </code></pre>
  <p>In the deployment config file, I have added the following</p>
  <pre><code> resources:
            requests:
              memory: 500Mi
              cpu: 500m
            limits:
              memory: 1500Mi
              cpu: 1500m
  
  </code></pre>
  <p>And my metrics server (namespace = kube-system) logs show following error:</p>
  <pre><code>I0717 11:49:36.396129       1 server.go:188] &quot;Failed probe&quot; probe=&quot;metric-storage-ready&quot; err=&quot;not metrics to serve&quot;
  I0717 11:49:46.396613       1 server.go:188] &quot;Failed probe&quot; probe=&quot;metric-storage-ready&quot; err=&quot;not metrics to serve&quot;
  E0717 11:49:49.529809       1 scraper.go:139] &quot;Failed to scrape node&quot; err=&quot;GET \&quot;https://**.**.**.**:**/stats/summary?only_cpu_and_memory=true\&quot;: bad status code \&quot;403 Forbidden\&quot;&quot; node=&quot;gke-******&quot;
  E0717 11:49:49.529921       1 scraper.go:139] &quot;Failed to scrape node&quot; err=&quot;GET \&quot;https://**.**.**.**:***/stats/summary?only_cpu_and_memory=true\&quot;: bad status code \&quot;403 Forbidden\&quot;&quot; node=&quot;gke-*****&quot;
  </code></pre>
  <p>ClusterRole for metrics server:</p>
  <pre><code>Name:         system:metrics-server
  Labels:       addonmanager.kubernetes.io/mode=Reconcile
                kubernetes.io/cluster-service=true
  Annotations:  &lt;none&gt;
  PolicyRule:
    Resources         Non-Resource URLs  Resource Names  Verbs
    ---------         -----------------  --------------  -----
    deployments.apps  []                 []              [get list update watch]
    namespaces        []                 []              [get list watch]
    nodes             []                 []              [get list watch]
    pods              []                 []              [get list watch]
                      [/metrics]         []              [get]
  </code></pre>
  <p>With my limited knowledge, I am unable to figure out why it's getting unauthorized errors.</p>
  <p>Please help me out guys</p>
  <p>Thanks in advance</p>