
Export your application from the sandbox into Red Hat OpenShift Service on AWS
Learn how to take an application you created in the Developer Sandbox for Red Hat OpenShift and move it into another cluster, such as a new instance of the Developer Sandbox or a more permanent solution such as Red Hat OpenShift Service on AWS.
Introduction
When you create an application in the no-cost Developer Sandbox for Red Hat OpenShift, your journey isn't finished. Perhaps you are reaching the end of your 30 days but want to continue working in the Developer Sandbox. While your existing sandbox will be deleted when it expires, you can create a new one after expiration.
Or you're ready to bring your application into your real environment, such as OpenShift in the cloud via Red Hat OpenShift Service on AWS.
Good news! You can export your application from the Developer Sandbox and bring it with you. In this activity, you will export your application and prepare it to be imported into another Red Hat OpenShift cluster. You might also decide to store the resulting files in a Git repository and begin implementing the GitOps pattern of application deployment and maintenance.
What you will do
This activity consists of two major parts. In the first part, you will deploy a sample application with multiple components. This part of the activity is not the focus, but it is necessary so you have something to export. This will not be an in-depth exercise.
The second part of this activity is where the focus lies, exporting the application from the Developer Sandbox.
Here are the steps:
- Create a two-component application.
- Run the application.
- Export from your sandbox.
- Delete the non-application parts.
- Import into another cluster.
What you will learn
When you have finished this activity, you will be able to export your application from Developer Sandbox, prepare it to be imported into another cluster, and perform the import.
How long will this activity take?
You should budget about 30 minutes to complete this activity.
Prerequisites
To complete this activity, you will need the following:
- A Developer Sandbox account.
- The
oc
command-line interface installed on your computer. - A web browser to access your sandbox dashboard.
Programming languages
You don’t need to know any programming languages to complete this task. If you’re interested in viewing the code, the backend is written in Node.js, and the front end is HTML and Bootstrap.
If you need help
If you get stuck, something isn’t working, or you simply have questions, you can easily contact us via email at devsandbox@redhat.com.
Step 0: Log into your sandbox at the command line
If you’re unsure how to do this, you can find instructions here: Access your Developer Sandbox for Red Hat OpenShift from the command line | Red Hat Developer
Step 1: Create a two-component application
Now that you’re logged in, it’s time to create an application that can be exported from your sandbox. To do this, simply run the following command:
oc create -f https://raw.githubusercontent.com/redhat-developer-demos/ocp-demo-load/main/qotd-app-objects.yaml
You will immediately start to see the applications built under the group name QuoteOfTheDay
(Figure 1). This grouping name is important. You’ll use it later when preparing your objects to be imported into another cluster.
Step 2: Run the application
Now that the application is built, it’s time to test it and see it working.
Looking at the two applications in the dashboard, you can see that both applications have an external route
, which is a public URL by which they can be accessed. This is evidenced by the small arrow icons in the upper right corner of each application (Figure 2).
The “qotd-nodejs”
container is the backend portion of our app. This is the REST web API that supplies data to the front end. The URL for that back-end container will be copied and pasted into the front-end web page.
You can get the URL by clicking on the arrow (route) icon, or by running the following command at the command line:
(If using PowerShell):
oc get routes | select-string '^qotd-nodejs'
(If using Bash):
oc get routes | grep qotd-nodejs
Once you have the route, you will need to prefix it with the protocol “https://”, append it with “/quotes/random”,
and save that result. Here’s an example of the route and the finished URL:
qotd-nodejs-dsch-dev.apps.sandbox-m3.1530.p1.openshiftapps.com
https://qotd-nodejs-dsch-dev.apps.sandbox-m3.1530.p1.openshiftapps.com/quotes/random
Open the front end application by clicking on its route icon. You’ll be presented with a screen similar to Figure 3:
Click on the prompt at the top to reveal the Settings page, where you will paste in your URL:
Click the Save button and return to the home page. You will now be able to retrieve random quotes.
Step 3: Export from your sandbox
Returning to the OpenShift dashboard, make note of the application name. This is what we wish to export from our sandbox and import into another cluster. It’s the title below the block that contains the containers we created. In this case, it is “QuoteOfTheDay”
(Figure 5).
In the upper right corner of the dashboard, you will notice a button labeled Export application
(Figure 6). Click that button.
You will be asked to verify that you wish to export the application (Figure 7).
Note: Exporting an application will not remove it from your sandbox. It simply provides a copy of all of the objects in the form of YAML files.
Click the OK
button to export your application.
You will immediately be notified that the export process has begun (Figure 8). The OpenShift gitops-primer
operator will start then create a YAML file for each object in your cluster.
After a few minutes, you will be notified that the export process has finished (Figure 9).
Click on the Download link and save the *.zip file on your local machine. When this step is finished, unzip the file.
Now, move to the command line and navigate to the directory where the un-zipped files are located. You will find several files. In my particular case, I have 99 files listed.
This is where it gets interesting.
Step 4: Delete the non-application parts
When you exported, ran, and created the YAML files, it selected every object in the cluster. This is much more than we need. We only need the objects related to the QuoteOfTheDay
application. The way to determine which objects are part of the QuoteOfTheDay
application is to look for the label “app.kubernetes.io/part-of: QuoteOfTheDay”
in the YAML. Every file that contains that string is part of the application, and every file that does not contain that string needs to be deleted.
This can be accomplished by one command in a terminal session. Navigate to the directory containing the downloaded files and run the following command:
(If using PowerShell)
Remove-Item (gci | Where-Object { !( $_ | Select-String "app.kubernetes.io/part-of: QuoteOfTheDay" -quiet) })
(If using Bash)
grep -L "app.kubernetes.io/part-of: QuoteOfTheDay" * | xargs rm
You’ll be left with a directory of YAML files that reflect only the application.
Step 5: Import into another cluster
At this point, the application can be imported into another OpenShift cluster. Log into a cluster and run the following command at the directory where your YAML files reside:
oc apply -f .
Move it, remove it, improve it
Move
Moving your application is what this activity is all about. To complete the cycle, use Red Hat OpenShift Service on AWS (ROSA) to get a complete, production-ready cluster. Note: ROSA is not a free offering. It is a production environment.
Remove
Want to undo the application? Simply run this command:
oc delete -f .
Improve
Put the resulting files in a Git repository and adopt the GitOps Pattern.