简体   繁体   中英

Kubernetes Autoscaling Containers

is it possible to autoscale docker containers, which contain application servers (like wildfly/tomcat/jetty/) within kubernetes ? For example at cpu & ram use or based on http requests ? If there is a build 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 ?

目前尚不支持对容器进行自动扩展,这也不是Kubernetes近期1.0路线图的一部分(这意味着核心团队不会很快添加它,但外部贡献肯定是受欢迎的)。

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

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 .

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM