Skip to content

Commit c0805f4

Browse files
committed
OSDOCS#8398: Migrated the S2i Deployments tutorial
1 parent 0b2d213 commit c0805f4

File tree

3 files changed

+235
-0
lines changed

3 files changed

+235
-0
lines changed

_topic_maps/_topic_map_rosa.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ Topics:
204204
File: cloud-experts-deploying-configmaps-secrets-env-var
205205
- Name: Using Source-to-Image (S2I) webhooks for automated deployment
206206
File: cloud-experts-deploying-s2i-webhook-cicd
207+
- Name: S2i deployments
208+
File: cloud-experts-deploying-application-s2i-deployments
207209
---
208210
Name: Getting started
209211
Dir: rosa_getting_started
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
:_mod-docs-content-type: ASSEMBLY
2+
[id="cloud-experts-deploying-application-s2i-deployments"]
3+
= Tutorial: S2I deployments
4+
include::_attributes/attributes-openshift-dedicated.adoc[]
5+
:context: cloud-experts-deploying-application-s2i-deployments
6+
toc::[]
7+
8+
// Link in there is place holder until that section is migrated.
9+
There are several methods to deploy applications in OpenShift. This tutorial explores using the integrated Source-to-Image (S2I) builder. As mentioned in the link:https://file.rdu.redhat.com/eponvell/OSDOCS-8400_Migrate-OpenShift-Concepts/cloud_experts_tutorials/cloud-experts-getting-started/cloud-experts-getting-started-openshift-concepts.html#source-to-image-s2i[OpenShift concepts] section, S2I is a tool for building reproducible, Docker-formatted container images.
10+
11+
[id="cloud-experts-deploying-application-s2i-deployments-preqs"]
12+
== Prerequisites
13+
14+
The following requirements must be completed before you can use this tutorial.
15+
16+
. You have created a ROSA cluster.
17+
. Retrieve your login command
18+
.. If you are not logged in via the CLI, in {cluster-manager-url}, click the dropdown arrow next to your name in the upper-right and select *Copy Login Command*.
19+
+
20+
image::ostoy-cli-login.png[CLI Login]
21+
+
22+
.. A new tab opens. Enter your username and password, and select the authentication method.
23+
+
24+
.. Click *Display Token*
25+
+
26+
.. Copy the command under "Log in with this token".
27+
+
28+
.. Log in to the command line interface (CLI) by running the copied command in your terminal. You should see something similar to the following:
29+
+
30+
[source,terminal]
31+
----
32+
$ oc login --token=RYhFlXXXXXXXXXXXX --server=https://api.osd4-demo.abc1.p1.openshiftapps.com:6443
33+
----
34+
+
35+
.Example output
36+
[source,terminal]
37+
----
38+
Logged into "https://api.myrosacluster.abcd.p1.openshiftapps.com:6443" as "rosa-user" using the token provided.
39+
40+
You don't have any projects. You can try to create a new project, by running
41+
42+
oc new-project <project name>
43+
----
44+
45+
. Create a new project from the CLI by running the following command:
46+
+
47+
[source,terminal]
48+
----
49+
$ oc new-project ostoy-s2i
50+
----
51+
52+
[id="cloud-experts-deploying-application-s2i-deployments-fork-repo"]
53+
== Fork the OSToy repository
54+
55+
The next section focuses on triggering automated builds based on changes to the source code. You must set up a GitHub webhook to trigger S2I builds when you push code into your GitHub repo. To set up the webhook, you must link:https://github.com/openshift-cs/ostoy/fork[first fork the repo].
56+
57+
[NOTE]
58+
====
59+
Replace `<username\>` with your own GitHub username for the following URLs in this guide.
60+
====
61+
62+
[id="cloud-experts-deploying-application-s2i-deployments-deploy-to-cluster"]
63+
== Using S2i to deploy OSToy on your cluster
64+
65+
. Add secret to OpenShift
66+
+
67+
The example emulates a `.env` file and shows how easy it is to move these directly into an OpenShift environment. Files can even be renamed in the Secret. In your CLI enter the following command, replacing `<UserName>` with your GitHub username:
68+
+
69+
[source,terminal]
70+
----
71+
$ oc create -f https://raw.githubusercontent.com/<UserName>/ostoy/master/deployment/yaml/secret.yaml
72+
----
73+
74+
. Add ConfigMap to OpenShift
75+
+
76+
The example emulates an HAProxy config file, and is typically used for overriding default configurations in an OpenShift application. Files can even be renamed in the ConfigMap.
77+
+
78+
In your CLI enter the following command, replacing `<UserName>` with your GitHub username:
79+
+
80+
[source,terminal]
81+
----
82+
$ oc create -f https://raw.githubusercontent.com/<UserName>/ostoy/master/deployment/yaml/configmap.yaml
83+
----
84+
85+
. Deploy the microservice
86+
+
87+
You must deploy the microservice first to ensure that the SERVICE environment variables are available from the UI application. `--context-dir` is used here to only build the application defined in the `microservice` directory in the git repository. Using the `app` label allows us to ensure the UI application and microservice are both grouped in the OpenShift UI. Run the following command in the CLI to create the microservice, replacing `<UserName>` with your GitHub username:
88+
+
89+
[source,terminal]
90+
----
91+
$ oc new-app https://github.com/<UserName>/ostoy \
92+
--context-dir=microservice \
93+
--name=ostoy-microservice \
94+
--labels=app=ostoy
95+
----
96+
+
97+
.Example output
98+
[source,terminal]
99+
----
100+
--> Creating resources with label app=ostoy ...
101+
imagestream.image.openshift.io "ostoy-microservice" created
102+
buildconfig.build.openshift.io "ostoy-microservice" created
103+
deployment.apps "ostoy-microservice" created
104+
service "ostoy-microservice" created
105+
--> Success
106+
Build scheduled, use 'oc logs -f buildconfig/ostoy-microservice' to track its progress.
107+
Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
108+
'oc expose service/ostoy-microservice'
109+
Run 'oc status' to view your app.
110+
----
111+
112+
. Check the status of the microservice
113+
+
114+
Before moving onto the next step we should be sure that the microservice was created and is running correctly by running the following command:
115+
+
116+
[source,terminal]
117+
----
118+
$ oc status
119+
----
120+
+
121+
.Example output
122+
[source,terminal]
123+
----
124+
In project ostoy-s2i on server https://api.myrosacluster.g14t.p1.openshiftapps.com:6443
125+
126+
svc/ostoy-microservice - 172.30.47.74:8080
127+
dc/ostoy-microservice deploys istag/ostoy-microservice:latest <-
128+
bc/ostoy-microservice source builds https://github.com/UserName/ostoy on openshift/nodejs:14-ubi8
129+
deployment #1 deployed 34 seconds ago - 1 pod
130+
----
131+
+
132+
Wait until you see that it was successfully deployed. You can also check this through the web UI.
133+
134+
. Deploy the front end UI
135+
+
136+
The application has been designed to rely on several environment variables to define external settings. Attach the previously created Secret and ConfigMap afterward, along with creating a PersistentVolume. Enter the following into the CLI:
137+
+
138+
[source,terminal]
139+
----
140+
$ oc new-app https://github.com/<UserName>/ostoy \
141+
--env=MICROSERVICE_NAME=OSTOY_MICROSERVICE
142+
----
143+
+
144+
.Example output
145+
+
146+
[source,terminal]
147+
----
148+
--> Creating resources ...
149+
imagestream.image.openshift.io "ostoy" created
150+
buildconfig.build.openshift.io "ostoy" created
151+
deployment.apps "ostoy" created
152+
service "ostoy" created
153+
--> Success
154+
Build scheduled, use 'oc logs -f buildconfig/ostoy' to track its progress.
155+
Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
156+
'oc expose service/ostoy'
157+
Run 'oc status' to view your app.
158+
----
159+
160+
. Update the Deployment
161+
+
162+
Update the deployment to use a "Recreate" deployment strategy (as opposed to the default of `RollingUpdate`) for consistent deployments with persistent volumes. Reasoning here is that the PV is backed by EBS and as such only supports the `RWO` method. If the deployment is updated without all existing pods being killed it might not be able to schedule a new pod and create a PVC for the PV as it's still bound to the existing pod. If you will be using EFS you do not have to change this.
163+
+
164+
[source,terminal]
165+
----
166+
$ oc patch deployment ostoy --type=json -p \
167+
'[{"op": "replace", "path": "/spec/strategy/type", "value": "Recreate"}, {"op": "remove", "path": "/spec/strategy/rollingUpdate"}]'
168+
----
169+
170+
. Set a Liveness probe
171+
+
172+
Create a Liveness Probe on the Deployment to ensure the pod is restarted if something isn't healthy within the application. Enter the following into the CLI:
173+
+
174+
[source,terminal]
175+
----
176+
$ oc set probe deployment ostoy --liveness --get-url=http://:8080/health
177+
----
178+
179+
. Attach Secret, ConfigMap, and PersistentVolume to Deployment
180+
+
181+
Run the following commands attach your secret, ConfigMap, and PersistentVolume:
182+
+
183+
.. Attach Secret
184+
+
185+
[source,terminal]
186+
----
187+
$ oc set volume deployment ostoy --add \
188+
--secret-name=ostoy-secret \
189+
--mount-path=/var/secret
190+
----
191+
+
192+
.. Attach ConfigMap
193+
+
194+
[source,terminal]
195+
----
196+
$ oc set volume deployment ostoy --add \
197+
--configmap-name=ostoy-config \
198+
-m /var/config
199+
----
200+
201+
.. Create and attach PersistentVolume
202+
+
203+
[source,terminal]
204+
----
205+
$ oc set volume deployment ostoy --add \
206+
--type=pvc \
207+
--claim-size=1G \
208+
-m /var/demo_files
209+
----
210+
211+
. Expose the UI application as an OpenShift Route
212+
+
213+
Run the following command to deploy this as an HTTPS application that uses the included TLS wildcard certificates:
214+
+
215+
[source,terminal]
216+
----
217+
$ oc create route edge --service=ostoy --insecure-policy=Redirect
218+
----
219+
220+
. Browse to your application with the following methods:
221+
** Running the following command opens a web browser with your OSToy application:
222+
+
223+
[source,terminal]
224+
----
225+
$ python -m webbrowser "$(oc get route ostoy -o template --template='https://{{.spec.host}}')"
226+
----
227+
+
228+
** You can get the route for the application and copy and paste the route into your browser by running the following command:
229+
+
230+
[source,terminal]
231+
----
232+
$ oc get route
233+
----

images/ostoy-cli-login.png

11.6 KB
Loading

0 commit comments

Comments
 (0)