Multi-Tiered Deployment

Deploy a Multi-Tiered Application

In this guide, we will deploy a multi-tier web application on Akash. The example application will consist of two services: a front-end web service and a back-end database.

Before We Begin

This guide is to be considered an extension of the Deploy an Application guide. Please ensure you have successfully completed all steps leading up to the "Create the Deployment Configuration" step in said guide, as they will not be discussed here.

Create the Deployment Configuration

Let's create a deployment configuration that specifies multiple services in a single deployment.
1
---
2
version: "2.0"
3
4
services:
5
redis:
6
image: bitnami/redis:6.2
7
env:
8
- REDIS_AOF_ENABLED=no
9
- ALLOW_EMPTY_PASSWORD=yes
10
expose:
11
- port: 6379
12
to:
13
- service: goosebin
14
goosebin:
15
image: hydrogen18/goosebin:latest
16
env:
17
- REDIS_HOST=redis
18
- REDIS_PORT=6379
19
- PASTE_SIZE_LIMIT=100000
20
- HTTP_PORT=8000
21
depends_on:
22
- redis
23
expose:
24
- port: 8000
25
as: 80
26
to:
27
- global: true
28
29
profiles:
30
compute:
31
redis:
32
resources:
33
cpu:
34
units: 1
35
memory:
36
size: 128Mi
37
storage:
38
size: 16Mi
39
goosebin:
40
resources:
41
cpu:
42
units: 1
43
memory:
44
size: 64Mi
45
storage:
46
size: 16Mi
47
placement:
48
dc1:
49
pricing:
50
redis:
51
denom: uakt
52
amount: 9999
53
goosebin:
54
denom: uakt
55
amount: 9999
56
57
deployment:
58
redis:
59
dc1:
60
profile: redis
61
count: 1
62
goosebin:
63
dc1:
64
profile: goosebin
65
count: 1
Copied!
Let's break down the above SDL into its 3 primary categories: services, profiles, and deployment.

Services

1
services:
2
redis:
3
image: bitnami/redis:6.2
4
env:
5
- REDIS_AOF_ENABLED=no
6
- ALLOW_EMPTY_PASSWORD=yes
7
expose:
8
- port: 6379
9
to:
10
- service: goosebin
11
goosebin:
12
image: hydrogen18/goosebin:latest
13
env:
14
- REDIS_HOST=redis
15
- REDIS_PORT=6379
16
- PASTE_SIZE_LIMIT=100000
17
- HTTP_PORT=8000
18
depends_on:
19
- redis
20
expose:
21
- port: 8000
22
as: 80
23
to:
24
- global: true
Copied!
The services entries contain maps of workloads to be run on the Akash deployment. This deployment has 2 service entries: redis and goosebin - the former being our backend and the latter being our frontend. Please note that while these service names are arbitrary, their usage must remain consistent across the whole .yml file.
We can see that goosebin is globally exposed and open to the public, while redis is internal to the deployment and is only shared with goosebin.
Within the goosebin entry, we set some environmental variables - these are declared internally within the goosebin image. Note that each application can choose whatever environment variables it wants to use on its own for configuration. The variable that ties our services together is REDIS_HOST. This is what goosebin looks at to determine which host to connect to for redis. In this case, we set REDIS_HOST=redis because we chose to name the service redis - had we named the service database, we would have set REDIS_HOST=database.
The expose section is similar to other HTTP examples - internally, the container for this example is listing on port 8000. The deployment will only be assigned a unique URI that can be visited in a web browser when expose has global: true and the port is set to 80.

Profiles

1
profiles:
2
compute:
3
redis:
4
resources:
5
cpu:
6
units: 1
7
memory:
8
size: 128Mi
9
storage:
10
size: 16Mi
11
goosebin:
12
resources:
13
cpu:
14
units: 1
15
memory:
16
size: 64Mi
17
storage:
18
size: 16Mi
19
placement:
20
dc1:
21
pricing:
22
redis:
23
denom: uakt
24
amount: 100
25
goosebin:
26
denom: uakt
27
amount: 100
Copied!
The profiles entries contain named compute and placement profiles to be used in the deployment.
Since we have 2 services to deploy, details for each of them must be specified here. This section is very similar to a standard deployment, so it won't be covered in detail here. An important item to note, however, is that the named compute/placement profiles here (redis and goosebin) must match the names we had specified in the services section. Additional mappings can also be specified within profiles such as audited attributes and data center attributes.

Deployments

1
deployment:
2
redis:
3
dc1:
4
profile: redis
5
count: 1
6
goosebin:
7
dc1:
8
profile: goosebin
9
count: 1
Copied!
The deployment entries map the datacenter profiles to compute profiles to create a final desired configuration for the resources required for the services.
Similar to the profiles entries, we must specify deployment criteria for both of our services. This says that the 1 instance of the redis service and 1 instance of the goosebin service should be deployed to a datacenter matching the dc1 datacenter profile. Each instance of the services will have the resources defined in its corresponding compute profile (redis or goosebin) available to it.

Deployment

Now that we have the SDL configured, let's deploy this application and see what happens. A more detailed guide on this process can be found in the Deploy an Application guide.
Create the Deployment
Create the deployment by running:
1
akash tx deployment create goosebin.yml --from $AKASH_KEY_NAME --node $AKASH_NODE --chain-id $AKASH_CHAIN_ID --fees 5000uakt -y
Copied!
Once a provider is chosen, a lease is created, and the manifest is uploaded, we can view the status of our deployment by running:
1
akash provider lease-status --node $AKASH_NODE --home ~/.akash --dseq $AKASH_DSEQ --from $AKSH_KEY_NAME --provider $AKASH_PROVIDER
Copied!
You should see a response similar to:
1
{
2
"services": {
3
"goosebin": {
4
"name": "goosebin",
5
"available": 1,
6
"total": 1,
7
"uris": [
8
"p3n56m0h7dant3iphkau8tdeds.ingress.sjc1p0.mainnet.akashian.io"
9
],
10
"observed_generation": 1,
11
"replicas": 1,
12
"updated_replicas": 1,
13
"ready_replicas": 1,
14
"available_replicas": 1
15
},
16
"redis": {
17
"name": "redis",
18
"available": 1,
19
"total": 1,
20
"uris": null,
21
"observed_generation": 1,
22
"replicas": 1,
23
"updated_replicas": 1,
24
"ready_replicas": 1,
25
"available_replicas": 1
26
}
27
},
28
"forwarded_ports": {}
29
}
Copied!
The URI shown above will take you to the front-end service. We can verify the service is running and talking with the backend (redis) by running the following:
1
akash provider lease-logs --node $AKASH_NODE --home $AKASH_HOME --from $AKSH_KEY_NAME --dseq $AKASH_DSEQ --provider $AKASH_PROVIDER
Copied!
You should see a response similar to:
1
[goosebin-5cf5678d5b-rfdqv] Starting HTTP server on "0.0.0.0:8000"
2
[goosebin-5cf5678d5b-rfdqv] GET / rendered "home"
3
[goosebin-5cf5678d5b-rfdqv] GET /create-paste rendered "newPaste"
4
[goosebin-5cf5678d5b-rfdqv] POST /create-paste rendered "createPaste"
5
[goosebin-5cf5678d5b-rfdqv] GET /paste/HD-i5mNSyiQn0Kop8y8IvQ rendered "showPaste"
6
[goosebin-5cf5678d5b-rfdqv] GET /create-paste rendered "newPaste"
7
[goosebin-5cf5678d5b-rfdqv] GET / rendered "home"
8
[goosebin-5cf5678d5b-rfdqv] GET / rendered "home"
9
[goosebin-5cf5678d5b-rfdqv] POST /create-paste rendered "createPaste"
10
[redis-8569665588-zh6pr] redis 19:38:14.11
11
[redis-8569665588-zh6pr] redis 19:38:14.17 Welcome to the Bitnami redis container
12
[redis-8569665588-zh6pr] redis 19:38:14.18 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-redis
13
[redis-8569665588-zh6pr] redis 19:38:14.19 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-redis/issues
14
[redis-8569665588-zh6pr] redis 19:38:14.20
15
[redis-8569665588-zh6pr] redis 19:38:14.21 INFO ==> ** Starting Redis setup **
16
[redis-8569665588-zh6pr] redis 19:38:14.27 WARN ==> You set the environment variable ALLOW_EMPTY_PASSWORD=yes. For safety reasons, do not use this flag in a production environment.
17
[redis-8569665588-zh6pr] redis 19:38:14.29 INFO ==> Initializing Redis
18
[redis-8569665588-zh6pr] redis 19:38:14.42 INFO ==> Setting Redis config file
19
[redis-8569665588-zh6pr] redis 19:38:14.59 INFO ==> ** Redis setup finished! **
20
[redis-8569665588-zh6pr]
21
[redis-8569665588-zh6pr] redis 19:38:14.62 INFO ==> ** Starting Redis **
22
[redis-8569665588-zh6pr] 1:C 06 Apr 2021 19:38:14.689 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23
[redis-8569665588-zh6pr] 1:C 06 Apr 2021 19:38:14.689 # Redis version=6.2.1, bits=64, commit=00000000, modified=0, pid=1, just started
24
[redis-8569665588-zh6pr] 1:C 06 Apr 2021 19:38:14.689 # Configuration loaded
25
[redis-8569665588-zh6pr] 1:M 06 Apr 2021 19:38:14.690 * monotonic clock: POSIX clock_gettime
26
[redis-8569665588-zh6pr] 1:M 06 Apr 2021 19:38:14.691 * Running mode=standalone, port=6379.
Copied!
We can see the goosebin frontend has made some requests to the redis backend, and the containers are healthy.
Last modified 5mo ago