Openshift - Container - Platform 4.12 Getting - Started en Us
Openshift - Container - Platform 4.12 Getting - Started en Us
12
Getting started
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons
Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is
available at
http://creativecommons.org/licenses/by-sa/3.0/
. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must
provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert,
Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift,
Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States
and other countries.
Linux ® is the registered trademark of Linus Torvalds in the United States and other countries.
XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States
and/or other countries.
MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and
other countries.
Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the
official Joyent Node.js open source or commercial project.
The OpenStack ® Word Mark and OpenStack logo are either registered trademarks/service marks
or trademarks/service marks of the OpenStack Foundation, in the United States and other
countries and are used with the OpenStack Foundation's permission. We are not affiliated with,
endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
Abstract
This document provides information to help you get started in OpenShift Container Platform. This
includes definitions for common terms found in Kubernetes and OpenShift Container Platform. This
also contains a walkthrough of the OpenShift Container Platform web console, as well as creating
and building applications by using the command-line interface.
Table of Contents
Table of Contents
.CHAPTER
. . . . . . . . . . 1.. .KUBERNETES
. . . . . . . . . . . . . . .OVERVIEW
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. . . . . . . . . . . . .
1.1. KUBERNETES COMPONENTS 4
1.2. KUBERNETES RESOURCES 4
1.3. KUBERNETES CONCEPTUAL GUIDELINES 6
.CHAPTER
. . . . . . . . . . 2.
. . OPENSHIFT
. . . . . . . . . . . . . CONTAINER
. . . . . . . . . . . . . .PLATFORM
. . . . . . . . . . . .OVERVIEW
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8. . . . . . . . . . . . .
2.1. GLOSSARY OF COMMON TERMS FOR OPENSHIFT CONTAINER PLATFORM 8
2.2. UNDERSTANDING OPENSHIFT CONTAINER PLATFORM 10
2.3. INSTALLING OPENSHIFT CONTAINER PLATFORM 11
2.4. NEXT STEPS 11
2.4.1. For developers 11
2.4.2. For administrators 13
.CHAPTER
. . . . . . . . . . 3.
. . CREATING
. . . . . . . . . . . . AND
. . . . . BUILDING
. . . . . . . . . . . AN
. . . .APPLICATION
. . . . . . . . . . . . . . .USING
. . . . . . . THE
. . . . .WEB
. . . . . CONSOLE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
..............
3.1. BEFORE YOU BEGIN 14
3.2. LOGGING IN TO THE WEB CONSOLE 14
3.3. CREATING A NEW PROJECT 15
3.4. GRANTING VIEW PERMISSIONS 15
3.5. DEPLOYING YOUR FIRST IMAGE 16
3.5.1. Examining the pod 17
3.5.2. Scaling the application 19
3.6. DEPLOYING A PYTHON APPLICATION 20
3.7. CONNECTING TO A DATABASE 21
3.7.1. Creating a secret 22
3.7.2. Loading data and displaying the national parks map 23
.CHAPTER
. . . . . . . . . . 4.
. . .CREATING
. . . . . . . . . . . AND
. . . . . BUILDING
. . . . . . . . . . . AN
. . . .APPLICATION
. . . . . . . . . . . . . . .USING
. . . . . . . THE
. . . . . CLI
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
..............
4.1. BEFORE YOU BEGIN 25
4.2. LOGGING IN TO THE CLI 25
4.3. CREATING A NEW PROJECT 25
4.4. GRANTING VIEW PERMISSIONS 26
4.5. DEPLOYING YOUR FIRST IMAGE 27
4.5.1. Creating a route 27
4.5.2. Examining the pod 28
4.5.3. Scaling the application 31
4.6. DEPLOYING A PYTHON APPLICATION 32
4.7. CONNECTING TO A DATABASE 33
4.7.1. Creating a secret 34
4.7.2. Loading data and displaying the national parks map 35
1
OpenShift Container Platform 4.12 Getting started
2
CHAPTER 1. KUBERNETES OVERVIEW
Traditionally, applications were deployed on top of a single operating system. With virtualization, you can
split the physical host into several virtual hosts. Working on virtual instances on shared resources is not
optimal for efficiency and scalability. Because a virtual machine (VM) consumes as many resources as a
physical machine, providing resources to a VM such as CPU, RAM, and storage can be expensive. Also,
you might see your application degrading in performance due to virtual instance usage on shared
resources.
To solve this problem, you can use containerization technologies that segregate applications in a
containerized environment. Similar to a VM, a container has its own filesystem, vCPU, memory, process
space, dependencies, and more. Containers are decoupled from the underlying infrastructure, and are
portable across clouds and OS distributions. Containers are inherently much lighter than a fully-featured
OS, and are lightweight isolated processes that run on the operating system kernel. VMs are slower to
boot, and are an abstraction of physical hardware. VMs run on a single machine with the help of a
hypervisor.
Sharing resources
3
OpenShift Container Platform 4.12 Getting started
Component Purpose
kube-proxy Runs on every node in the cluster and maintains the network traffic
between the Kubernetes resources.
kubelet Runs on nodes and reads the container manifests. Ensures that the
defined containers have started and are running.
kubectl Allows you to define how you want to run workloads. Use the kubectl
command to interact with the kube-apiserver.
container runtime container runtime runs containers on a host operating system. You must
install a container runtime on each node so that pods can run on the
node.
Persistent storage Stores the data even after the device is shut down. Kubernetes uses
persistent volumes to store the application data.
Pod The pod is the smallest logical unit in Kubernetes. A pod contains one or
more containers to run in a worker node.
4
CHAPTER 1. KUBERNETES OVERVIEW
commands. An Operator acts as a control loop which continuously compares the desired state of
resources with the actual state of resources and puts actions in place to bring reality in line with the
desired state.
Resource Purpose
Kubernetes is a core component of an OpenShift Container Platform. You can use OpenShift Container
Platform for developing and running containerized applications. With its foundation in Kubernetes, the
OpenShift Container Platform incorporates the same technology that serves as the engine for massive
telecommunications, streaming video, gaming, banking, and other applications. You can extend your
containerized applications beyond a single cloud to on-premise and multi-cloud environments by using
the OpenShift Container Platform.
Start with one or more worker nodes to run the container workloads.
Manage the deployment of those workloads from one or more control plane nodes.
Wrap containers in a deployment unit called a pod. By using pods provides extra metadata with
the container and offers the ability to group several containers in a single deployment entity.
Create special kinds of assets. For example, services are represented by a set of pods and a
policy that defines how they are accessed. This policy allows containers to connect to the
services that they need even if they do not have the specific IP addresses for the services.
Replication controllers are another special asset that indicates how many pod replicas are
required to run at a time. You can use this capability to automatically scale your application to
adapt to its current demand.
The API to OpenShift Container Platform cluster is 100% Kubernetes. Nothing changes between a
6
CHAPTER 1. KUBERNETES OVERVIEW
The API to OpenShift Container Platform cluster is 100% Kubernetes. Nothing changes between a
container running on any other Kubernetes and running on OpenShift Container Platform. No changes
to the application. OpenShift Container Platform brings added-value features to provide enterprise-
ready enhancements to Kubernetes. OpenShift Container Platform CLI tool (oc) is compatible with
kubectl. While the Kubernetes API is 100% accessible within OpenShift Container Platform, the kubectl
command-line lacks many features that could make it more user-friendly. OpenShift Container Platform
offers a set of features and command-line tool like oc. Although Kubernetes excels at managing your
applications, it does not specify or manage platform-level requirements or deployment processes.
Powerful and flexible platform management tools and processes are important benefits that OpenShift
Container Platform offers. You must add authentication, networking, security, monitoring, and logs
management to your containerization platform.
7
OpenShift Container Platform 4.12 Getting started
Provide developers and IT organizations with cloud application platforms that can be used for
deploying applications on secure and scalable resources.
With its foundation in Kubernetes, OpenShift Container Platform incorporates the same technology
that serves as the engine for massive telecommunications, streaming video, gaming, banking, and other
applications. Its implementation in open Red Hat technologies lets you extend your containerized
applications beyond a single cloud to on-premise and multi-cloud environments.
Kubernetes
Kubernetes is an open source container orchestration engine for automating deployment, scaling,
and management of containerized applications.
Containers
Containers are application instances and components that run in OCI-compliant containers on the
worker nodes. A container is the runtime of an Open Container Initiative (OCI)-compliant image. An
image is a binary application. A worker node can run many containers. A node capacity is related to
memory and CPU capabilities of the underlying resources whether they are cloud, hardware, or
virtualized.
Pod
A pod is one or more containers deployed together on one host. It consists of a colocated group of
containers with shared resources such as volumes and IP addresses. A pod is also the smallest
compute unit defined, deployed, and managed.
In OpenShift Container Platform, pods replace individual application containers as the smallest
deployable unit.
Pods are the orchestrated unit in OpenShift Container Platform. OpenShift Container Platform
schedules and runs all containers in a pod on the same node. Complex applications are made up of
many pods, each with their own containers. They interact externally and also with another inside the
OpenShift Container Platform environment.
8
CHAPTER 2. OPENSHIFT CONTAINER PLATFORM OVERVIEW
are running than needed, the replica set deletes as many as necessary to match the specified number
of replicas.
Deployment and DeploymentConfig
OpenShift Container Platform implements both Kubernetes Deployment objects and OpenShift
Container Platform DeploymentConfigs objects. Users may select either.
Deployment objects control how an application is rolled out as pods. They identify the name of the
container image to be taken from the registry and deployed as a pod on a node. They set the number
of replicas of the pod to deploy, creating a replica set to manage the process. The labels indicated
instruct the scheduler onto which nodes to deploy the pod. The set of labels is included in the pod
definition that the replica set instantiates.
Deployment objects are able to update the pods deployed onto the worker nodes based on the
version of the Deployment objects and the various rollout strategies for managing acceptable
application availability. OpenShift Container Platform DeploymentConfig objects add the additional
features of change triggers, which are able to automatically create new versions of the Deployment
objects as new versions of the container image are available, or other changes.
Service
A service defines a logical set of pods and access policies. It provides permanent internal IP
addresses and hostnames for other applications to use as pods are created and destroyed.
Service layers connect application components together. For example, a front-end web service
connects to a database instance by communicating with its service. Services allow for simple internal
load balancing across application components. OpenShift Container Platform automatically injects
service information into running containers for ease of discovery.
Route
A route is a way to expose a service by giving it an externally reachable hostname, such as
www.example.com. Each route consists of a route name, a service selector, and optionally a security
configuration. A router can consume a defined route and the endpoints identified by its service to
provide a name that lets external clients reach your applications. While it is easy to deploy a complete
multi-tier application, traffic from anywhere outside the OpenShift Container Platform environment
cannot reach the application without the routing layer.
Build
A build is the process of transforming input parameters into a resulting object. Most often, the
process is used to transform input parameters or source code into a runnable image. A BuildConfig
object is the definition of the entire build process. OpenShift Container Platform leverages
Kubernetes by creating containers from build images and pushing them to the integrated registry.
Project
OpenShift Container Platform uses projects to allow groups of users or developers to work together,
serving as the unit of isolation and collaboration. It defines the scope of resources, allows project
administrators and collaborators to manage resources, and restricts and tracks the user’s resources
with quotas and limits.
A project is a Kubernetes namespace with additional annotations. It is the central vehicle for
managing access to resources for regular users. A project lets a community of users organize and
manage their content in isolation from other communities. Users must receive access to projects
from administrators. But cluster administrators can allow developers to create their own projects, in
which case users automatically have access to their own projects.
Each project has its own set of objects, policies, constraints, and service accounts.
9
OpenShift Container Platform 4.12 Getting started
Operators
An Operator is a Kubernetes-native application. The goal of an Operator is to put operational
knowledge into software. Previously this knowledge only resided in the minds of administrators,
various combinations or shell scripts or automation software such as Ansible. It was outside your
Kubernetes cluster and hard to integrate. With Operators, all of this changes.
Operators are purpose-built for your applications. They implement and automate common Day 1
activities such as installation and configuration as well as Day 2 activities such as scaling up and down,
reconfiguration, updates, backups, fail overs, and restores in a piece of software running inside your
Kubernetes cluster by integrating natively with Kubernetes concepts and APIs. This is called a
Kubernetes-native application.
With Operators, applications must not be treated as a collection of primitives, such as pods,
deployments, services, or config maps. Instead, Operators should be treated as a single object that
exposes the options that make sense for the application.
OpenShift Container Platform utilises a number of computing resources, known as nodes. A node has a
lightweight, secure operating system based on Red Hat Enterprise Linux (RHEL), known as Red Hat
Enterprise Linux CoreOS (RHCOS).
After a node is booted and configured, it obtains a container runtime, such as CRI-O or Docker, for
managing and running the images of container workloads scheduled to it. The Kubernetes agent, or
kubelet schedules container workloads on the node. The kubelet is responsible for registering the node
with the cluster and receiving the details of container workloads.
OpenShift Container Platform configures and manages the networking, load balancing and routing of
the cluster. OpenShift Container Platform adds cluster services for monitoring the cluster health and
performance, logging, and for managing upgrades.
The container image registry and OperatorHub provide Red Hat certified products and community built
softwares for providing various application services within the cluster. These applications and services
manage the applications deployed in the cluster, databases, frontends and user interfaces, application
runtimes and business automation, and developer services for development and testing of container
applications.
You can manage applications within the cluster either manually by configuring deployments of
containers running from pre-built images or through resources known as Operators. You can build
custom images from pre-build images and source code, and store these custom images locally in an
internal, private or public registry.
The Multicluster Management layer can manage multiple clusters including their deployment,
configuration, compliance and distribution of workloads in a single console.
10
CHAPTER 2. OPENSHIFT CONTAINER PLATFORM OVERVIEW
For more information about the installation process, the supported platforms, and choosing a method of
installing and preparing your cluster, see the following:
Installation process
Develop and deploy containerized applications with OpenShift Container Platform. OpenShift Container
11
OpenShift Container Platform 4.12 Getting started
Develop and deploy containerized applications with OpenShift Container Platform. OpenShift Container
Platform is a platform for developing and deploying containerized applications. OpenShift Container
Platform documentation helps you:
Work with projects: Create projects from the OpenShift Container Platform web console or
OpenShift CLI (oc) to organize and share the software you develop.
Use the Developer perspective in the OpenShift Container Platform web console to create and deploy
applications.
Use the Topology view to see your applications, monitor status, connect and group components, and
modify your code base.
Use the developer CLI tool (odo): The odo CLI tool lets developers create single or multi-
component applications and automates deployment, build, and service route configurations. It
abstracts complex Kubernetes and OpenShift Container Platform concepts, allowing you to
focus on developing your applications.
Create CI/CD Pipelines: Pipelines are serverless, cloud-native, continuous integration, and
continuous deployment systems that run in isolated containers. They use standard Tekton
custom resources to automate deployments and are designed for decentralized teams working
on microservices-based architecture.
Deploy Helm charts: Helm 3 is a package manager that helps developers define, install, and
update application packages on Kubernetes. A Helm chart is a packaging format that describes
an application that can be deployed using the Helm CLI.
Understand image builds: Choose from different build strategies (Docker, S2I, custom, and
pipeline) that can include different kinds of source materials (Git repositories, local binary
inputs, and external artifacts). Then, follow examples of build types from basic builds to
advanced builds.
Create container images: A container image is the most basic building block in OpenShift
Container Platform (and Kubernetes) applications. Defining image streams lets you gather
multiple versions of an image in one place as you continue its development. S2I containers let
you insert your source code into a base container that is set up to run code of a particular type,
such as Ruby, Node.js, or Python.
Create templates: Use existing templates or create your own templates that describe how an
application is built or deployed. A template can combine images with descriptions, parameters,
replicas, exposed ports and other content that defines how an application can be run or built.
Understand Operators: Operators are the preferred method for creating on-cluster
applications for OpenShift Container Platform 4.12. Learn about the Operator Framework and
how to deploy applications using installed Operators into your projects.
Develop Operators: Operators are the preferred method for creating on-cluster applications
12
CHAPTER 2. OPENSHIFT CONTAINER PLATFORM OVERVIEW
for OpenShift Container Platform 4.12. Learn the workflow for building, testing, and deploying
Operators. Then, create your own Operators based on Ansible or Helm, or configure built-in
Prometheus monitoring using the Operator SDK.
REST API reference: Learn about OpenShift Container Platform application programming
interface endpoints.
Manage users and groups: Add users and groups with different levels of permissions to use or
modify clusters.
Manage authentication: Learn how user, group, and API authentication works in OpenShift
Container Platform. OpenShift Container Platform supports multiple identity providers.
Manage networking: The cluster network in OpenShift Container Platform is managed by the
Cluster Network Operator (CNO). The CNO uses iptables rules in kube-proxy to direct traffic
between nodes and pods running on those nodes. The Multus Container Network Interface
adds the capability to attach multiple network interfaces to a pod. Using network policy
features, you can isolate your pods or permit selected traffic.
Manage Operators: Lists of Red Hat, ISV, and community Operators can be reviewed by cluster
administrators and installed on their clusters . After you install them, you can run, upgrade, back
up, or otherwise manage the Operator on your cluster.
Use custom resource definitions (CRDs) to modify the cluster: Cluster features implemented
with Operators can be modified with CRDs. Learn to create a CRD and manage resources from
CRDs.
Set resource quotas: Choose from CPU, memory, and other system resources to set quotas.
Prune and reclaim resources: Reclaim space by pruning unneeded Operators, groups,
deployments, builds, images, registries, and cron jobs.
Scale and tune clusters: Set cluster limits, tune nodes, scale cluster monitoring, and optimize
networking, storage, and routes for your environment.
Understanding the OpenShift Update Service: Learn about installing and managing a local
OpenShift Update Service for recommending OpenShift Container Platform updates in
disconnected environments.
Monitor clusters: Learn to configure the monitoring stack. After configuring monitoring, use the
web console to access monitoring dashboards. In addition to infrastructure metrics, you can also
scrape and view metrics for your own services.
13
OpenShift Container Platform 4.12 Getting started
You must be able to access a running instance of OpenShift Container Platform. If you do not
have access, contact your cluster administrator.
Prerequisites
Procedure
Log in to the OpenShift Container Platform web console using your login credentials.
You are redirected to the Projects page. For non-administrative users, the default view is the
Developer perspective. For cluster administrators, the default view is the Administrator perspective. If
you do not have cluster-admin privileges, you will not see the Administrator perspective in your web
console.
The web console provides two perspectives: the Administrator perspective and Developer
perspective. The Developer perspective provides workflows specific to the developer use cases.
Use the perspective switcher to switch to the Developer perspective. The Topology view with options
to create an application is displayed.
14
CHAPTER 3. CREATING AND BUILDING AN APPLICATION USING THE WEB CONSOLE
Users must receive access to projects from administrators. Cluster administrators can allow developers
to create their own projects. In most cases, users automatically have access to their own projects.
Each project has its own set of objects, policies, constraints, and service accounts.
Prerequisites
You have the appropriate roles and permissions in a project to create applications and other
workloads in OpenShift Container Platform.
Procedure
3. Optional: In the Display name field, enter Getting Started with OpenShift.
NOTE
4. Click Create.
Additional resources
The following procedure creates a RoleBinding object for the default ServiceAccount object. The
service account communicates with the OpenShift Container Platform API to learn about pods, services,
and resources within the project.
15
OpenShift Container Platform 4.12 Getting started
Prerequisites
Procedure
1. From the Administrator perspective, navigate to User Management and then click
RoleBindings.
6. In the Role name field, search for view and select view.
Additional resources
Understanding authentication
RBAC overview
Prerequisites
You have the appropriate roles and permissions in a project to create applications and other
workloads in OpenShift Container Platform.
Procedure
1. From the +Add view in the Developer perspective, click Container images to open a dialog.
16
CHAPTER 3. CREATING AND BUILDING AN APPLICATION USING THE WEB CONSOLE
3. Ensure that you have the current values for the following:
a. Application: national-parks-app
b. Name: parksmap
6. In the Advanced Options section, click Labels and add labels to better identify this deployment
later. Labels help identify and filter components in the web console and in the command line.
Add the following labels:
app=national-parks-app
component=parksmap
role=frontend
7. Click Create.
You are redirected to the Topology page where you can see the parksmap deployment in the national-
parks-app application.
Additional resources
The Overview panel enables you to access many features of the parksmap deployment. The Details
and Resources tabs enable you to scale application pods, check build status, services, and routes.
Prerequisites
Procedure
17
OpenShift Container Platform 4.12 Getting started
The Overview panel includes tabs for Details, Resources, and Observe. The Details tab might
be displayed by default.
Tab Defintion
Services that are created for your pod and assigned ports
are listed under the Services heading.
Additional resources
18
CHAPTER 3. CREATING AND BUILDING AN APPLICATION USING THE WEB CONSOLE
When you deploy the national-parks-app image, a deployment resource is created. In this example, only
one Pod is deployed.
Prerequisites
Procedure
NOTE
19
OpenShift Container Platform 4.12 Getting started
4. Use the down arrow to scale the pod down to one instance.
Additional resources
Prerequisites
Procedure
1. From the +Add view in the Developer perspective, click Import from Git to open a dialog.
2. Enter the following URL in the Git Repo URL field: https://github.com/openshift-
roadshow/nationalparks-py.git
A builder image is automatically detected.
NOTE
If the detected builder image is Dockerfile, select Edit Import Strategy. Select
Builder Image and then click Python.
4. Ensure that you have the current values for the following:
a. Application: national-parks-app
b. Name: nationalparks
7. In the Advanced Options section, click Labels and add labels to better identify this deployment
later. Labels help identify and filter components in the web console and in the command line.
Add the following labels:
20
CHAPTER 3. CREATING AND BUILDING AN APPLICATION USING THE WEB CONSOLE
a. app=national-parks-app
b. component=nationalparks
c. role=backend
d. type=parksmap-backend
8. Click Create.
NOTE
Click the Resources tab. In the Builds section, you can see your build running.
Additional resources
Prerequisites
Procedure
1. From the +Add view in the Developer perspective, click Container images to open a dialog.
5. Ensure that you have the current values for the following:
a. Application: national-parks-app
21
OpenShift Container Platform 4.12 Getting started
b. Name: mongodb-nationalparks
8. In the Advanced Options section, click Deployment to add environment variables to add the
following environment variables:
Name Value
MONGODB_USER mongodb
MONGODB_PASSWORD mongodb
MONGODB_DATABASE mongodb
MONGODB_ADMIN_PASSWORD mongodb
9. Click Create.
Additional resources
Prerequisites
Procedure
1. From the Developer perspective, navigate to Secrets on the left hand navigation and click
22
CHAPTER 3. CREATING AND BUILDING AN APPLICATION USING THE WEB CONSOLE
1. From the Developer perspective, navigate to Secrets on the left hand navigation and click
Secrets.
Key Value
MONGODB_USER mongodb
DATABASE_SERVICE_NAME mongodb-nationalparks
MONGODB_PASSWORD mongodb
MONGODB_DATABASE mongodb
MONGODB_ADMIN_PASSWORD mongodb
c. Click Create.
a. From the drop down menu, select nationalparks as the workload to add.
b. Click Save.
This change in configuration triggers a new rollout of the nationalparks deployment with the
environment variables properly injected.
Additional resources
Understanding secrets
Prerequisites
Procedure
23
OpenShift Container Platform 4.12 Getting started
1. From the Topology view, navigate to nationalparks deployment and click Resources and
retrieve your route information.
2. Copy and paste the URL into your web browser and add the following at the end of the URL:
/ws/data/load
Example output
3. From the Topology view, navigate to parksmap deployment and click Resources and retrieve
your route information.
4. Copy and paste the URL into your web browser to view your national parks across the world
map.
Additional resources
24
CHAPTER 4. CREATING AND BUILDING AN APPLICATION USING THE CLI
You must be able to access a running instance of OpenShift Container Platform. If you do not
have access, contact your cluster administrator.
You must have the OpenShift CLI (oc) downloaded and installed.
Prerequisites
Procedure
Log into OpenShift Container Platform from the CLI using your username and password or with
an OAuth token:
You can now create a project or issue other commands for managing your cluster.
Additional resources
oc login
oc logout
Users must receive access to projects from administrators. Cluster administrators can allow developers
to create their own projects. In most cases, users automatically have access to their own projects.
25
OpenShift Container Platform 4.12 Getting started
Each project has its own set of objects, policies, constraints, and service accounts.
Prerequisites
Procedure
Example output
Additional resources
oc new-project
The following procedure creates a RoleBinding object for the default ServiceAccount object. The
service account communicates with the OpenShift Container Platform API to learn about pods, services,
and resources within the project.
Prerequisites
Procedure
To add the view role to the default service account in the user-getting-started project, enter
the following command:
Additional resources
Understanding authentication
26
CHAPTER 4. CREATING AND BUILDING AN APPLICATION USING THE CLI
RBAC overview
oc policy add-role-to-user
Prerequisites
Procedure
Example output
--> Found container image 0c2f55f (12 months old) from quay.io for
"quay.io/openshiftroadshow/parksmap:latest"
* An image stream tag will be created as "parksmap:latest" that will track this image
Additional resources
oc new-app
Optionally, you can define security, such as TLS, for the route.
Prerequisites
27
OpenShift Container Platform 4.12 Getting started
Procedure
$ oc get service
Example output
Example output
route.route.openshift.io/parksmap created
$ oc get route
Example output
Additional resources
oc get
You can view the pods in your cluster and to determine the health of those pods and the cluster as a
28
CHAPTER 4. CREATING AND BUILDING AN APPLICATION USING THE CLI
You can view the pods in your cluster and to determine the health of those pods and the cluster as a
whole.
Prerequisites
Procedure
1. To list all pods with node names, enter the following command:
$ oc get pods
Example output
$ oc describe pods
Example output
Name: parksmap-848bd4954b-5pvcc
Namespace: user-getting-started
Priority: 0
Node: ci-ln-fr1rt92-72292-4fzf9-worker-a-g9g7c/10.0.128.4
Start Time: Sun, 13 Feb 2022 14:14:14 -0500
Labels: app=national-parks-app
app.kubernetes.io/part-of=national-parks-app
component=parksmap
deployment=parksmap
pod-template-hash=848bd4954b
role=frontend
Annotations: k8s.v1.cni.cncf.io/network-status:
[{
"name": "openshift-sdn",
"interface": "eth0",
"ips": [
"10.131.0.14"
],
"default": true,
"dns": {}
}]
k8s.v1.cni.cncf.io/networks-status:
[{
"name": "openshift-sdn",
"interface": "eth0",
"ips": [
29
OpenShift Container Platform 4.12 Getting started
"10.131.0.14"
],
"default": true,
"dns": {}
}]
openshift.io/generated-by: OpenShiftNewApp
openshift.io/scc: restricted
Status: Running
IP: 10.131.0.14
IPs:
IP: 10.131.0.14
Controlled By: ReplicaSet/parksmap-848bd4954b
Containers:
parksmap:
Container ID: cri-
o://4b2625d4f61861e33cc95ad6d455915ea8ff6b75e17650538cc33c1e3e26aeb8
Image:
quay.io/openshiftroadshow/parksmap@sha256:89d1e324846cb431df9039e1a7fd0ed2ba0c51a
afbae73f2abd70a83d5fa173b
Image ID:
quay.io/openshiftroadshow/parksmap@sha256:89d1e324846cb431df9039e1a7fd0ed2ba0c51a
afbae73f2abd70a83d5fa173b
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Sun, 13 Feb 2022 14:14:25 -0500
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-6f844 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-6f844:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
ConfigMapName: openshift-service-ca.crt
ConfigMapOptional: <nil>
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 46s default-scheduler Successfully assigned user-getting-
started/parksmap-848bd4954b-5pvcc to ci-ln-fr1rt92-72292-4fzf9-worker-a-g9g7c
Normal AddedInterface 44s multus Add eth0 [10.131.0.14/23] from openshift-sdn
30
CHAPTER 4. CREATING AND BUILDING AN APPLICATION USING THE CLI
Additional resources
oc describe
oc get
oc label
Viewing pods
When you deploy the national-parks-app image, a deployment resource is created. In this example, only
one Pod is deployed.
Prerequisites
Procedure
To scale your application from one pod instance to two pod instances, enter the following
command:
Example output
deployment.apps/parksmap scaled
Verification
1. To ensure that your application scaled properly, enter the following command:
31
OpenShift Container Platform 4.12 Getting started
$ oc get pods
Example output
2. To scale your application back down to one pod instance, enter the following command:
Additional resources
oc scale
Prerequisites
Procedure
Example output
--> Found image 0406f6c (13 days old) in image stream "openshift/python" under tag "3.9-
ubi8" for "python"
Python 3.9
----------
Python 3.9 available as container is a base platform for building and running various
Python 3.9 applications and frameworks. Python is an easy to learn, powerful programming
language. It has efficient high-level data structures and a simple but effective approach to
object-oriented programming. Python's elegant syntax and dynamic typing, together with its
interpreted nature, make it an ideal language for scripting and rapid application development
32
CHAPTER 4. CREATING AND BUILDING AN APPLICATION USING THE CLI
2. To create a route to expose your application, nationalparks, enter the following command:
Example output
route.route.openshift.io/parksmap created
$ oc get route
Example output
Additional resources
oc new-app
Prerequisites
33
OpenShift Container Platform 4.12 Getting started
Procedure
Example output
--> Found container image dc18f52 (8 months old) from quay.io for
"quay.io/centos7/mongodb-36-centos7"
MongoDB 3.6
-----------
MongoDB (from humongous) is a free and open-source cross-platform document-oriented
database program. Classified as a NoSQL database program, MongoDB uses JSON-like
documents with schemas. This container image contains programs to run mongod server.
* An image stream tag will be created as "mongodb-nationalparks:latest" that will track this
image
Additional resources
oc new-project
Prerequisites
34
CHAPTER 4. CREATING AND BUILDING AN APPLICATION USING THE CLI
Procedure
Example output
secret/nationalparks-mongodb-parameters created
2. To update the environment variable to attach the mongodb secret to the nationalpartks
workload, enter the following command:
Example output
deployment.apps/nationalparks updated
3. To show the status of the nationalparks deployment, enter the following command:
Example output
4. To show the status of the mongodb-nationalparks deployment, enter the following command:
Example output
Additional resources
oc set env
oc rollout status
35
OpenShift Container Platform 4.12 Getting started
You deployed the parksmap and nationalparks applications and then deployed the mongodb-
nationalparks database. However, no data has been loaded into the database.
Prerequisites
Procedure
$ oc exec $(oc get pods -l component=nationalparks | tail -n 1 | awk '{print $1;}') -- curl -s
http://localhost:8080/ws/data/load
Example output
2. To verify that your data is loaded properly, enter the following command:
$ oc exec $(oc get pods -l component=nationalparks | tail -n 1 | awk '{print $1;}') -- curl -s
http://localhost:8080/ws/data/all
Example output
route.route.openshift.io/nationalparks labeled
4. To retrieve your routes to view your map, enter the following command:
$ oc get routes
Example output
36
CHAPTER 4. CREATING AND BUILDING AN APPLICATION USING THE CLI
5. Copy and paste the HOST/PORT path you retrieved above into your web browser. Your browser
should display a map of the national parks across the world.
Additional resources
oc exec
oc label
oc get
37