Kubernetes Autoscaling

11/6/2018

I have Kubernetes v1.12.1 installed on my cluster. I downloaded the metrics-server from the following repo: https://github.com/kubernetes-incubator/metrics-server

and then run the following command:

kubectl create -f metrics-server/deploy/1.8+/

and then I tried autoscaling a deployment using:

kubectl autoscale deployment example-app-tier --min 1 --max 3 --cpu-percent 70 --spacename example

but the targets here shows unkown/70%

kubectl get hpa --spacename example
NAMESPACE   NAME               REFERENCE                     TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
example example-app-tier   Deployment/example-app-tier   <unknown>/70%   1         3         1          3h35m

and when I try running the kubectl top nodes or pods I get an error saying:

error: Metrics not available for pod default/pi-ss8j6, age: 282h48m5.334137739s

So I'm looking for any tutorial that helps me step by step enabling autoscaling using metrics-server or Prometheus (and not Heapster as it is deprecated and will not be supported anymore)

Thank you!

-- Mina Gobrial
autoscaling
kubernetes
prometheus

1 Answer

11/6/2018

you need to register your metrics server with API server and make sure they communicate.

https://github.com/kubernetes/kubernetes/issues/59438

If it is done already , you need to check the help for the kubectl top command in your version of k8s , the command may default to use heapster , and you may need to tell it to use the new service instead.

https://github.com/kubernetes/kubernetes/pull/56206

from the help command it looks like it is not yet ported to new metric server and still looking for heapster by default.

C02W84XMHTD5:tmp iahmad$ kubectl top node --help
Display Resource (CPU/Memory/Storage) usage of nodes. 

The top-node command allows you to see the resource consumption of nodes.

Aliases:
node, nodes, no

Examples:
  # Show metrics for all nodes
  kubectl top node

  # Show metrics for a given node
  kubectl top node NODE_NAME

Options:
      --heapster-namespace='kube-system': Namespace Heapster service is located in
      --heapster-port='': Port name in service to use
      --heapster-scheme='http': Scheme (http or https) to connect to Heapster as
      --heapster-service='heapster': Name of Heapster service
  -l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l
key1=value1,key2=value2)

Usage:
  kubectl top node [NAME | -l label] [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).

note: I am using 1.10 , maybe in your version , the options are different

-- Ijaz Ahmad Khan
Source: StackOverflow