Questo contenuto non è disponibile nella lingua selezionata.
Chapter 3. Creating and building an application using the web console
3.1. Before you begin Copia collegamentoCollegamento copiato negli appunti!
- Review Accessing the web console.
- You must be able to access a running instance of OpenShift Container Platform. If you do not have access, contact your cluster administrator.
3.2. Logging in to the web console Copia collegamentoCollegamento copiato negli appunti!
You can log in to the OpenShift Container Platform web console to access and manage your cluster.
Prerequisites
- You must have access to an OpenShift Container Platform cluster.
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
The web console provides two perspectives: the Administrator perspective and Developer perspective. The Developer perspective provides workflows specific to the developer use cases.
Figure 3.1. Perspective switcher
Use the perspective switcher to switch to the Developer perspective. The Topology view with options to create an application is displayed.
3.3. Creating a new project Copia collegamentoCollegamento copiato negli appunti!
A project enables a community of users to organize and manage their content in isolation. Projects are OpenShift Container Platform extensions to Kubernetes namespaces. Projects have additional features that enable user self-provisioning.
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 are logged in to the OpenShift Container Platform web console.
- You are in the Developer perspective.
- You have the appropriate roles and permissions in a project to create applications and other workloads in OpenShift Container Platform.
Procedure
-
In the +Add view, select Project
Create Project. -
In the Name field, enter .
user-getting-started Optional: In the Display name field, enter
.Getting Started with OpenShiftNoteDisplay name and Description fields are optional.
- Click Create.
You have created your first project on OpenShift Container Platform.
3.4. Granting view permissions Copia collegamentoCollegamento copiato negli appunti!
OpenShift Container Platform automatically creates a few special service accounts in every project. The default service account takes responsibility for running the pods. OpenShift Container Platform uses and injects this service account into every pod that launches.
The following procedure creates a
RoleBinding
ServiceAccount
Prerequisites
- You are logged in to the OpenShift Container Platform web console.
- You have a deployed image.
- You are in the Administrator perspective.
Procedure
- Navigate to User Management and then click RoleBindings.
- Click Create binding.
-
Select .
Namespace role binding (RoleBinding) -
In the Name field, enter .
sa-user-account -
In the Namespace field, search for and select .
user-getting-started -
In the Role name field, search for and select
view.view -
In the Subject field, select .
ServiceAccount -
In the Subject namespace field, search for and select .
user-getting-started -
In the Subject name field, enter .
default - Click Create.
3.5. Deploying your first image Copia collegamentoCollegamento copiato negli appunti!
The simplest way to deploy an application in OpenShift Container Platform is to run an existing container image. The following procedure deploys a front end component of an application called
national-parks-app
Prerequisites
- You are logged in to the OpenShift Container Platform web console.
- You are in the Developer perspective.
- You have the appropriate roles and permissions in a project to create applications and other workloads in OpenShift Container Platform.
Procedure
- From the +Add view in the Developer perspective, click Container images to open a dialog.
-
In the Image Name field, enter the following:
quay.io/openshiftroadshow/parksmap:latest Ensure that you have the current values for the following:
-
Application:
national-parks-app -
Name:
parksmap
-
Application:
- Select Deployment as the Resource.
- Select Create route to the application.
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
-
- Click Create.
You are redirected to the Topology page where you can see the
parksmap
national-parks-app
3.5.1. Examining the pod Copia collegamentoCollegamento copiato negli appunti!
OpenShift Container Platform leverages the Kubernetes concept of a pod, which is one or more containers deployed together on one host, and the smallest compute unit that can be defined, deployed, and managed. Pods are the rough equivalent of a machine instance, physical or virtual, to a container.
The Overview panel enables you to access many features of the
parksmap
Prerequisites
- You are logged in to the OpenShift Container Platform web console.
- You are in the Developer perspective.
- You have a deployed image.
Procedure
Click
in the Topology view to open the Overview panel.D parksmapFigure 3.2. Parksmap deployment
The Overview panel includes tabs for Details, Resources, and Observe. The Details tab might be displayed by default.
Expand Table 3.1. Overview panel tab definitions Tab Defintion Details
Enables you to scale your application and view pod configuration such as labels, annotations, and the status of the application.
Resources
Displays the resources that are associated with the deployment.
Pods are the basic units of OpenShift Container Platform applications. You can see how many pods are being used, what their status is, and you can view the logs.
Services that are created for your pod and assigned ports are listed under the Services heading.
Routes enable external access to the pods and a URL is used to access them.
Observe
View various Events and Metrics information as it relates to your pod.
3.5.2. Scaling the application Copia collegamentoCollegamento copiato negli appunti!
In Kubernetes, a
Deployment
Pod
Service
ReplicaSets
Deployment
When you deploy the
national-parks-app
Pod
The following procedure scales the
national-parks-image
Prerequisites
- You are logged in to the OpenShift Container Platform web console.
- You are in the Developer perspective.
- You have a deployed image.
Procedure
-
In the Topology view, click the application.
national-parks-app - Click the Details tab.
Use the up arrow to scale the pod to two instances.
Figure 3.3. Scaling application
NoteApplication scaling can happen quickly because OpenShift Container Platform is launching a new instance of an existing image.
- Use the down arrow to scale the pod down to one instance.
3.6. Deploying a Python application Copia collegamentoCollegamento copiato negli appunti!
The following procedure deploys a back-end service for the
parksmap
The deployed back-end service that is
nationalparks
Prerequisites
- You are logged in to the OpenShift Container Platform web console.
- You are in the Developer perspective.
- You have a deployed image.
Procedure
- From the +Add view in the Developer perspective, click Import from Git to open a dialog.
Enter the following URL in the Git Repo URL field:
https://github.com/openshift-roadshow/nationalparks-py.gitA builder image is automatically detected.
NoteIf the detected builder image is Dockerfile, select Edit Import Strategy. Select Builder Image and then click Python.
- Scroll to the General section.
Ensure that you have the current values for the following:
-
Application:
national-parks-app -
Name:
nationalparks
-
Application:
- Select Deployment as the Resource.
- Select Create route to the application.
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=nationalparks -
role=backend -
type=parksmap-backend
-
- Click Create.
From the Topology view, select the
application.nationalparksNoteClick the Resources tab. In the Builds section, you can see your build running.
3.7. Connecting to a database Copia collegamentoCollegamento copiato negli appunti!
Deploy and connect a MongoDB database where the
national-parks-app
national-parks-app
parksmap
Prerequisites
- You are logged in to the OpenShift Container Platform web console.
- You are in the Developer perspective.
- You have a deployed image.
Procedure
- From the +Add view in the Developer perspective, click Container images to open a dialog.
-
In the Image Name field, enter .
quay.io/centos7/mongodb-36-centos7 -
In the Runtime icon field, search for .
mongodb - Scroll down to the General section.
Ensure that you have the current values for the following:
-
Application:
national-parks-app -
Name:
mongodb-nationalparks
-
Application:
- Select Deployment as the Resource.
- Unselect the checkbox next to Create route to the application.
In the Advanced Options section, click Deployment to add environment variables to add the following environment variables:
Expand Table 3.2. Environment variable names and values Name Value MONGODB_USERmongodbMONGODB_PASSWORDmongodbMONGODB_DATABASEmongodbMONGODB_ADMIN_PASSWORDmongodb- Click Create.
3.7.1. Creating a secret Copia collegamentoCollegamento copiato negli appunti!
The
Secret
nationalparks-mongodb-parameters
nationalparks
Prerequisites
- You are logged in to the OpenShift Container Platform web console.
- You are in the Developer perspective.
- You have a deployed image.
Procedure
- From the Developer perspective, navigate to Secrets on the left hand navigation and click Secrets.
Click Create
Key/value secret. -
In the Secret name field, enter .
nationalparks-mongodb-parameters Enter the following values for Key and Value:
Expand Table 3.3. Secret keys and values Key Value MONGODB_USERmongodbDATABASE_SERVICE_NAMEmongodb-nationalparksMONGODB_PASSWORDmongodbMONGODB_DATABASEmongodbMONGODB_ADMIN_PASSWORDmongodb- Click Create.
-
In the Secret name field, enter
Click Add Secret to workload.
-
From the drop down menu, select as the workload to add.
nationalparks - Click Save.
-
From the drop down menu, select
This change in configuration triggers a new rollout of the
nationalparks
3.7.2. Loading data and displaying the national parks map Copia collegamentoCollegamento copiato negli appunti!
You deployed the
parksmap
nationalparks
mongodb-nationalparks
mongodb-nationalparks
nationalparks
Prerequisites
- You are logged in to the OpenShift Container Platform web console.
- You are in the Developer perspective.
- You have a deployed image.
Procedure
-
From the Topology view, navigate to deployment and click Resources and retrieve your route information.
nationalparks Copy and paste the URL into your web browser and add the following at the end of the URL:
/ws/data/loadExample output
Items inserted in database: 2893-
From the Topology view, navigate to deployment and click Resources and retrieve your route information.
parksmap - Copy and paste the URL into your web browser to view your national parks across the world map.
Figure 3.4. National parks across the world