From aebeeb170e46f5dc6f76d075b6ce1bf5e3cd21a4 Mon Sep 17 00:00:00 2001 From: Corey Wanless Date: Fri, 11 Jan 2019 19:41:32 -0600 Subject: [PATCH] adds pod limits Signed-off-by: Corey Wanless --- installer/inventory | 24 +++++++++---- .../kubernetes/templates/deployment.yml.j2 | 36 +++++++++++++++++++ .../templates/management-pod.yml.j2 | 10 ++++++ 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/installer/inventory b/installer/inventory index 847ba60a2c..90b1530860 100644 --- a/installer/inventory +++ b/installer/inventory @@ -23,14 +23,26 @@ dockerhub_base=ansible # tiller_namespace=kube-system # Kubernetes and Openshift Install Resource Requests -# This is the request value for a pod's "task" container, which is the container -# used to run jobs. The other containers have a fixed resource request. The total amount -# of requested resources for a pod is the sum of all resources requested by all containers -# in the pod -# A cpu_request of 1500 is 1.5 cores for the task container -# A mem_request of 2 is for 2 gigabytes of memory for the task container +# This are the request and limit values for a pod's container for task/web/rabbitmq/memcached/management. +# The total amount of requested resources for a pod is the sum of all +# resources requested by all containers in the pod +# A cpu_request of 1500 is 1.5 cores for the container to start out with. +# A cpu_limit defines the maximum cores that that container can reserve. +# A mem_request of 2 is for 2 gigabytes of memory for the container +# A mem_limit defines the maximum memory that that container can reserve. +# Default values for these entries can be found in ./roles/kubernetes/defaults/main.yml # task_cpu_request=1500 # task_mem_request=2 +# task_cpu_limit=2000 +# task_mem_limit=4 +# web_cpu_limit=1000 +# web_mem_limit=2 +# rabbitmq_cpu_limit=1000 +# rabbitmq_mem_limit=3 +# memcached_cpu_limit=1000 +# memcached_mem_limit=2 +# management_cpu_limit=2000 +# management_mem_limit=2 # Common Docker parameters awx_task_hostname=awx diff --git a/installer/roles/kubernetes/templates/deployment.yml.j2 b/installer/roles/kubernetes/templates/deployment.yml.j2 index 1626f4959f..4dec9f6c76 100644 --- a/installer/roles/kubernetes/templates/deployment.yml.j2 +++ b/installer/roles/kubernetes/templates/deployment.yml.j2 @@ -162,6 +162,15 @@ spec: requests: memory: "{{ web_mem_request }}Gi" cpu: "{{ web_cpu_request }}m" +{% if web_mem_limit is defined or web_cpu_limit is defined %} + limits: +{% endif %} +{% if web_mem_limit is defined %} + memory: "{{ web_mem_limit }}Gi" +{% endif %} +{% if web_cpu_limit is defined %} + cpu: "{{ web_cpu_limit }}m" +{% endif %} - name: {{ kubernetes_deployment_name }}-celery securityContext: privileged: true @@ -208,6 +217,15 @@ spec: requests: memory: "{{ task_mem_request }}Gi" cpu: "{{ task_cpu_request }}m" +{% if task_mem_limit is defined or task_cpu_limit is defined %} + limits: +{% endif %} +{% if task_mem_limit is defined %} + memory: "{{ task_mem_limit }}Gi" +{% endif %} +{% if task_cpu_limit is defined %} + cpu: "{{ task_cpu_limit }}m" +{% endif %} - name: {{ kubernetes_deployment_name }}-rabbit image: "{{ kubernetes_rabbitmq_image }}:{{ kubernetes_rabbitmq_version }}" imagePullPolicy: Always @@ -251,6 +269,15 @@ spec: requests: memory: "{{ rabbitmq_mem_request }}Gi" cpu: "{{ rabbitmq_cpu_request }}m" +{% if rabbitmq_mem_limit is defined or rabbitmq_cpu_limit is defined %} + limits: +{% endif %} +{% if rabbitmq_mem_limit is defined %} + memory: "{{ rabbitmq_mem_limit }}Gi" +{% endif %} +{% if rabbitmq_cpu_limit is defined %} + cpu: "{{ rabbitmq_cpu_limit }}m" +{% endif %} - name: {{ kubernetes_deployment_name }}-memcached image: "{{ kubernetes_memcached_image }}:{{ kubernetes_memcached_version }}" imagePullPolicy: Always @@ -258,6 +285,15 @@ spec: requests: memory: "{{ memcached_mem_request }}Gi" cpu: "{{ memcached_cpu_request }}m" +{% if memcached_mem_limit is defined or memcached_cpu_limit is defined %} + limits: +{% endif %} +{% if memcached_mem_limit is defined %} + memory: "{{ memcached_mem_limit }}Gi" +{% endif %} +{% if memcached_cpu_limit is defined %} + cpu: "{{ memcached_cpu_limit }}m" +{% endif %} volumes: - name: {{ kubernetes_deployment_name }}-application-config configMap: diff --git a/installer/roles/kubernetes/templates/management-pod.yml.j2 b/installer/roles/kubernetes/templates/management-pod.yml.j2 index 618b66a3ae..c7fe44efb9 100644 --- a/installer/roles/kubernetes/templates/management-pod.yml.j2 +++ b/installer/roles/kubernetes/templates/management-pod.yml.j2 @@ -17,6 +17,16 @@ spec: - name: "{{ kubernetes_deployment_name }}-confd" mountPath: "/etc/tower/conf.d/" readOnly: true + resources: +{% if management_mem_limit is defined or management_cpu_limit is defined %} + limits: +{% endif %} +{% if management_mem_limit is defined %} + memory: "{{ management_mem_limit }}Gi" +{% endif %} +{% if management_cpu_limit is defined %} + cpu: "{{ management_cpu_limit }}m" +{% endif %} volumes: - name: {{ kubernetes_deployment_name }}-application-config configMap: