Launch an application on Code Engine using IBM Cloud Shell

Premise

In "Launching an application with Code Engine using IBM Cloud CLI" I wrote the other day, I used the IBM Cloud CLI installed on my PC. For now, let's use the IBM Cloud Shell to launch a container on the IBM Cloud Code Engine. The major difference is that there is no operation to log in to IBM Cloud from the IBM Cloud CLI, and you need to specify "us-south" as the location of the IBM Cloud Shell.

IBM Cloud Shell

What is IBM Cloud Shell?

It is an environment where you can run the bash shell on your web browser. It can be used on IBM Cloud. According to the official online manual "FAQ about IBM Cloud Shell", the shell execution environment is There is Ubuntu Linux.

As of October 2020, the version of Ubuntu used in IBM Cloud Shell is 18.04.5 LTS (Bionic Beaver). To check, try running the following command in the IBM Cloud Shell.

$ cat /etc/os-release

How to access IBM Cloud Shell

After logging in to IBM Cloud with a web browser such as Chrome, click the "IBM Cloud Shell" icon at the top right of the screen. image.png

Location change

As of October 2020, the "IBM Cloud Code Engine" used here is only "Dallas" as the location of IBM Cloud, so change the location of IBM Cloud Shell to "us-south".

Click Change at the top of the IBM Cloud Shell screen. image.png

The message "Change Cloud Shell location" will be displayed. Change the location to "Dallas (us-south)" and click "Continue". image.png

At the top of the IBM Cloud Shell screen, the location changes to Dallas. image.png

Check for Code Engine plugin

Check if you can call the command for Code-Engine in IBM Cloud Shell.

$ ibmcloud plugin show code-engine

It is OK if it is displayed as shown in the figure below. You can see that IBM Cloud Shell can use the beta version of IBM Cloud Code Engine as of October 2020. image.png

Use containers serverless with IBM Cloud Code Engine

Specify resource group

See the official Online Manual (https://cloud.ibm.com/docs/cli?topic=cli-ibmcloud_commands_resource&locale=en) for a description of the resource group itself. If you do not specify a resource group, IBM Cloud Code Engine cannot create a "project" that organizes applications and jobs.

Run the following command to view the existing resource groups.

$ ibmcloud resource groups

Example result

Name ID Default group state
default   xxxxxxxxxxxxxxxxx   true                ACTIVE

Here, target the resource group whose name is "default".

$ ibmcloud target -g default

Project creation

In IBM Cloud Code Engine, a device for running applications and jobs is called a "project" and must be prepared. Run the following command: The name of the project to be created is 2ndproject. You can use alphanumeric characters for the project name, so you can use any name you like.

$ ibmcloud ce project create --name 2ndproject

You can check the existing project that has been created by executing the following command.

$ ibmcloud ce project list

Example of execution result

Name        ID                                    Status  Tags  Location  Resource Group  Time to deletion  
2ndproject  ab70ec5f-3fb4-4272-88c6-78dc63024173  active        us-south  default         7 days from now

As of October 2020, IBM Cloud Code Engine is in beta, so you will be notified that it will be automatically removed after 7 days.

Project designation

To create the application, run the following command to specify the project. Here, the created 2nd project is specified. Actually, the 2nd project is the place to specify the project name, so replace it with the project name you created and execute the command.

$ ibmcloud ce project select -n 2ndproject

Example of execution result

Selecting project '2ndproject'...
OK

Creating an application

Call the Nginx Docker image published on DockerHub and create it as an application on the IBM Cloud Code Engine. Run the following command:

$ ibmcloud ce application create --name nodered --image nodered/node-red --cpu 1 --memory 512Mi

Here, 1 CPU and 512 MB of memory are allocated to the Node-RED container. Example of execution result

Project '2ndproject' and all its contents will be automatically deleted 7 days from now.
Creating application 'nodered'...
The Configuration is still working to reflect the latest desired specification.
The Route is still working to reflect the latest desired specification.
Configuration 'nodered' is waiting for a Revision to become ready.
Configuration 'nodered' is waiting for a Revision to become ready.
Ingress has not yet been reconciled.
Waiting for load balancer to be ready
Run 'ibmcloud ce application get -n nodered' to check the application status.
OK

https://nodered.ab70ec5f-3fb4.us-south.codeengine.appdomain.cloud

You can access the created application by accessing the above URL. nodered is the application name specified in ibmcloud ce application create, and ab70ec5f-3fb4 is part of the ID of the project to which the application belongs, so it is different for each person. As of October 2020, IBM Cloud Code Engine is in beta, so it is indicated that it will be automatically deleted in 7 days.

Check application status

$ ibmcloud ce application get -n nodered

The above nodered will be the application name specified in ibmcloud ce application create. If the application name is different, replace it with the application name you used and execute the command.

Example of execution result

Name:          nodered  
ID:            ed33006e-da81-4030-b7d6-98d7265da9ab  
Project Name:  2ndproject  
Project ID:    ab70ec5f-3fb4-4272-88c6-78dc63024173  
Age:           5m9s  
Created:       2020-10-06 13:12:37 +0000 UTC  
URL:           https://nodered.ab70ec5f-3fb4.us-south.codeengine.appdomain.cloud  
Console URL:   https://cloud.ibm.com/codeengine/project/us-south/ab70ec5f-3fb4-4272-88c6-78dc63024173/application/nodered/configuration  

Image:  nodered/node-red  
Resource Allocation:  
  CPU:     1  
  Memory:  512Mi  

Revisions:  
  nodered-arbhb-1:  
    Age:                5m8s  
    Traffic:            100%  
    Image:              nodered/node-red (pinned to 7903d6)  
    Running Instances:  0  

Runtime:  
  Concurrency:         10  
  Concurrency Target:  10  
  Maximum Scale:       10  
  Minimum Scale:       0  
  Timeout:             300  

Conditions:  
  Type                 OK    Age    Reason  
  ConfigurationsReady  true  4m39s    
  Ready                true  4m32s    
  RoutesReady          true  4m32s  

Of the items displayed as execution results, accessing "URL" will display the application, and accessing "Console URL" will allow you to check the settings of the application created on the Web browser.

Example of accessing "Console URL" image.png

Access from a web browser

Check if the application is running by accessing the URL displayed when creating the application or checking the status of the application. Since Node-RED was specified here, Node-RED is displayed. image.png

As you can see, Node-RED is in the initial state.

Practical usage

Since you can start a container as serverless, the instance (starting container) will be automatically deleted if there is no access, and the number of instances will increase as the access increases. Even if you start Node-RED as described above, the number of instances will increase or decrease automatically, so even if you start Node-RED on the IBM Cloud Code Engine and set the flow, it will immediately return to the initial state. ..

Therefore, it can be said that it is a practical usage to create a flow that you want to run with Node-RED on your PC, create a container image, and run the created container image with IBM Cloud Code Engine.

Other

You can check the log of the application running in the container by operating in the same way as in the case of IBM Cloud CLI.

Recommended Posts

Launch an application on Code Engine using IBM Cloud Shell
Try Quarkus on IBM Cloud Shell
Deploy a Node.js application to an ECS instance using the Cloud Toolkit
How to publish an application on Heroku
Send an email using JavaMail on AWS