Search…
Managing Service Resources
Working with defaults and overrides for resources
Your default or environment specific configuration always include a default resources section. This stanza consists of resource default s for:
  • cpu : limits and resources (required)
  • memory : limits and resources (required)
  • replicas (required)
  • storage : type and size
These values are directly related to Kubernetes definitions of resources. You can read more about resources here.
1
resources:
2
cpu:
3
limits: 2000m
4
requests: 100m
5
memory:
6
limits: 16Gi
7
requests: 100Mi
8
replicas: 1
9
storage:
10
size: 9Gi
11
type: aws-efs
Copied!
Exampe of default resources stanza

Overriding Resources

You can override services in two different sections of your Default Environment Configuration: in the services section and/or in a particular environment template.
1
resources:
2
cpu:
3
limits: 1000m
4
requests: 100m
5
memory:
6
limits: 2Gi
7
requests: 100Mi
8
replicas: 1
Copied!
Defaults for this example
In this example we will want to do three things:
  • Add extra memory for our frontend service for all environments
  • Have two backend replicas for all environments
  • In our production environment we want 5 backend replicas and 10 frontend replicas

Add extra memory for our frontend service in all environments

1
services:
2
- name: frontend
3
image: releaseapp/spacedust/frontend
4
command:
5
- "./start.sh"
6
registry: local
7
ports:
8
- type: node_port
9
target_port: '4000'
10
port: '4000'
11
memory:
12
limits: 4Gi
13
requests: 500Mi
14
static: true
15
build_command: GENERATE_SOURCEMAP=false yarn build
16
build_base: frontend
17
build_output_directory: build/
Copied!
Memory limits to 4Gi and requests to 500Mi
Now every environment will have 4Gi memory limit and a 500Mi request for each frontend instance, while every other service instance will have a 2Gi memory limit and 100Mi request value.

Always deploy 2 backend replicas as default

In order to make sure we always have 2 backend replicas no matter which kind of environment we are deploying, we will need to override the replicas for the backend service in our default environment config.
1
services
2
- name: backend
3
image: releaseapp/spacedust/backend
4
command:
5
- "./run-spacedust.sh"
6
registry: local
7
depends_on:
8
- postgres
9
- redis
10
ports:
11
- type: node_port
12
target_port: '3000'
13
port: '3000'
14
replicas: 2
Copied!
Always deploy 2 instances of the backend service
Once we override replicas under the service definition for backend, every environment we deploy based on our default environment configuration will always deploy two instances of the backend service, while only deploying one instance of each other service.

Make sure production always has 5 backend and 10 frontend instances

So, now we have our default overrides the way we want we need to modify production because it serves a lot more traffic then any ephemeral or staging environment. In order to do this we need to create our 'production' space, then modify the environment specific configuration.
1
services:
2
- name: frontend
3
image: releaseapp/spacedust/frontend
4
command:
5
- "./start.sh"
6
registry: local
7
ports:
8
- type: node_port
9
target_port: '4000'
10
port: '4000'
11
replicas: 10
12
memory:
13
limits: 4Gi
14
requests: 500Mi
15
static: true
16
build_command: GENERATE_SOURCEMAP=false yarn build
17
build_base: frontend
18
build_output_directory: build/
19
- name: backend
20
image: releaseapp/spacedust/backend
21
command:
22
- "./run-spacedust.sh"
23
registry: local
24
depends_on:
25
- postgres
26
- redis
27
ports:
28
- type: node_port
29
target_port: '3000'
30
port: '3000'
31
replicas: 5
Copied!
Set replicas for fronted and backend to 10 and 5 respectively
Once the replicas are overridden for the environment specific configuration you can then deploy that configuration and your 'production' environment will have the 5 backend instances and 10 frontend instances running in the cluster. All of the rest of your environments will not be affected by these changes, because they are specific to your 'production' environment.
Last modified 7mo ago