orbatschow
orbatschow

Reputation: 1537

Kubernetes Autoscaling Containers

Is it possible to autoscale docker containers, which contain application servers (like wildfly/tomcat/jetty/) within Kubernetes? For example at CPU and RAM usage or based on http requests? If there is a built-in feature for that I can't find it, or is it possible to write something like a configuration script for this? If so where does the magic happen?

Upvotes: 3

Views: 1238

Answers (4)

Shifali Srivastava
Shifali Srivastava

Reputation: 99

You can autoscale your deployment by using Horizontal Pod Autoscaler.

 kubectl autoscale deployment task2deploy1 –cpu-percent=80 –min=2 –max=6

The command will ensure the deployment has minimum of 2 and maximum of 6 pods with target CPU utilization set to 80%. You can list the autoscalers using:

 kubectl get hpa

NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS
task2deploy1 Deployment/task2deploy1 /80% 2 6 0

 kubectl describe  hpa 

Name: task2deploy1

lots of information would be printed on the screen regarding the autoscaler.

Keep checking for the changes in the number of pods using :

kubectl describe deployment task2deploy1 

Upvotes: 0

Amila Kumaranayaka
Amila Kumaranayaka

Reputation: 61

You can use horizontal pod auto-scaling in kubernetes 1.3 onwards. kubernetes blog provides detailed information on the functionality.

http://blog.kubernetes.io/2016/07/autoscaling-in-kubernetes.html

but the above article mainly focus on GKE. so the below would be more informative.

https://kubernetes.io/docs/user-guide/horizontal-pod-autoscaling/

how to use kubectl for pod autoscaling is described here.

 kubectl autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [flags]

Examples

# Auto scale a deployment "foo", with the number of pods between 2 and 10, target CPU utilization specified so a default autoscaling policy will be used:
  kubectl autoscale deployment foo --min=2 --max=10

  # Auto scale a replication controller "foo", with the number of pods between 1 and 5, target CPU utilization at 80%:
  kubectl autoscale rc foo --max=5 --cpu-percent=80

Upvotes: 2

pagid
pagid

Reputation: 13867

Since Kubernetes 1.2 autoscaling is part of the stable API. It's done based on CPU usage or based on metrics provided from the container itself.

It can be used for deployments or replication controllers like this:

# Auto scale a deployment "foo", with the number of pods between 2 and 10, target CPU utilization specified so a default autoscaling policy will be used:
kubectl autoscale deployment foo --min=2 --max=10

# Auto scale a replication controller "foo", with the number of pods between 1 and 5, target CPU utilization at 80%:
kubectl autoscale rc foo --max=5 --cpu-percent=80

Further details can be found in the official documentation within the Horizontal scaling description, in the kubectl autoscale documentation and within the official blog.

Upvotes: 1

Robert Bailey
Robert Bailey

Reputation: 18200

Autoscaling of containers is not yet supported and is not part of the near term 1.0 roadmap for Kubernetes (meaning that the core team isn't going to add it soon but external contributions are certainly welcome).

Upvotes: 4

Related Questions