|
| 1 | +--- |
| 2 | +slug: playground |
| 3 | +id: ekm78u6ypkfo |
| 4 | +type: challenge |
| 5 | +title: OpenShift Playground |
| 6 | +notes: |
| 7 | +- type: text |
| 8 | + contents: | |
| 9 | + ## Goal |
| 10 | +
|
| 11 | + Explore OpenShift version 4.16. |
| 12 | +
|
| 13 | + ## Concepts |
| 14 | +
|
| 15 | + * OpenShift Web Console |
| 16 | + * `oc` command line tool |
| 17 | +
|
| 18 | + ## Use case |
| 19 | +
|
| 20 | + You control an OpenShift cluster for one hour. You can deploy your own container image, or set up a pipeline to build your application from source, then use an Operator to deploy and manage a database backend. |
| 21 | +
|
| 22 | + This OpenShift cluster will self-destruct in one hour. |
| 23 | +tabs: |
| 24 | +- id: gokx20ly4oue |
| 25 | + title: Terminal |
| 26 | + type: terminal |
| 27 | + hostname: crc |
| 28 | + cmd: /bin/bash |
| 29 | +- id: aluytc9bmhm1 |
| 30 | + title: Web Console |
| 31 | + type: website |
| 32 | + url: https://console-openshift-console.crc.${_SANDBOX_ID}.instruqt.io |
| 33 | + new_window: true |
| 34 | +- id: 60xkslm20oxn |
| 35 | + title: Visual Editor |
| 36 | + type: code |
| 37 | + hostname: crc |
| 38 | + path: /root |
| 39 | +difficulty: basic |
| 40 | +timelimit: 3600 |
| 41 | +--- |
| 42 | +Before you get started we recommend reading the following tips. They explain |
| 43 | +a bit about how the playground environment is setup and what access you have. |
| 44 | + |
| 45 | +## Logging in to the Cluster via Dashboard |
| 46 | + |
| 47 | +Let's also log in to our web console. This can be done by clicking the *Web Console* tab near the top of your screen. |
| 48 | + |
| 49 | +You can login as `admin` user. Use the following credentials: |
| 50 | + |
| 51 | +* Username: |
| 52 | +``` |
| 53 | +admin |
| 54 | +``` |
| 55 | +* Password: |
| 56 | +``` |
| 57 | +admin |
| 58 | +``` |
| 59 | + |
| 60 | + |
| 61 | +You can also login as the `developer` user. Use the following credentials: |
| 62 | + |
| 63 | +* Username: |
| 64 | +``` |
| 65 | +developer |
| 66 | +``` |
| 67 | +* Password: |
| 68 | +``` |
| 69 | +developer |
| 70 | +``` |
| 71 | + |
| 72 | +## Logging in to the Cluster via CLI |
| 73 | + |
| 74 | +When the OpenShift playground is created you will be logged in initially as |
| 75 | +a cluster admin: |
| 76 | + |
| 77 | +``` |
| 78 | +oc whoami |
| 79 | +``` |
| 80 | + |
| 81 | +This will allow you to perform |
| 82 | +operations which would normally be performed by a cluster admin. |
| 83 | + |
| 84 | +Before creating any applications, it is recommended you login as a distinct |
| 85 | +user. This will be required if you want to log in to the web console and |
| 86 | +use it. |
| 87 | + |
| 88 | +To login to the OpenShift cluster from the _Terminal_ run: |
| 89 | + |
| 90 | +``` |
| 91 | +oc login -u developer -p developer |
| 92 | +``` |
| 93 | + |
| 94 | +This will log you in using the credentials: |
| 95 | + |
| 96 | +* **Username:** ``developer`` |
| 97 | +* **Password:** ``developer`` |
| 98 | + |
| 99 | +Use the same credentials to log into the web console. |
| 100 | + |
| 101 | +In order that you can still run commands from the command line as a cluster |
| 102 | +admin, the ``sudoer`` role has been enabled for the ``developer`` account. |
| 103 | +To execute a command as a cluster admin use the ``--as system:admin`` option |
| 104 | +to the command. For example: |
| 105 | + |
| 106 | +``` |
| 107 | +oc get projects --as system:admin |
| 108 | +``` |
| 109 | + |
| 110 | +## Creating your own Project |
| 111 | + |
| 112 | +To create a new project called ``myproject`` run the command: |
| 113 | + |
| 114 | +``` |
| 115 | +oc new-project myproject |
| 116 | +``` |
| 117 | + |
| 118 | +You could instead create the project from the web console. If you do this, |
| 119 | +to change to the project from the command line run the command: |
| 120 | + |
| 121 | +``` |
| 122 | +oc project myproject |
| 123 | +``` |
| 124 | + |
| 125 | +## Persistent Volume Claims |
| 126 | + |
| 127 | +Persistent volumes have been pre-created in the playground environment. |
| 128 | +These will be used if you make persistent volume claims for an application. |
| 129 | +The volume sizes are defined as 100Gi each, however you are limited by how |
| 130 | +much disk space the host running the OpenShift environment has, which is |
| 131 | +much less. |
| 132 | + |
| 133 | +To view the list of available persistent volumes you can run: |
| 134 | + |
| 135 | +``` |
| 136 | +oc get pv --as system:admin |
| 137 | +``` |
| 138 | + |
| 139 | +## Builder Images and Templates |
| 140 | + |
| 141 | +The playground environment is pre-loaded with Source-to-Image (S2I) builders |
| 142 | +for Java (Wildfly), Javascript (Node.JS), Perl, PHP, Python and Ruby. |
| 143 | +Templates are also available for MariaDB, MongoDB, MySQL, PostgreSQL and |
| 144 | +Redis. |
| 145 | + |
| 146 | +You can see the list of what is available, and what versions, under _Add to |
| 147 | +Project_ in the web console, or by running from the command line: |
| 148 | + |
| 149 | +``` |
| 150 | +oc new-app -L |
| 151 | +``` |
| 152 | + |
| 153 | +## Running Images as a Defined User |
| 154 | + |
| 155 | +By default OpenShift prohibits images from running as the ``root`` user |
| 156 | +or as a specified user. Instead, each project is assigned its own unique |
| 157 | +range of user IDs that application images have to run as. |
| 158 | + |
| 159 | +If you attempt to run an arbitrary image from an external image registry |
| 160 | +such a Docker Hub, which is not built to best practices, or requires that |
| 161 | +it be run as ``root``, it may not work as a result. |
| 162 | + |
| 163 | +In order to run such an image, you will need to grant additional privileges |
| 164 | +to the project you create to allow it to run an application image as any |
| 165 | +user ID. This can be done by running the command: |
| 166 | + |
| 167 | +``` |
| 168 | +oc adm policy add-scc-to-user anyuid -z default -n myproject --as system:admin |
| 169 | +``` |
| 170 | + |
| 171 | +# Next Steps! |
| 172 | + |
| 173 | +Congratulations on completing this self-paced lab and learning about the capabilities of Red Hat OpenShift. To continue your journey, here's some handy links: |
| 174 | + |
| 175 | +* [Red Hat Developer learning page](https://developers.redhat.com/learn) |
| 176 | +* [Want to try a free, instant 30-day OpenShift cluster? Get started with the Developer Sandbox for Red Hat OpenShift](https://developers.redhat.com/developer-sandbox) |
| 177 | + |
| 178 | +Don't forget to finish the lab and provide your feedback on the next page. Thanks for playing! |
0 commit comments