Creating new application on Openshift

We're already build tomcat application by docker file and imported to openshift imagestream as well. If you missed these step please follow the link below:

Checking tomcat image already created.

# oc get all
NAME DOCKER REPO TAGS UPDATED
is/tomcat 172.30.1.1:5000/cloudroot/tomcat latest 18 hours ago

First of all, We should permit tomcat startup with root permission.

# oc login -u system:admin
Logged into "https://192.168.1.100:8443" as "system:admin" using existing credentials.
You have access to the following projects and can switch between them with 'oc project <projectname>':
* cloudroot
default
kube-system
myproject
openshift
openshift-infra
Using project "cloudroot".
# oadm policy add-scc-to-user anyuid -z default

By simple command line, we will start tomcat application creation

# oc new-app 172.30.1.1:5000/cloudroot/tomcat:latest
W0519 12:06:14.786372 16843 dockerimagelookup.go:220] Docker registry lookup failed: Get https://172.30.1.1:5000/v2/: http: server gave HTTP response to HTTPS client
W0519 12:06:14.836494 16843 newapp.go:333] Could not find an image stream match for "172.30.1.1:5000/cloudroot/tomcat:latest". Make sure that a Docker image with that tag is available on the node for the deployment to succeed.
--> Found Docker image 41ad784 (3 days old) from 172.30.1.1:5000 for "172.30.1.1:5000/cloudroot/tomcat:latest"
* This image will be deployed in deployment config "tomcat"
* Port 8080/tcp will be load balanced by service "tomcat"
* Other containers can access this service through the hostname "tomcat"
* WARNING: Image "172.30.1.1:5000/cloudroot/tomcat:latest" runs as the 'root' user which may not be permitted by your cluster administrator
--> Creating resources ...
deploymentconfig "tomcat" created
service "tomcat" created

--> Success
Run 'oc status' to view your app.

which will create 4 itens more.

# oc get all
NAME DOCKER REPO TAGS UPDATED
is/tomcat 172.30.1.1:5000/cloudroot/tomcat latest 18 hours ago
NAME        REVISION   DESIRED   CURRENT   TRIGGERED BY
dc/tomcat 1 1 1 config
NAME          DESIRED   CURRENT   READY     AGE
rc/tomcat-1 1 1 1 1m
NAME         CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
svc/tomcat 172.30.80.208 <none> 8080/TCP 1m
NAME                READY     STATUS    RESTARTS   AGE
po/tomcat-1-5npmg 1/1 Running 0 1m
But “What does IS / DC / RC / SVC / PO stand for?”
  • IS — Image Strem: An image stream comprises any number of Docker-formatted container images identified by tags. It presents a single virtual view of related images, similar to an image repository,
  • DC — Deployment Configuration: OpenShift Origin deployments provide fine-grained management over common user applications. They are described using three separate API objects like:
    *A deployment configuration, which describes the desired state of a particular component of the application as a pod template. 
    *One or more replication controllers, which contain a point-in-time record of the state of a deployment configuration as a pod template. 
    *One or more pods, which represent an instance of a particular version of an application.
  • RC — Replication Controller: A replication controller ensures that a specified number of replicas of a pod are running at all times. If pods exit or are deleted, the replication controller acts to instantiate more up to the defined number. Likewise, if there are more running than desired, it deletes as many as necessary to match the defined amount.
  • SVC — Services Controller: A Kubernetes service serves as an internal load balancer. It identifies a set of replicated pods in order to proxy the connections it receives to them. Backing pods can be added to or removed from a service arbitrarily while the service remains consistently available, enabling anything that depends on the service to refer to it at a consistent address.
  • PO — Pods: OpenShift Origin 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.

After creation, we can access the container (pod) via command line for double check if tomcat service was started as expected:

# oc rsh po/tomcat-1-5npmg
/ #
/ # ps -ef
PID USER TIME COMMAND
1 root 0:00 /bin/sh -c ${CATALINA_HOME}/bin/catalina.sh run
5 root 0:17 /opt/jdk/bin/java -Djava.util.logging.config.file=/opt/to
55 root 0:00 /bin/sh -c TERM="xterm-256color" /bin/sh

or checking container logs.

# oc logs po/tomcat-1-5npmg | grep "Server startup"
19-May-2017 15:07:35.212 INFO [main] apache.catalina.startup.Catalina.start Server startup in 58540 ms

So, the container (pod) could be checked by web-console as well.

Creating a new route

An OpenShift Origin route exposes a service at a host name, like www.example.com, so that external clients can reach it by name.

DNS resolution for a host name is handled separately from routing. Your administrator may have configured a DNS wildcard entry that will resolve to the OpenShift Origin node that is running the OpenShift Origin router. If you are using a different host name you may need to modify its DNS records independently to resolve to the node that is running the router.

Each route consists of a name (limited to 63 characters), a service selector, and an optional security configuration.

Lets create a new route for tomcat application

which one service route was created automatically.

# oc get all
NAME DOCKER REPO TAGS UPDATED
is/tomcat 172.30.1.1:5000/cloudroot/tomcat v1,latest 19 hours ago
NAME        REVISION   DESIRED   CURRENT   TRIGGERED BY
dc/tomcat 1 1 1 config
NAME          DESIRED   CURRENT   READY     AGE
rc/tomcat-1 1 1 1 57m
NAME     HOST/PORTPATH SERVICES   PORT       TERMINATION   WILDCARD
routes/tomcat tomcat-cloudroot.192.168.1.100.xip.io tomcat 8080-tcp
NAME         CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
svc/tomcat 172.30.80.208 <none> 8080/TCP 57m
NAME                READY     STATUS    RESTARTS   AGE
po/tomcat-1-5npmg 1/1 Running 0 57m

So, We are able to access URL http://tomcat-cloudroot.192.168.1.100.xip.io

Voi-là!!

Enjoy!! :)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.