banner



How To Restart Master Service On Openshift

In this post, we practice a deep dive on what unproblematic resources get created behind the scenes when you create a new app in OpenShift.

Nosotros previously created an OpenShift cluster on DigitalOcean. Let'due south deploy apps on that server now.

Download code used in this post.

To begin with, you need the oc command line tool. You lot can download it from here. In one case you download the client tool, you need to login with your credentials. You can become the credentials from the OpenShift console by accessing the login command from the bill of fare as shown here,

Get login command from OpenShift web console
Getting the oc login control from the OpenShift web panel

The command will be of the format,

          $ oc login https://console.<your-domain>.com:8443 --token=ABCDXyz123        

Using OpenShift resources

At that place are many means to create apps in OpenShift. In this post, nosotros volition focus on using base elements of an OpenShift cluster, resource like pods, deployments and replication controllers. Fifty-fifty though nosotros don't create apps this way in actual usage, information technology helps empathize what happens below all the abstractions when we create an app.

Pods

Pods are the primal units of abstraction in an OpenShift cluster, similar to Kubernetes. In fact, any functioning you do with a Kubernetes resource can be done in OpenShift every bit well. Allow's go ahead and create a pod which runs a elementary web server.

          $ oc apply -f apache_root_pod.yml        

You can so check the status of the pod.

          $ oc get pods NAME                               READY     STATUS              RESTARTS   AGE apache                             0/1       ContainerCreating   0          4s        

Let's take a look at the pod'south logs,

          $ oc logs -f apache (13)Permission denied: AH00072: make_sock: could not bind to address [::]:80 (thirteen)Permission denied: AH00072: make_sock: could non demark to address 0.0.0.0:eighty        

Our pod didn't get created successfully, and rightly so. OpenShift is designed to run containers as not-root. This is a deliberate blueprint decision. Even though containers are isolated constructs, OpenShift takes actress security measure out to ensure that your container process runs as a not-root user. The implication is, most of the official Docker images don't run by default in OpenShift out of the box! But don't sweat over information technology, as OpenShift maintains nonroot versions of most of the stacks and services.

Let's replace this with the non-root equivalent.

Only outset, remove the old pod.

          $ oc pod delete apache        
          $ oc create -f apache_pod.yml        

Services and routes

There tin exist multiple pods with the same configuration and containers. A "service" is a resource which tags all these similar pods into a single entity. Why do we need services? If I have more than than one pod with the same configuration(typically happens if you lot are scaling up), I demand a fashion to collectively package all these pods. That's where services help.

Let's create a service.

          $ oc apply -f apache_service.yml        

Let's try to access the service,

          $  oc get svc Name                           Type        CLUSTER-IP       EXTERNAL-IP   PORT(Southward)    AGE apache-service                 ClusterIP   172.30.172.205   <none>        8080/TCP   16m  $  ringlet -s http://172.thirty.172.205:8080        

We use 8080 because that's what nosotros gave in the pod. The higher up curl volition time out. Just, if you login to the cluster and endeavour the same curl, it will piece of work.

          $ ssh -i <your ssh individual key> root@console.example.com . . [root@openshift-master ~]#  curl -due south http://10.130.0.10:8080 | head        

What but happened? Your service is by default visible and exposed only within the OpenShift cluster, non outside information technology.

To betrayal your service to outside work, we create a new entity called road associated with a service. Routes are resources specific to OpenShift and non found in Kubernetes. Call back of road as a mapping between your service and a domain proper name.

Let's expose the service as a road.

          $ oc expose svc/apache-service        

Now, we tin can access our app using a domain name. This is unremarkably of the format app-name.project-name.your-app-subdomain. You lot tin can check the road using the command,

          $ oc get route        

A route is another resource, very like to a pod or a service. Hence, nosotros can add together it using YAML besides. Let'due south try adding some other road to the same service, this time using YAML.

Make sure you change the "host" in the road yaml file to your host before your run this control:

          $ oc apply -f apache_route.yml        

We saw earlier that a service is a tagged collection of similar pods. Permit'due south create some other pod with the same specification.

          $ oc apply -f apache_pod2.yml        

If you observe the spec for second pod, you will discover that it has a generateName: apache- instead of a name property. That'southward just another style to specify a unique name for a pod.

Now, considering our service is tagged with all pods which accept the app: demo1 label selector, this will be added as one of the service endpoints. This ways that the service can either serve from the first pod or the 2d pod. We can verify this by looking at the service spec.

          $ oc describe svc/apache-service | grep -i endpoints Endpoints:         10.129.0.8:8080,10.130.0.10:8080        

Download code used in this post.

Replica sets

Nosotros meet that our apache server is served past ii pods. Let'due south try deleting 1 of them.

          $ oc delete pod apache        

Now, simply i pod serves our app, every bit indicated past the service endpoints.

          $ oc draw svc/apache-service | grep -i endpoints Endpoints:         10.129.0.8:8080        

Its quite mutual for pods to perish in a containerized setup. In guild to ensure that a specified number of pods run always, we need to create a new construct called replica set. Its like maxim to the OpenShift cluster, "Hey! always make sure that 2 copies of my Apache pod are always running."

OpenShift replica set

          $ oc utilise -f apache_rs.yml  $ # Afterwards a infinitesimal...  $ oc become pods NAME                               Set     Condition      RESTARTS   AGE apache-rs-948q6                    i/1       Running     0          11s apache-rs-bw7vt                    1/1       Running     0          11s        

Attempt deleting one of the pods, and notice that they get "replicated" over again.

          $ oc delete pod apache-rs-948q6 pod "apache-rs-948q6" deleted $ oc go pods NAME                               Set     Status      RESTARTS   AGE apache-rs-55pl9                    one/1       Running     0          22s apache-rs-bw7vt                    1/1       Running     0          7m                  

Deployments

Let's say we want to ship a newer image of our "apache" app.  The issue with replica sets is, when we desire to transport new code, nosotros have to destroy the existing replica sets.

          $ oc delete rs apache-rs replicaset.extensions "apache-rs" deleted                  

Edit the replica ready yaml to point to the new paradigm, and recreate the replica set.

To avoid this, OpenShift has another abstraction on top of replica set called the deployment config. Information technology contains the same data as in a replica set, and more. The main problem we're trying to solve with deployments is to trigger an automatic deployment based on an paradigm change.

Let'south create a deplyment fix.

          $ oc employ -f apache_dc.yml        
OpenShift deployment config

The deployment config looks similar for the most part except afterward line 23 where in that location is a specification which says what will trigger a new deployment. In our instance, its a new image. A deployment config by itself won't deploy anything, nosotros have to burn down it initially.

          $ oc rollout latest dc/apache-dc Fault from server (BadRequest): cannot trigger a deployment for "apache-dc" because it contains unresolved images                  

The "unresolved images" error is because OpenShift is not able to detect the higher up image in its internal docker registry. Let's add together that from our public docker image.

          $ oc tag --source=docker lakshminp/apache:v1 myproject/apache:latest Tag apache:latest set to lakshminp/apache:v1.                  

I'yard essentially tagging "lakshminp/apache:v1" as "apache:latest" in my projection's namespace. This creates an imagestream of the above image in my OpenShift cluster.(More on imagestreams in a future post). Confirming that the image stream is created,

          $ oc become is NAME      DOCKER REPO                        TAGS      UPDATED apache    172.30.1.i:5000/myproject/apache   latest    About an hour ago                  

We rollout the deployment once again, create the service, and expose it as a route.

          $ oc apply -f apache_service.yml        
          $ oc expose svc/apache-service        
version i deployed

Then far, not very unlike from a replica ready. In fact, we incurred on extra pace of creating an epitome source. Now, hither's where deployments shine. We create a newer version and tag it as the "latest", which will automatically trigger a new build.

          $ oc tag --source=docker lakshminp/apache:v2 myproject/apache:latest Tag apache:latest set to lakshminp/apache:v2.        

Y'all can see that OpenShift destroys the onetime pods and creates the new ones.

          $ oc get pods NAME                 READY     STATUS        RESTARTS   Age apache-dc-2-btpqz            11            Running       0          5m apache-dc-2-nqxkc    0/ane       Terminating   0          5m apache-dc-3-7b8c2            ane1            Running       0          2s apache-dc-three-8qvqz            1one            Running       0          6s apache-dc-iii-deploy            11            Running       0          8s                  

v2 deployed automatically

Creating apps by using these YAML files is non what nosotros typically do things. Nosotros'll encounter how we can create calibration this and amend the programmer experience in the side by side post.

Source: https://www.shapeblock.com/creating-apps-openshift-1/

Posted by: waldschmidthavemprought.blogspot.com

0 Response to "How To Restart Master Service On Openshift"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel