Bootstrap FreeKB - OpenShift - Deploy Hello Openshift
OpenShift - Deploy Hello Openshift

Updated:   |  OpenShift articles

An image contains the code used to create a deployment. Then, a deployment can be created from an image, which should then create a replica set (which is the number of pods that should be created), and then the pods should be created.

 

Use the oc project command to move into a project.

oc project my-project

 

Use the oc import-image command to import the hello-openshift image.

oc import-image openshift4/ose-hello-openshift-rhel8:v4.7.0-202205312157.p0.g7706ed4.assembly.stream --from=registry.redhat.io/openshift4/ose-hello-openshift-rhel8:v4.7.0-202205312157.p0.g7706ed4.assembly.stream --confirm

 

You may need to use the podman login command to log into the external registry.

sudo podman login registry.redhat.io

 

And then use the podman pull command to pull the image from the external registry.

sudo podman pull registry.redhat.io/openshift4/ose-hello-openshift-rhel8:v4.7.0-202205312157.p0.g7706ed4.assembly.stream

 

You can then use the oc new-app command to deploy Hello OpenShift. Check out my article Deploy an application from an image.

oc new-app registry.example.com/openshift4/ose-hello-openshift-rhel8

 

Or, create a YAML file such as hello-openshift.yml and add the following to the YAML file.

apiVersion: v1
kind: Pod
metadata:
  name: hello-openshift
spec:
  containers:
  - image: registry.redhat.io/openshift4/ose-hello-openshift-rhel8
    name: hello-openshift
    ports:
    - containerPort: 8080
      protocol: TCP
    - containerPort: 8888

 

Use the oc create command to create the hello-openshift pod.

oc create --filename hello-openshift.yml

 

Use the oc get pods command to ensure the pod is running.

~]$ oc get pods
NAME                                          READY   STATUS      RESTARTS   AGE
ose-hello-openshift-rhel8-76566c7464-fdj7z    1/1     Running     2          7d

 

The oc exec command can be used to verify that the pod returns Hello Openshift!

~]$ oc exec pod/ose-hello-openshift-rhel8-76566c7464-fdj7z -- curl --silent localhost:8080
Hello OpenShift!

 

Use the oc expose pod command to create a service that will route requests onto the pod.

oc expose pod ose-hello-openshift-rhel8-76566c7464-fdj7z --name hello-openshift-service

 

Use the oc get services command to ensure the service exists.

~]$ oc get services
NAME                      TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)    AGE
hello-openshift-service   ClusterIP      10.217.5.8     <none>         8080/TCP   7d

 

The oc exec command can be used to verify that the service returns Hello Openshift!

~]$ oc exec pod/ose-hello-openshift-rhel8-76566c7464-fdj7z -- curl hello-openshift-service:8080
Hello OpenShift!

 

Use the oc expose service command to create a route that will route requests onto the service.

oc expose service hello-openshift-service --name my-route --port 8080 --labels route-type=default

 

Use the oc get routes command to get the URL for the route.

~]$ oc get routes
NAME          HOST/PORT                                          PATH   SERVICES                  PORT       TERMINATION   WILDCARD
my-route      my-route-my-project.apps.openshift.example.com            hello-openshift-service   8080                     None

 

Use the nslookup command to ensure your DNS server is able to resolve the URL to the IP address of your OpenShift cluster.

~]$ nslookup my-route-my-project.apps.openshift.example.com
Server:         192.168.0.16
Address:        192.168.0.16#53

Name:   my-route-my-project.apps.openshift.example.com
Address: 192.168.130.1

 

The oc describe route command can be used to display more details about the route. Notice that the route has been exposed on router default.

~]$ oc describe route my-route
Name:                   my-route
Namespace:              my-project
Created:                17 minutes ago
Labels:                 name=my-route
Annotations:            openshift.io/host.generated=true
Requested Host:         my-route-my-project.apps.openshift.example.com
                           exposed on router default (host router-default.apps.openshift.example.com) 17 minutes ago
Path:                   <none>
TLS Termination:        <none>
Insecure Policy:        <none>
Endpoint Port:          8080

Service:        hello-openshift-service
Weight:         100 (100%)
Endpoints:      10.217.0.68:8080

 

The default router pod should be in the openshift-ingress project/namespace.

~]$ oc get pod --namespace openshift-ingress
NAME                             READY   STATUS    RESTARTS      AGE
router-default-f6d44996c-sljgl   1/1     Running   2 (58m ago)   56d

 

The router pods run an haproxy (high availability proxy) load balancer, which can be seen with the oc exec command.

~]$ oc exec pod/router-default-76c5c89559-dclkw --namespace openshift-ingress -- cat /var/lib/haproxy/conf/haproxy.config | grep my-route
  server pod:ose-hello-openshift-rhel8-76566c7464-fdj7z:hello-openshift-service:8080-tcp:10.129.7.69:8080 10.129.7.69:8080 cookie 15b9071e86b87a2b4b6f976291de96cf weight 256 check inter 5000ms

 

And Hello OpenShift should be displayed at the route URL.

 

Or using curl.

~]# curl my-route-my-project.apps.openshift.example.com
Hello OpenShift!

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 451c41 in the box below so that we can be sure you are a human.