Web Apps
Note: The functionalities provided through the
Webapp
feature are deprecated and will eventually be removed. We recommend using theService
feature which offers a more comprehensive and flexible solution for managing web applications and API deployments.
Note: Only generic (EKS-based) Web Apps are supported with CLI.
Providing Instance Type in Web App
When creating a web-app, we can set the instance type by including it under the resources
key in the following YAML format:
resources:
instanceTypeId: 1
To obtain a list of all available instances along with their corresponding instanceTypeId
, we can use the following command:
peak tenants list-instance-options --entity-type webapp
Session Stickiness in Web App
By default, session stickiness is disabled (false
). You can activate session stickiness by setting the sessionStickiness
parameter to true
.
Session stickiness ensures that each user’s requests are consistently directed to a particular server. This feature is especially valuable for stateful applications like web applications that rely on server-stored session data.
Note that employing session stickiness may lead to unpredictable behavior and is not recommended if you plan to scale your application.
Scale To Zero in Web App
By default, this option is disabled (false
). You can activate it by setting the scaleToZero
parameter to true
.
Setting Scale to zero ensures that the resources hosting your app are scaled down when idle over a period of time. The resources will scale back up automatically on next launch.
This option is not available for shiny
web app types and also does not work if sessionStickiness
is set to true
.
Creating a Web App
We can create a web-app by providing payload like following.
# webapp.yaml
body:
name: my-webapp
title: New webapp
description: This is a new webapp
imageDetails:
imageId: 100
versionId: 100
resources:
instanceTypeId: 1
sessionStickiness: true
scaleToZero: false
We can use the following command to create a web-app:
peak webapps create path/to/create_webapp.yaml -v path/to/webapp_params.yaml
Alternatively, we can also use the create command without having the need to provide a yaml
.
This is possible using the command line options or optionally combining them with yaml template, with the command line options taking precedence.
peak webapps create --name my-webapp --description some-description --title my-title --image-id <image-id> --version-id <version-id> --instance-type-id 43 --scale-to-zero --no-session-stickiness
Above command will generate the following json
body:
{
"name": "my-webapp",
"title": "my-title",
"description": "some-description",
"imageDetails": {
"imageId": "<image-id>",
"versionId": "<version-id>"
},
"resources": {
"instanceTypeId": 43
},
"scaleToZero": true,
"sessionStickiness": false
}
Updating a Web App
When updating the web-app, it will trigger a redeployment only under specific conditions. Redeployment is triggered if you make changes to any of the following parameters: imageId
, versionId
, instanceTypeId
, scaleToZero
or sessionStickiness
. However, only modifying the title
or description
will not trigger a redeployment.
We can update the web-app by providing web-app id and payload like following.
# webapp.yaml
body:
title: Updated webapp
description: This is an updated webapp
imageDetails:
imageId: 200
versionId: 200
resources:
instanceTypeId: 1
sessionStickiness: true
scaleToZero: false
We can use the following command to update a web-app:
peak webapps update -v path/to/webapp_params.yaml <webapp-id> path/to/update_webapp.yaml
Alternatively, we can also use the update command without having the need to provide a yaml
.
This is possible using the command line options or optionally combining them with yaml template, with the command line options taking precedence.
peak webapps update <webapp-id> --description some-description --title my-title --image-id <image-id> --version-id <version-id> --instance-type-id 43 --scale-to-zero --no-session-stickiness
Above command will generate the following json
body:
{
"title": "my-title",
"description": "some-description",
"imageDetails": {
"imageId": "<image-id>",
"versionId": "<version-id>"
},
"resources": {
"instanceTypeId": 43
},
"scaleToZero": true,
"sessionStickiness": false
}
Using the create-or-update
operation
The operation creates a new resource if it doesn’t exist and updates the resource in case it exists. The search is based on resource name
field.
If the web-app is being updated, it will trigger a redeployment only under specific conditions. Redeployment is triggered if you make changes to any of the following parameters: imageId
, versionId
, instanceTypeId
, scaleToZero
or sessionStickiness
. However, only modifying the title
or description
will not trigger a redeployment.
Consider the following example for creating a web-app:
# webapp.yaml
body:
title: New webapp
description: This is an new webapp
imageDetails:
imageId: 100
versionId: 100
resources:
instanceTypeId: 1
sessionStickiness: true
scaleToZero: false
peak webapps create-or-update -v path/to/webapp_params.yaml <webapp-id> path/to/create_or_update_webapp.yaml --image-id 3 --name my-webapp
Now we could update the web-app created with above command as follows:
# webapp_params.yaml
imageId: 2
versionId: 2
# webapp.yaml
body:
title: Updated webapp
description: This is an updated webapp
imageDetails:
imageId: {{ imageId }}
versionId: {{ versionId }}
resources:
instanceTypeId: 43
scaleToZero: true
sessionStickiness: false
peak webapps create-or-update -v path/to/webapp_params.yaml <webapp-id> path/to/webapp.yaml --image-id 3 --name my-webapp --instance-type-id 43 --scale-to-zero --no-session-stickiness
In the above example, the imageId
will be overwritten by the command line options and the final web-app body will look like:
{
"title": "Updated webapp",
"description": "This is an updated webapp",
"imageDetails": {
"imageId": 3,
"versionId": 2
},
"resources": {
"instanceTypeId": 43
},
"scaleToZero": true,
"sessionStickiness": false
}