OpenShift Hands-On Lab - Scale Up/Down Applications
OpenShift Learning Path for Cloud and DevOps Engineers
Table of contents
- 📝Introduction
- 📝Set Up CodeReady Containers (For those who choose to run it locally)
- 📝Set Up an OpenShift Sandbox (For those who choose to run it online on the Cloud. This was my choice).
- 📝Log In to the Cluster (Option 1)
- 📝Log In to the Cluster (Option 2)
- 📝Install an application from Source
- 📝Scale an application running in OpenShift up or down
📝Introduction
In this lab, we will learn how to use the oc
CLI tool to scale up and down the number of OpenShift pods.
These are the objectives of this lab:
- Create the New Project
📌Note: This section only applies to students using CodeReady Containers. Skip this section if you are using Red Hat OpenShift sandbox.
Install a web application in the Developer Sandbox for Red Hat OpenShift using the
oc
CLI tool.Use the
oc
CLI tool to scale-increase the number of pods associated with the web application you installed.Use the
oc
CLI tool to scale-decrease the number of pods associated with the web application you installed.
Logic for an OpenShift application is represented by a container(s) organized in a Kubernetes pod.
📌Note: Due to resource limitations in my Cloud Playground environment, I used the below Red Hat free online resources available for this lab.
To complete this lab, you must first register for a Red Hat Developer login on theRed Hat login page.
Once registered, you may complete the lab steps usingRed Hat's CodeReady Containers or the Red Hat-provided OpenShift sandbox.
Solutions for CodeReady Containers and the Red Hat OpenShift sandbox can be used in this lab. However, I decided to use the free Red Hat-provided OpenShift sandbox available for 30 days.
📝Set Up CodeReady Containers (For those who choose to run it locally)
📌Note: CodeReady Containers has specific hardware and operating system requirements. To ensure your environment is compatible, seeRed Hat's minimum system requirements for CodeReady Containers.
Navigate and log in to your Red Hat Developer account.
Under the Local tab, select your OS and click Download CodeReady Containers.
Click Copy Pull Secret for later use.
Install CodeReady Containers.
📌*Note:For OS-specific installation instructions, see [Red Hat's CodeReady Containers installation guide](access.redhat.com/documentation/en-us/red_h..).*
Open a terminal session and set up CodeReady Containers:
crc setup
When prompted, enter
yes
to enable telemetry data collection orno
to disable telemetry data collection.Start the VM:
crc start
📌Note: The cluster takes a minimum of 4 minutes to start before serving a request.
When prompted, paste in the previously copied pull request and press Enter.
Print the command needed to add the cached
oc
executable to your$PATH
:crc oc-env
Run the printed command.
Log in as the developer user:
oc login -u developer https://api.crc.testing:6443
📝Set Up an OpenShift Sandbox (For those who choose to run it online on the Cloud. This was my choice).
To log in through the web UI directly, navigate to the Red Hat CodeReady Containers page and log in to your Red Hat Developer account with the credentials you created.
Select Try OpenShift in our free sandbox.
Click Launch your Developer Sandbox for Red Hat OpenShift.
To confirm your account, enter a valid phone number and click Send Code.
Enter the verification code you received and click Verify Code.
Click Start using your sandbox.
Under Log in with, click DevSandbox.
Select the I have read and agree to the Red Hat OpenShift Online Services Agreement and click SUBMIT.
At the top right, click the shell icon (>_).
Leave the default project selected and click Start. Note: You will not be able to create new projects in the sandbox. For any steps in the lab stating you need to create a new project, skip that step and ensure you use one of the existing projects: <username>-dev, or <username>-stage.
📌Note: Type
q
to exit a menu or log.
📝Log In to the Cluster (Option 1)
📌Note: This section only applies to students using CodeReady Containers. Otherwise, skip to the next objective.
Log in to the cluster:
oc login -u developer https://api.crc.testing:6443
In a new browser, log in to the cluster using the console URL.
Use the
developer
credentials to log in.
📝Log In to the Cluster (Option 2)
📌Note: To complete a login using oc
in the OpenShift sandbox, click on the shell (>_) icon. Alternatively, you can download the binary and log in from a remote system (e.g. VSCode). Please review the Using Red Hat OpenShift Sandbox video detailing the necessary steps for that process.
📝Install an application from Source
Install an application from source code stored in a GitHub repository.
oc new-app quay.io/openshiftroadshow/parksmap
Now, run the following command in a terminal to expose the application to the Internet:
oc expose service/parksmap
The application named
parksmap
is now installed and exposed.You can try to open the app on your browser:
📝Scale an application running in OpenShift up or down
Run the following command in the terminal window to determine the number of pods running under the
parksmap
deployment:oc get deployment
📌Note: The deployment named
parksmap
has one pod associated with the deployment. That single pod is up and running as is shown in the 1/1 entry in the READY column, because you installed the parksmap application at the beginning of this lesson.You are now going to scale the
parksmap
application up, and then scale it down.Scale up an OpenShift application
Run the following command in the terminal window to scale the
parksmap
deployment to three pods. Use of the–replicas
option to declare the number of pods that the deployment needs to be created:oc scale deployment parksmap --replicas=3
Run the following command in the terminal window to determine the number of pods running under the
parksmap
deployment:oc get deployment -l app=parksmap
Scale down an OpenShift application
Run the following command in the terminal window to scale
parksmap
deployment to one pod:oc scale deployment parksmap --replicas=1
Then, run the following command in the terminal window to determine the number of pods running under the
parksmap
deployment:oc get deployment -l app=parksmap
The deployment now has one pod running. You have successfully scaled down the
parksmap
application.
📌Note - At the end of each hands-on Lab, always clean up all previous resources created to avoid being charged if you used a Cloud Provider to provision them.
Congratulations — you have completed this hands-on lab covering the basics of increasing and decreasing the number of pods in the deployment to scale up/down the application.
Thank you for reading. I hope you understood and learned something helpful from my blog.
Please follow me on CloudDevOpsToLearn and LinkedIn, franciscojblsouza