Lab 3 - instructions on creating an OpenShift project
Please find detailed instructions after setting up the oc CLI in the previous step Lab 3 - setting up
Last updated
Was this helpful?
Please find detailed instructions after setting up the oc CLI in the previous step Lab 3 - setting up
Last updated
Was this helpful?
Deploying to OpenShift via 'oc' CLI: video (14:32 mins)
In this lab we will work in the OpenShift Web Console and with the OpenShift CLI. The following image is a simplified overview of the topics of that lab. Have in mind that OpenShift is a Kubernetes platform.
This lab has two parts:
1. Build and save the container image to OpenShift internal Container Repository
We will create a OpenShift project
We will define a build config for OpenShift
We will build with the build Pod inside OpenShift and save container image to the internal OpenShift container registry
2. Deploy the application to the cluster and expose the service
You will define and apply a deployment configuration (yaml) to create a Pod with your microservice
You will define a service which routes requests to the Pod with your microservice
You will expose the service
The following gif is an animation of the simplified steps above in a sequence.
We need an OpenShift project, this is simply put equivalent to a Kubernetes namespace plus OpenShift security. Let us create one.
Note: A project allows a community of users to organize and manage their content in isolation from other communities.
Make sure you are logged on to your OpenShift cluster. See here.
Now we want to build and save a container image in the OpenShift Container Registry. We use these commands to do that:
Defining a new build using 'binary build' and the Docker strategy (more details and oc new-build documentation)
Starting the build process on OpenShift with our defined build configuration. (oc start-build documentation)
Select the 'cloud-native-starter' project in 'My Projects'
Open 'Builds' in the menu and then click 'Builds'
Select 'Last Build' (#1)
Open 'Logs'
Inspect the logs
Select the 'default' project
Expand DEPLOYMENT 'registry-console' in 'Overview' and click on the URL in 'Routes - External Traffic'
In the container registry you will find the 'authors' image and you can click on the latest label.
This deployment will deploy a container to a Pod in Kubernetes. For more details we use the Kubernetes documentation for Pods.
A Pod is the basic building block of Kubernetes–the smallest and simplest unit in the Kubernetes object model that you create or deploy. A Pod represents processes running on your Cluster .
Here is a simplified image for that topic. The deployment.yaml file points to the container image that needs to be instantiated in the pod.
Let's start with the deployment yaml. For more details see the Kubernetes documentation for deployments.
Definition of kind
defines this as a Deployment
configuration.
Inside the spec
section we specify an app name and version label.
Then we define a name
for the container and we provide the container image
location, e.g. where the container can be found in the Container Registry.
The containerPort
depends on the port definition inside our Dockerfile and in our server.xml.
We have previously talked about the usage of the HealthEndpoint class for our Authors service and here we see it the livenessProbe
definition.
This is the full deployment.yaml file.
1. Ensure you are in the {ROOT_FOLDER}/2-deploying-to-openshift/deployment
2. Apply the deployment to OpenShift
Open your OpenShift Web Console
Select the Cloud-Native-Starter project and examine the deployment
Click on #1 to open the details of the deployment
In the details you find the 'health check' we defined before
After the definition of the Pod we need to define how to access the Pod. For this we use a service in Kubernetes. For more details see the Kubernetes documentation for service.
A Kubernetes Service is an abstraction which defines a logical set of Pods and a policy by which to access them - sometimes called a micro-service. The set of Pods targeted by a Service is (usually) determined by a Label Selector.
In the service we map the NodePort of the cluster to the port 3000 of the Authors microservice running in the authors Pod, as we can see in the following picture.
In the service.yaml we see a selector of the pod using the label 'app: authors'.
Apply the service to OpenShift
Using oc expose we create a Route to our service in the OpenShift cluster. (oc expose documentation)
Execute this command, copy the URL to open the Swagger UI in browser
This is the Swagger UI in your browser:
2. Execute this command to verify the output:
3. Output
Open your OpenShift Web Console
Select the Cloud-Native-Starter project
Chose 'Applications' and then 'Services'
Click on 'authors'
Examine the traffic and remember the simplified overview picture.
Congratulations! You deployed from a source code, thru container definition, your first project.