That blog post is a simple cheat sheet, how to deploy a containerized application to OpenShift. We using an existing container image on a public Quay Repository and the OpenShift CLI. This blog post is also a combination of existing blog posts to compare the automated created specifications to the predefined specifications in the blog post “Configure a project in an IBM Cloud Red Hat OpenShift cluster to access the IBM Cloud Container Registry“ and use the login written in the blog post “Log in to the an IBM Cloud Red Hat OpenShift cluster using the IBM Cloud and OpenShift CLI“.
Step 1: Log on to the IBM Cloud Red Hat OpenShift cluster using the IBM Cloud CLI¶
To log on, just follow the steps in this blog post “Log in to the an IBM Cloud Red Hat OpenShift cluster using the IBM Cloud and OpenShift CLI¶“
Step 2: Create a new project¶
oc new-project vend-simple
Step 3: Create a new deployment based on an existing image¶
The example is based on this source code: GitHub project.
oc new-app --docker-image quay.io/tsuedbroecker/vend-simple:v2
Step 4: Inspect the automated created deployment¶
- Get newly created deployments
oc get deployments
Example output:
NAME READY UP-TO-DATE AVAILABLE AGE
vend-simple 1/1 1 1 17s
- Inspect the automated created deployment specification
oc describe deployment vend-simple
Example output:
Name: vend-simple
Namespace: vend-simple
CreationTimestamp: Tue, 16 Nov 2021 18:43:52 +0100
Labels: app=vend-simple
app.kubernetes.io/component=vend-simple
app.kubernetes.io/instance=vend-simple
Annotations: deployment.kubernetes.io/revision: 2
image.openshift.io/triggers:
[{"from":{"kind":"ImageStreamTag","name":"vend-simple:v1"},"fieldPath":"spec.template.spec.containers[?(@.name==\"vend-simple\")].image"}]
openshift.io/generated-by: OpenShiftNewApp
Selector: deployment=vend-simple
Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: deployment=vend-simple
Annotations: openshift.io/generated-by: OpenShiftNewApp
Containers:
vend-simple:
Image: quay.io/tsuedbroecker/vend-simple@sha256:2e6bf9cd6f2921168573bf0270b531acc7863e9d3efdc63337b2cd5ef1b2146a
Port: 3000/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: vend-simple-5b7555b454 (1/1 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 67s deployment-controller Scaled up replica set vend-simple-6ccdfbc85b to 1
Normal ScalingReplicaSet 66s deployment-controller Scaled up replica set vend-simple-5b7555b454 to 1
Normal ScalingReplicaSet 52s deployment-controller Scaled down replica set vend-simple-6ccdfbc85b to 0
Step 5: Inspect the automated the services¶
- Get newly created services
oc get services
Example output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
vend-simple ClusterIP 172.21.61.249 <none> 3000/TCP 2m51s
- Inspect the automated created service specification
oc describe service vend-simple
Example output:
Name: vend-simple
Namespace: vend-simple
Labels: app=vend-simple
app.kubernetes.io/component=vend-simple
app.kubernetes.io/instance=vend-simple
Annotations: openshift.io/generated-by: OpenShiftNewApp
Selector: deployment=vend-simple
Type: ClusterIP
IP Families: <none>
IP: 172.21.61.249
IPs: 172.21.61.249
Port: 3000-tcp 3000/TCP
TargetPort: 3000/TCP
Endpoints: 172.17.51.166:3000
Session Affinity: None
Events: <none>
Step 6: Expose the service to create a route¶
oc expose service/vend-simple
Steo 7: Get the route and open the URL in browser to verify the output¶
oc get route | grep "vend"
- Example output in your browser
"{\"message\":\"vend test - \"}"
Steo 8: Get the route and open the route in browser to verify the output¶
oc get pods
- Example output:
NAME READY STATUS RESTARTS AGE
vend-simple-5b7555b454-f9jw4 1/1 Running 0 14m
Step 9: Access the running pod on it’s command line¶
oc exec vend-simple-5b7555b454-f9jw4 ls
- Example output:
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
docker_entrypoint.sh
generate_env-config.sh
modules
node_modules
package-lock.json
package.json
server.js
Summary¶
As we have seen, the oc new-app
command is an easy straight forward way to create/deploy an application to OpenShift.
I hope this was useful for you and let’s see what’s next?
Greetings,
Thomas
#ibmcloud, #openshift, #roks
I attempted to install this app on an open shift cluster v4.10.30 and the pod will not start. Its getting a “CrashLoopBackOff”. All the events shows is “Back-off restarting failed container”
LikeLike
Hi John, I updated the image pls use now version 2. (https://quay.io/repository/tsuedbroecker/vend-simple?tab=tags&tag=v2) Maybe ensure that the contain is loaded with imagePullPolicy: Always in the vend-simple deployment.
I also changed the code here and I need to verify it https://github.com/thomassuedbroecker/vend/commit/e5d704262f7ffd91d8ebf6587810c4e8f22ca7c3 .
I hope that helps and greetings Thomas
LikeLike