Skip to content

Commit

Permalink
update odo scenario to openshift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhelfand committed Nov 7, 2019
1 parent ff05cd2 commit f3f493f
Show file tree
Hide file tree
Showing 40 changed files with 609 additions and 84 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/introduction/developing-with-odo/okd-login.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions introduction/developing-with-odo-311/00-application-overview.md
@@ -0,0 +1,13 @@
The application you will be deploying is a wild west shooter style game.

Applications are often divided into components based on a logical division of labor. For example, an application might consist of a data-storage, backend component that performs the application's primary work and stores the results. The backend component is paired with a user interface, frontend component that accesses the backend to retrieve data and displays it to a user.

The application deployed in this tutorial consists of two such components.

## Backend

The backend is a Java-based Spring Boot application. It performs queries against the Kubernetes and OpenShift REST APIs to retrieve a list of the resource objects that were created when you deployed the application. Then, it returns details about these resource objects to the frontend.

## Frontend

The frontend is the user interface for a wild west style game written in Node.js. It displays popup images which you can shoot, corresponding to the resource objects returned by the backend.
@@ -0,0 +1,58 @@
## Logging in to OpenShift

Before we get started, you need to log in to OpenShift. To log in to the OpenShift cluster used for this scenario from the _Terminal_,
run:

`odo login -u developer -p developer`{{execute}}

This will log you in using the credentials:

* **Username:** ``developer``
* **Password:** ``developer``

You should see the output below:

```
Login successful.
You have one project on this server: "default"
Using project "default".
```

Rather than using this default project, we will create a new one by running `odo project create`:

`odo project create myproject`{{execute}}

You should see the following output confirming the creation of a new OpenShift project called `myproject` and that `odo` is now using `myproject`:

```
✓ New project created and now using project : myproject
```

## Creating a Service Account
The backend of our application uses the OpenShift REST API. In order for the backend to access the API, we need to grant access to the service account that the backend is using. We will do this in the web console.

Click the **Dashboard** tab in the console frame of this window. This opens the OpenShift web console.

You should see an **OKD** window with **Username** and **Password** fields, which is similar to this one:

![OKD Web Console](../../assets/introduction/developing-with-odo/okd-login.png)

For this scenario, start by entering the following:

**Username:** ``developer``{{copy}}

**Password:** ``developer``{{copy}}

After logging in to the web console, click on the kebab (three squares) next to the project **myproject**. Click **View Membership** in the drop down that appears.

![View Membership](../../assets/introduction/developing-with-odo/view-membership.png)

On the Membership page, click **Service Accounts** and then **Edit Membership**.

In the select boxes at the bottom, choose **myproject / default** and **view** for the role. Then click the **Add** button next to the role, and, finally, click **Done Editing** at the top of the page.

![Edit Roles](../../assets/introduction/developing-with-odo/membership.png)

Now the service account that the backend uses has **view** access so it can retrieve objects via the API. Note that you could choose **edit** access instead. That would allow the the backend to both retrieve and modify or delete objects. If you do that, you can end up destroying certain resources in the game that are not recoverable, which is why we are choosing **view** access for this scenario.
@@ -0,0 +1,77 @@
As mentioned, applications often consist of two or more components that work together to implement the overall application. OpenShift helps organize these modular applications with a concept called, appropriately enough, the application. An OpenShift application represents all of an app's components in a logical management unit. The `odo` tool helps you manage that group of components and link them together as an application.

A selection of runtimes, frameworks, and other components are available on an OpenShift cluster for building your applications. This list is referred to as the *Software Catalog*.

List the supported component types in the catalog by running:

`odo catalog list components`{{execute}}

Administrators can configure the software catalog to determine what components are available in the catalog, so the list will vary on different OpenShift clusters. For this scenario, the cluster's catalog list must include `java` and `nodejs`.

Source code for the backend of our `wildwest` application is available in the command line environment. Change directories into the source directory, `backend`:

`cd ~/backend`{{execute}}

Take a look at the contents of the `backend` directory. It's a regular Java Spring Boot application using the Maven build system:

`ls`{{execute}}

Build the `backend` source files with Maven to create a jar file:

`mvn package`{{execute}}

Since this is the first time running this build, it may take 30-45 seconds to complete. Subsequent builds will run much more quickly.

With the backend's `.jar` file built, we can use `odo` to deploy and run it atop the Java application server we saw earlier in the software catalog. The command below creates a *component* configuration of *component-type* `java` named `backend`:

`odo create java backend --binary target/wildwest-1.0.jar`{{execute}}

As the component configuration is created, `odo` will print the following:

```
✓ Checking component
✓ Checking component version
Please use `odo push` command to create the component with source deployed
```

The component is not yet deployed on OpenShift. With an `odo create` command, a configuration file called `config.yaml` has been created in the local directory of the `backend` component that contains information about the component for deployment.

To see the configuration settings of the `backend` component in `config.yaml`, `odo` has a command to display this information:

`odo config view`{{execute}}

Since `backend` is a binary component, as specified in the `odo create` command above, changes to the component's source code should be followed by pushing the jar file to a running container. After `mvn` compiled a new `wildwest-1.0.jar` file, the program would be deployed to OpenShift with the `odo push` command. We can execute such a push right now:

`odo push`{{execute}}

As the push is progressing, `odo` will print:

```
✓ Checking component
✓ Checking component version
✓ Creating java component with name backend
✓ Initializing 'backend' component
✓ Creating component backend
✓ Successfully created component backend
✓ Applying component settings to component: backend
✓ Successfully updated component with name: backend
✓ Pushing changes to component: backend of type binary
✓ Waiting for component to start
✓ Copying files to component
✓ Building component
✓ Changes successfully pushed to component: backend
```

Using `odo push`, OpenShift has created a container to host the `backend` component, deployed the container into a pod running on the OpenShift cluster, and started up the `backend` component.

If you want to check on the status of an action in `odo`, you can use the `odo log` command. When `odo push` is finished, let's run `odo log` to follow the progress of the `backend` component deployment:

`odo log -f`{{execute}}

You should see output similar to the following to confirm the `backend` is running on a container in a pod in the OpenShift environment:

```
2019-05-13 12:32:15.986 INFO 729 --- [ main] c.o.wildwest.WildWestApplication : Started WildWestApplication in 6.337 seconds (JVM running for 7.779)
```

The `backend` jar file has now been pushed, and the `backend` component is running.
@@ -0,0 +1,51 @@
With the `backend` component running and connected to persistent storage, we are ready to bring up the `frontend` component and connect it to the `backend`. Once again, source code for the component is already available in the command line environment.

Change directories to the `frontend` directory:

`cd ~/frontend`{{execute interrupt}}

Listing the contents of this directory shows that `frontend` is a Node.js application.

`ls`{{execute}}

Since `frontend` is written in an interpreted language, there is no build step analogous to the Maven build we performed for the `backend` component. We can proceed directly to specifying the `nodejs` environment from the cluster's software catalog.

We give this Node.js component the name `frontend`:

`odo create nodejs frontend`{{execute}}

`odo` will create a `config.yaml` just like with the `backend` component, and you should see the following output:

```
✓ Checking component
✓ Checking component version
Please use `odo push` command to create the component with source deployed
```

With the component named and the the config file created, we can push the Node.js source code from the current directory:

`odo push`{{execute}}

`odo push` should produce the following output:

```
✓ Checking component
✓ Checking component version
✓ Creating nodejs component with name frontend
✓ Initializing 'frontend' component
✓ Creating component frontend
✓ Successfully created component frontend
✓ Applying component settings to component: frontend
✓ Successfully updated component with name: frontend
✓ Pushing changes to component: frontend of type local
✓ Waiting for component to start
✓ Copying files to component
✓ Building component
✓ Changes successfully pushed to component: frontend
```

When we created the `backend` component, we viewed the logs via the terminal. You can also follow the status of your container creation in the web console. Click the Dashboard tab and make sure you're in the project named `myproject`. Click **Overview** in the left navigation to go to the Overview section, where you should see the following:

![OKD Web Console](../../assets/introduction/developing-with-odo/frontend-console.png)

Once the deployment finishes, you'll see the pod become available. When the pod becomes available, the `frontend` component has now been deployed and is running on a container on OpenShift.
15 changes: 15 additions & 0 deletions introduction/developing-with-odo-311/04-linking-components.md
@@ -0,0 +1,15 @@
With both components of our application running on the cluster, we need to connect them so they can communicate. OpenShift provides mechanisms to publish communication bindings from a program to its clients. This is referred to as linking.

To link the current `frontend` component to the `backend`, you can run:

`odo link backend --component frontend --port 8080`{{execute}}

This will inject configuration information into the `frontend` about the `backend` and then restart the `frontend` component.

The following output will be displayed to confirm the linking information has been added to the `frontend` component:

```
✓ Component backend has been successfully linked from the component frontend
```

Now that the `frontend` component has been linked with the `backend` component, let's make `frontend` publicly accessible.
@@ -0,0 +1,34 @@
We have updated `frontend` to be linked with `backend` to allow our application's components to communicate. Let's now create an external URL for our application so we can see it in action:

`odo url create frontend --port 8080`{{execute}}

Once the URL has been created in the `frontend` component's configuration, you will see the following output:

```
✓ URL created for component: frontend
To create URL on the OpenShift cluster, please run `odo push`
```

The change can now be pushed:

`odo push`{{execute}}

`odo` will print the URL generated for the application. It should be located in the middle of the output from `odo push` similar to the output below:

```
✓ Checking component
✓ Checking component version
◑ Applying component settings to component: frontend ✓ Checking URL frontend
◒ Applying component settings to component: frontend ✓ Successfully created URL for component: frontend
✓ http://frontend-app-myproject.2886795296-80-rhsummit1.environments.katacoda.com
✓ Applying component settings to component: frontend
✓ Successfully updated component with name: frontend
✓ Pushing changes to component: frontend of type local
✓ Waiting for component to start
✓ Copying files to component
✓ Building component
✓ Changes successfully pushed to component: frontend
```

Visit the URL in your browser to view the application once the `odo push` command finishes.
@@ -0,0 +1,34 @@
We've deployed the first version of our application and tested it by visiting it with a browser. Let's look at how OpenShift and `odo` help make it easier to iterate on that app once it's running.

First, make sure you are still in the `frontend` directory:

`cd ~/frontend`{{execute}}

Now, we will tell `odo` to `watch` for changes on the file system in the background. Note that the `&` is included to run `odo watch` in the background for this tutorial, but it is usually just run as `odo watch` and can be terminated using `ctrl+c`.

`odo watch &`{{execute}}

Let's change the displayed name for our wild west game. Currently, the title is "Wild West Shoot 'em Up!" We will change this to "My App Shoot 'em Up!"

![Application Title](../../assets/introduction/developing-with-odo/app-name.png)

Edit the file `index.html` with a search-and-replace one-liner performed with the Unix stream editor, `sed`:

`sed -i "s/Wild West/My App/" index.html`{{execute}}

There may be a slight delay before `odo` recognizes the change. Once the change is recognized, `odo` will push the changes to the `frontend` component and print its status to the terminal:

```
File /root/frontend/index.html changed
File changed
Pushing files...
✓ Waiting for component to start
✓ Copying files to component
✓ Building component
```

Refresh the application's page in the web browser. You will see the new name in the web interface for the application.

__NOTE__: If you no longer have the the application page opened in a browser, you can recall the url by executing:

`odo url list`{{execute interrupt}}
Empty file.
69 changes: 69 additions & 0 deletions introduction/developing-with-odo-311/assets/volumes.json
@@ -0,0 +1,69 @@
{
"apiVersion": "v1",
"kind": "List",
"items": [
{
"apiVersion": "v1",
"kind": "PersistentVolume",
"metadata": {
"name": "pv-01"
},
"spec": {
"accessModes": [
"ReadWriteOnce",
"ReadWriteMany",
"ReadOnlyMany"
],
"capacity": {
"storage": "10Gi"
},
"hostPath": {
"path": "/data/pv-01"
},
"persistentVolumeReclaimPolicy": "Recycle"
}
},
{
"apiVersion": "v1",
"kind": "PersistentVolume",
"metadata": {
"name": "pv-02"
},
"spec": {
"accessModes": [
"ReadWriteOnce",
"ReadWriteMany",
"ReadOnlyMany"
],
"capacity": {
"storage": "10Gi"
},
"hostPath": {
"path": "/data/pv-02"
},
"persistentVolumeReclaimPolicy": "Recycle"
}
},
{
"apiVersion": "v1",
"kind": "PersistentVolume",
"metadata": {
"name": "pv-03"
},
"spec": {
"accessModes": [
"ReadWriteOnce",
"ReadWriteMany",
"ReadOnlyMany"
],
"capacity": {
"storage": "10Gi"
},
"hostPath": {
"path": "/data/pv-03"
},
"persistentVolumeReclaimPolicy": "Recycle"
}
}
]
}
5 changes: 5 additions & 0 deletions introduction/developing-with-odo-311/env-init.sh
@@ -0,0 +1,5 @@
ssh root@host01 'for i in {1..200}; do oc policy add-role-to-user system:image-puller system:anonymous && break || sleep 1; done'
ssh root@host01 'oc adm policy add-cluster-role-to-group sudoer system:authenticated'
ssh root@host01 "docker pull registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:latest"

echo "Ready"
19 changes: 19 additions & 0 deletions introduction/developing-with-odo-311/finish.md
@@ -0,0 +1,19 @@
Congratulations! You just learned the basics of using the `odo` tool to manage application components on the OpenShift Container Platform.

## What's next?

We hope `odo` helps you conveniently access all the power OpenShift has to offer, and that these first steps leave you eager to learn more. https://learn.openshift.com has other tutorials from basic to advanced that offer a real cluster to learn on, just like this scenario. It's also easy to run your own OpenShift cluster locally or to leave infrastructure management to Red Hat experts by using a hosted OpenShift.

Here are some of the ways you can get your own OpenShift cluster:

### Minishift

Minishift is a complete OpenShift environment inside a virtual machine that runs on your local system. Minishift supports Windows, MacOS, and Linux operating systems. To find out more about minishift, visit https://www.okd.io/minishift/.

### OpenShift Online

The OpenShift team provides a hosted, managed environment that frees developers from worrying about infrastructure. OpenShift Online includes a free *Starter* tier for developing and testing applications on OpenShift. OpenShift Online Pro provides scalability for production deployments at competitive monthly rates in a multi-tenant environment. Find details about OpenShift Online, and sign up for free, at https://www.openshift.com/pricing/.

### OpenShift Dedicated

For the highest production requirements, Red Hat hosts and manages dedicated OpenShift instances available only to your organization. OpenShift Dedicated is ideal for larger teams that want the scale and velocity benefits of container cluster orchestration without having to sweat the details of deploying and maintaining secure, reliable infrastructure. To find out more, visit https://www.openshift.com/dedicated/.

0 comments on commit f3f493f

Please sign in to comment.