How to Install and Configure OpenShift Origin PaaS Server on Ubuntu 20.04
OpenShift is a free, open-source, and cloud development Platform as a Service (PaaS) developed by Red Hat that allows the developers to develop and deploy their applications on a cloud infrastructure. It is a community distribution of Kubernetes and enables faster development and release cycles for applications. It comes with a simple and easy to use web interface that allows you to monitor the container resources, container health, the nodes the containers reside on, IP addresses of the nodes, etc
In this tutorial, we will explain how to install OpenShift Origin on Ubuntu 20.04 server.
Prerequisites
- A server running Ubuntu 20.04.
- A root password is configured on your server.
Install Docker CE
First, you will need to install the Docker CE in your system to run all OKD services in docker containers. By default, the latest version of Docker CE is available in the Ubuntu 20.04 default repository. You can install it by just running the following command:
apt-get install docker.io -y
Once the Docker is installed, start the Docker service and enable it to start at boot with the following command:
systemctl start docker systemctl enable docker
You can also verify the status of the Docker service with the following command:
systemctl status docker
At this point, Docker is installed and running. You can now proceed to the next step.
Download OpenShift Origin
At the time of writing this tutorial, the latest version of OpenShift Origin is v3.11.0. You can download it from the Git Hub repository using the following command:
wget https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
Once the download is completed, extract the downloaded file with the following command:
tar -xvzf openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
Next, change the directory to the extracted directory and copy kubectl and oc binaries to the /usr/local/bin directory.
cd openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit
cp oc kubectl /usr/local/bin/
Next, verify the installation of OpenShift client utility using the following command:
oc version
You should see the following output:
oc v3.11.0+0cbc58b
kubernetes v1.11.0+d4cacc0
features: Basic-Auth GSSAPI Kerberos SPNEGO
Next, you will need to create a new daemon.json file and allow the use of the Insecure Docker registry.
nano /etc/docker/daemon.json
Add the following line:
{
"insecure-registries" : [ "172.30.0.0/16" ]
}
Save and close the file then restart Docker service to implement the changes.
systemctl restart docker
Start OpenShif Origin Cluster
Now, start the OpenShift Origin cluster by specifying your system's IP:
oc cluster up --public-hostname=your-server-ip
Now, login to your cluster as administrator user with the following command:
oc login -u system:admin
Next, change to the default project with the following command:
oc project default
Output:
Now using project "default" on server "https://your-server-ip:8443".
Now, verify the current status of your project with the following command:
oc status
You should get the following output:
Create Project on OpenShift
Now, log in to OpenShift with developer user with the following command:
oc login
You will be asked to provide a username and password as shown below:
Provide username as a developer and the password as a developer, and hit Enter. You should see the following output:
Login successful.
You have one project on this server: "myproject"
Using project "myproject".
To create a new project, run the following command:
oc new-project dev --display-name="Project - Dev" --description="My Project"
Provide all the required information and click on the Create button to create a new project.
Deploy Application on OpenShift Origin
First, login to the OpenShift with developer user by running the following command:
oc login
Login with developer user as shown below:
Authentication required for https://your-server-ip:8443 (openshift)
Username: developer
Password:
Login successful.
You have access to the following projects and can switch between them with 'oc project ':
* dev
my-project
myproject
Using project "dev".
Once login, switch the project to the my-project which you have created through OpenShift web console:
oc project my-project
Output:
Now using project "my-project" on server "https://your-server-ip:8443".
Next, verify the status of your current project with the following command:
oc status
Output:
In project My Project (my-project) on server https://your-server-ip:8443
You have no services, deployment configs, or build configs.
Run 'oc new-app' to create an application.
Next, tag an application image from Docker Hub registry with the following command:
oc tag --source=docker openshift/deployment-example:v2 deployment-example:latest
Output:
Tag deployment-example:latest set to openshift/deployment-example:v2.
Next, deploy an application to the OpenShift with the following command:
oc new-app deployment-example
You should see the following output:
--> Found image da61bb2 (4 years old) in image stream "my-project/deployment-example" under tag "latest" for "deployment-example"
* This image will be deployed in deployment config "deployment-example"
* Port 8080/tcp will be load balanced by service "deployment-example"
* Other containers can access this service through the hostname "deployment-example"
* WARNING: Image "my-project/deployment-example:latest" runs as the 'root' user which may not be permitted by your cluster administrator
--> Creating resources ...
deploymentconfig.apps.openshift.io "deployment-example" created
service "deployment-example" created
--> Success
Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
'oc expose svc/deployment-example'
Run 'oc status' to view your app.
Now, verify the application deployment status with the following command:
oc status
You should see the following output:
In project My Project (my-project) on server https://your-server-ip:8443
svc/deployment-example - 172.30.87.146:8080
dc/deployment-example deploys istag/deployment-example:latest
deployment #1 deployed 36 seconds ago - 1 pod
2 infos identified, use 'oc status --suggest' to see details.
To get information about your service, run the following command:
oc get svc
Output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
deployment-example ClusterIP 172.30.87.146 8080/TCP 1m
To get detailed information, run the following command:
oc describe svc deployment-example
Output:
Name: deployment-example
Namespace: my-project
Labels: app=deployment-example
Annotations: openshift.io/generated-by=OpenShiftNewApp
Selector: app=deployment-example,deploymentconfig=deployment-example
Type: ClusterIP
IP: 172.30.87.146
Port: 8080-tcp 8080/TCP
TargetPort: 8080/TCP
Endpoints: 172.17.0.10:8080
Session Affinity: None
Events:
You can also verify the Pods status using the following command:
oc get pods
Output:
NAME READY STATUS RESTARTS AGE
deployment-example-1-b9prf 1/1 Running 0 2m
Now, expose the application for external access using the following command:
oc expose service/deployment-example
Output:
route.route.openshift.io/deployment-example exposed
To display the routes information, run the following command:
oc get routes
You should get the following output:
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
deployment-example deployment-example-my-project.your-server-ip.nip.io deployment-example 8080-tcp None
If you want to delete your application, run the following command:
oc delete all -l app=deployment-example
You should see the following output:
pod "deployment-example-1-b9prf" deleted
replicationcontroller "deployment-example-1" deleted
service "deployment-example" deleted
deploymentconfig.apps.openshift.io "deployment-example" deleted
route.route.openshift.io "deployment-example" deleted