An exercise in deploying a prebuilt Docker image to Openshift 4, using its web console.
- Introduce Openshift's web console
- Deploy an app from a prebuilt Docker image
- Check status and logs in the web console
- Set an environment variable in a deployment configuration
- Learn basic troubleshooting of a failed deployment
Briefly review the source for the NodeJS app we are deploying at:
https://github.com/svejk-ciber/nodejs-helloworld
(you dont need to clone the repo).
Notice how the Github Actions pipeline builds and publishes a Docker image from the NodeJS source.
- Open Openshift's web console in your web browser (open the
Console
tab in Katacoda playground). - Log in with the developer user
- CRC (this includes Katacoda): Switch the view to the
Developer
mode. Otherwise you risk running commands as the cluster-admin user. - Create a project with a name of for example
hello
.
- In the new project, choose the
Topology
view from the left menu - Create an app from an image:
- Choose
Container Image
- Enter
svejkciber/nodejs-helloworld:00ce99e2badb634a700862bc97963a8d28032f46
asImage Name
- Enter a name and application name, e,g.
hello
. - Ignore the warning about
Image runs as root
. More on how to fix this issue in a later lab... - Hit
Create
. - Inspect the resource created in Openshift: Left-click on the node in the topology. From there, you should see the following
resources:
- A DeploymentConfig
- A Service
- A Route
- A ReplicationController: it seems that you have to use
Advanced | Search
to find it. - A Pod
- No Builds or BuildConfigs, since this is a pure dpeloyment.
The deployed pod fails to start up.
-
Select the failing pod from the deployment config view and inspect its log. Choose the tab
Logs
It should show an error like:/usr/src/app/app.js:6 throw "WORLD_STATE is not set in the process environment."; ^ WORLD_STATE is not set in the process environment. (Use `node --trace-uncaught ...` to show where the exception was thrown)
-
Fix the error and redeploy
- Go back to the deployment configuration and set the missing environment variable
- Choose the tab
Environment
- Add the environment variable as a
Single Value
. The name of the variable must match the above error message, the value can be any string. - Save the configuration change with the button on the bottom of the page.
- Go back to the deployment configuration and observe that an automatic redeploy started (and probably finished).
- Verify by checking that
- a new replication controller was created recently
- a new pod was started successfully
- Check that there are no errors in the application log. The application log should now show:
Server running at http://0.0.0.0:3000/
- Why did an automatic redeploy start?
Hint: Look at theTriggers
section in theDeployment Config Overview
.
-
Test the application Open the application's route in the web browser (or curl) by clicking on the URL added on the topology diagram, or from the
Routes
section of theResources
tab of the deployment configuration. Verify that that the app shows a greeting.
If time permits, the following variations can be useful:
- Create a S2I build from the git repo of the NodeJS app (build it yourself with Openshift)
- Fork the git repo, replace the pipeline credentials for deploying to DockerHub with your own,
repeat the exercise your forked repo. Trigger another build (just commit anything) and
publishment of your Docker image. Verify that the trigger
ImageChange
works as expected in the deployment configuration of the Openshift project.