This tutorial is adapted from Web Age course
What is OpenShift?
Red Hat: OpenShift Origin is a container application platform that brings docker and Kubernetes to the enterprise. In this tutorial, you will utilize OpenShift CLI tools and also use the web UI to create a simple project. You will deploy a Docker image which contains “Hello world” service application. You will also see how to manage pods, service applications, and scale the application. Finally, you will delete the service application and the deployment configuration.
This tutorial requires an Internet connection to work and all the required software installed on your system.
Part 1 – Setting the Stage
1. Make sure you have internet connected.
2. Open a new Terminal window by clicking Applications > Terminal.
3. Switch the logged-in user to root:
sudo -i
When prompted for the logged-in user’s password, enter wasadmin
4. Enter the following command:
whoami
You should see that you are root now.
root
Note: Now that you are root on your Lab server, beware of system-wrecking consequences of issuing a wrong command.
5. Switch to the home directory:
cd ~
Part 2 – Connect to OpenShift
In this part, you will use “oc” command line tool to connect to OpenShift and perform various operations.
1. Enter these commands to disable security:
setenforce 0 systemctl stop firewalld systemctl disable firewalld
2. Enter these commands to ensure an IP address is assigned to the machine:
dhclient -r dhclient -v
3. Enter the following command to start Docker
systemctl start docker
4. Start OpenShift.
oc cluster up --base-dir="/home/wasadmin/.occluster"
5. Find the user you are connected to OpenShift Origin as:
oc whoami
It will most likely show you developer.
6. Let’s connect as system:admin account
oc login -u system:admin
7. Verify you are connected as system:admin
oc whoami
8. Get projects list:
oc projects
9. Make myproject the active project:
oc project myproject
10. Get status:
oc status
Notice it shows the project name along with server URL. It also tells you that no services or apps are currently deployed.
Part 3 – Deploy a new Application
In this part, you will deploy a simple hello-world style application. The container image is already available in your VM.
1. In the terminal, run following command to view existing docker images:
docker images
Notice: It shows docker.io/openshift/hello-openshift as one of the images.
Note: openshift/hello-openshift is a Docker image hosted at http://hub.docker.com. It has already been pulled into the VM. It’s a simple image of a Docker container which when deployed and executed, displays a simple greeting message. In the next lab, you will see how to create your custom images hosting services.
__2. Create a new OpenShift app from the docker image:
oc new-app --docker-image="docker.io/openshift/hello-openshift"
The output of the above command looks like this:
Don;t worry about the warning about git.
You can also specify a full URL to some other Docker registry, such as Google. You can also specify the image details in yaml format.
__3. Get status:
oc status
Notice hello-openshift service and deployment configuration are displayed.
__4. Get pod list:
oc get pods
It might take a while before the pod READY status shows 1/1. Wait for a few seconds and run the command again until it shows 1/1.
__5. Open a web browser and enter the following URL:
https://localhost:8443
Note: It might give you a certificate error that your connection is not secure. If you encounter this error then perform the following steps:
1. Click Advanced.
2. Click Add Exception.
3. Click Confirm Security Exception.
You may have to perform these steps 2 times until the login is shown.
__6. Login with developer/developer credentials.
__7. In My Projects section, click My Project project
__8. Click Overview on the left side of the page.
Notice, if the pod is created and running properly, it should show up like this:
Part 4 – Expose Service and Access it
In this part, you will expose the “hello” service and access it via the web browser.
__1. In the terminal, run following command to see service details:
oc describe svc/hello-openshift
__2. In the web browser, on the left side of the page, click Applications > Services.
Notice hello-openshift service is available. You can see similar details which you noticed in the previous step of this part.
__3. Click the hello–openshift service.
On the page, you should be able to see service details and the pod which is running the service. Notice that there’s no route defined for the service on port 8080, which means you can’t access the service, yet.
__4. In the terminal, run following command to expose the service:
oc expose svc/hello-openshift --name=hello-openshift --hostname=hello-openshift.localhost
Notice in the web browser, now hostname is available. It means the service the now exposed.
__5. Right-click the URL under Hostname and click Open Link in new tab.
Notice Hello OpenShift! message is displayed on the page.
__6. Close the tab where Hello OpenShift! message is displayed and go back to the OpenShift management console.
__7. In the terminal run following command:
oc status
Notice it shows the hostname on the terminal like this:
It means the service is exposed.
Part 5 – Scale the Service/Application
In this part, you will scale the service/application by creating multiple instances. By default, 1 instance is created.
__1. In the web browser, click Overview on the left side of the page. You may need to expand it.
Notice it shows 1 pod like this
__2. Click the up arrow, next to 1 pod circle.
Notice it shows 2 pods now. It might take a while, depending on container size, to bring the second pod up and running.
__3. On the left side of the page, click Applications > Pods.
Notice 2 pods are listed.
__4. In the terminal, run the following command:
oc get pods
Notice 2 pods are running.
__5. In the terminal, run the following command:
oc status
__6. Make a note of deployment configuration name dc/hello-openshift
__7. Run following command to scale down back to 1 pod:
oc scale dc/hello-openshift --replicas=1
__8. Run the following command to get pod list:
oc get pods
Notice there’s 1 pod running.
__9. In the web browser, click Overview.
Notice there’s 1 pod running.
Part 6 – Delete Service/Application and Deployment
In this part, you will delete the hello-openshift deployment and the service/application.
__1. In the terminal, run following command to delete the service/application:
oc delete svc/hello-openshift
__2. Run the following command to delete the deployment configuration:
oc delete dc/hello-openshift
__3. Get pod list:
oc get pods
Notice no pods are running.
If it shows a pod, wait for a few seconds and run the command again to view the pods list.
__4. Get status:
oc status
Notice no pods are running.
__5. In the web browser, click Overview.
Notice no pods are running.
__6. Keep the terminal and the web browser open for the next lab.
Part 7 – Review
In this lab, you accessed OpenShift Origin by utilizing the CLI tools and the web UI. You deployed a Docker container image to it, managed the pods and service applications, scaled the service application by running multiple instances, and then cleaned up the environment by deleting the deployment configuration and the service application.