215 lines
12 KiB
Org Mode
215 lines
12 KiB
Org Mode
#+AUTHOR: James Blair
|
||
#+DATE: <2023-08-27 Sun 17:15>
|
||
|
||
|
||
[[./images/header.jpg]]
|
||
|
||
Welcome to the OpenShift Ruby on Rails Workshop!
|
||
|
||
The workshop provides ruby developers an introduction to OpenShift and containers, and how these can be used to build fully automated end-to-end continuos integration and deployment pipelines for Ruby on Rails applications.
|
||
|
||
|
||
|
||
|
||
* Agenda
|
||
|
||
| # | Topic | How | Time allocated | Section link |
|
||
|---|------------------------------------------|--------------------------------|----------------|--------------|
|
||
| 1 | Introduction to containers & kubernetes | Facilitator led, group session | 10m | [[#1-introduction-to-containers--kubernetes][Link]] |
|
||
| 2 | Exploring openshift application platform | Facilitator led, group session | 10m | [[#2-exploring-openshift-application-platform][Link]] |
|
||
| 3 | Setting up your development environment | Individual, hands on excercise | 10m | [[#3. Setting up your development environment][Link]] |
|
||
| 4 | Deploying a ruby application | Individual, hands on excercise | 20m | [[#4. Deploying a ruby application ][Link]] |
|
||
| 5 | Creating a deployment pipeline | Individual, hands on excercise | 20m | [[#5. Creating a deployment pipeline ][Link]] |
|
||
| 6 | Developing & deploying a new feature | Individual, hands on excercise | 20m | [[#6. Developing & deploying a new feature ][Link]] |
|
||
|
||
|
||
|
||
|
||
* 1. Introduction to containers & kubernetes
|
||
|
||
Before we can get hands on with the workshop, let's make sure we have an understanding of both [[https://www.redhat.com/en/topics/containers][containers]] and [[https://www.redhat.com/en/topics/containers/what-is-kubernetes][kubernetes]].
|
||
|
||
|
||
** What are containers?
|
||
|
||
Containers are technologies that allow the packaging and isolation of applications with their entire runtime environment—all of the files necessary to run. This makes it easy to move the contained application between environments (~dev~, ~test~, ~production~, etc.) while retaining full functionality.
|
||
|
||
[[./images/virtualization-vs-containers.png]]
|
||
|
||
What does this mean? For starters, virtualization uses a hypervisor to emulate hardware, which allows multiple operating systems to run side by side. This isn’t as lightweight as using containers.
|
||
|
||
When you have finite resources with finite capabilities, you need lightweight apps that can be densely deployed. Linux containers run natively on the operating system, sharing it across all of your containers, so your apps and services stay lightweight and run swiftly in parallel.
|
||
|
||
Containers are also an important part of IT security. By [[https://www.redhat.com/en/topics/security/container-security][building security into the container pipeline]], containers stay reliable, scalable, and trusted.
|
||
|
||
You can also easily move the containerized application between public, private and hybrid cloud environments and data centers (or on-premises) with consistent behavior and functionality.
|
||
|
||
[[https://www.redhat.com/en/topics/containers/whats-a-linux-container][Continue reading →]]
|
||
|
||
|
||
|
||
|
||
** Why are containers important?
|
||
|
||
Containers help reduce conflicts between your development and operations teams by separating areas of responsibility. Developers can focus on their apps and operations teams can focus on the infrastructure. And, because containers are based on open source technology, you get the latest and greatest advancements as soon as they’re available.
|
||
|
||
Container technologies—including [[https://www.redhat.com/en/topics/containers/what-is-podman][Podman]], [[https://www.redhat.com/en/topics/containers/what-is-skopeo][Skopeo]], [[https://www.redhat.com/en/topics/containers/what-is-buildah][Buildah]], [[http://thenewstack.io/cri-o-make-kubernetes-center-container-ecosystem/][CRI-O]], [[https://www.redhat.com/en/topics/containers/what-is-kubernetes][Kubernetes]], and [[https://www.redhat.com/en/topics/containers/what-is-docker][Docker]] — help your team simplify, speed up, and orchestrate application development and deployment.
|
||
|
||
Containers share the same operating system kernel and isolate the application processes from the rest of the system so the whole thing can be moved, opened, and used across development, testing, and production configurations.
|
||
|
||
Because they are lightweight and portable, containers provide the opportunity for faster development and meeting business needs as they arise.
|
||
|
||
|
||
|
||
|
||
** What is kubernetes?
|
||
|
||
Kubernetes (also known as ~k8s~ or "kube") is an open source container orchestration platform that automates many of the manual processes involved in deploying, managing, and scaling containerized applications.
|
||
|
||
You can cluster together groups of hosts running Linux® containers, and Kubernetes helps you easily and efficiently manage those clusters.
|
||
|
||
[[https://www.redhat.com/en/topics/containers/what-is-a-kubernetes-cluster][Kubernetes clusters]] can span hosts across on-premise, public, private, or hybrid clouds. For this reason, Kubernetes is an ideal platform for hosting cloud-native applications that require rapid scaling.
|
||
|
||
Kubernetes was originally developed and designed by engineers at Google. Google was one of the early contributors to Linux container technology.
|
||
|
||
Red Hat was one of the first companies to work with Google on Kubernetes, even prior to launch, and has become the [[https://www.stackalytics.com/cncf?module=kubernetes][2nd leading contributor]] to the Kubernetes upstream project. Google donated the Kubernetes project to the newly formed [[https://www.cncf.io/][Cloud Native Computing Foundation]] (CNCF) in 2015.
|
||
|
||
[[./images/kubernetes-diagram.svg]]
|
||
|
||
|
||
|
||
|
||
* 2. Exploring openshift application platform
|
||
|
||
Now that we have refreshed on containers and kubernetes, let's take a tour through the OpenShift application platform from the perspective of a developer.
|
||
|
||
** Web console developer view
|
||
|
||
The first stop on our tour will be the Web console "Developer View". In order to move quickly with containers, developers need to be able to use the benefits of Kubernetes without being required to develop a platform engineering skillset. Taking time from development cycles to learn, install, and manage infrastructure tools is not helping get business applications to market.
|
||
|
||
Red Hat OpenShift has a specifically designed developer view so that you can make the most of the platform, without having to get bogged down learning kubernetes.
|
||
|
||
Within developer view you can see a graphical topology for your application, check application logs or observability metrics, scale applications, restart deployments, review pipelines and much more.
|
||
|
||
[[https://www.redhat.com/en/blog/openshift-topology-view-milestone-towards-better-developer-experience][More on developer view →]]
|
||
|
||
[[./images/topology-view.gif]]
|
||
|
||
|
||
|
||
** Web console terminal
|
||
|
||
Sometimes you just need to quickly drop into a terminal to get something done. With the OpenShift Web Terminal you don't need to leave your browser or worry about logging in at a local terminal!
|
||
|
||
[[./images/web-terminal.gif]]
|
||
|
||
|
||
** Quick add for new applications
|
||
|
||
Want to quickly test a proof of concept or spin up a container? Awesome, within developer view in OpenShift you can quickly add a new application directly from git, from an existing image, from a Dockerfile, a yaml manifest, or a catalog of templated services.
|
||
|
||
[[./images/add-application.png]]
|
||
|
||
|
||
** Visual pipeline builder
|
||
|
||
OpenShift Pipelines (based on Tekton) make creating cloud native pipelines on OpenShift easy. There is a pipeline web interface built into the OpenShift web console so you don't need to login to another system and switch contexts to be able to interact with your pipelines.
|
||
|
||
[[./images/openshift-pipelines.gif]]
|
||
|
||
|
||
|
||
* 3. Setting up your development environment
|
||
|
||
For our first hands on excercise let's get logged into the tools we'll be using today and get familar with each.
|
||
|
||
|
||
** Log into bitbucket and fork codebase
|
||
|
||
For this workshop we will be using a [[https://www.atlassian.com/software/bitbucket/enterprise][Bitbucket]] server as our ~git~ source control management tooling. The server is running on the same OpenShift cluster we will be using for the hands on excercises and can be accessed with the link below:
|
||
|
||
[[https://bitbucket-bitbucket.apps.rosa-7lpn7.2pqm.p1.openshiftapps.com]]
|
||
|
||
Use the credentials provided on the workshop etherpad to login.
|
||
|
||
[[./images/bitbucket-login.png]]
|
||
|
||
Once logged in you should be able to view and create a fork of the ~Rails Team/rails-example~ repository to your own user using this link: [[https://bitbucket-bitbucket.apps.rosa-7lpn7.2pqm.p1.openshiftapps.com/projects/MSD/repos/rails-example?fork]]
|
||
|
||
[[./images/bitbucket-fork.png]]
|
||
|
||
|
||
** Log into openshift web console
|
||
|
||
Once we have our individual code fork created let's log into the OpenShift web console using the link [[https://console-openshift-console.apps.rosa-7lpn7.2pqm.p1.openshiftapps.com]].
|
||
|
||
Use the credentials provided on the workshop etherpad to login.
|
||
|
||
[[./images/openshift-login.png]]
|
||
|
||
Once logged in, feel free to repeat the OpenShift tour we went through as a group in section two to get more comfortable with the user interface.
|
||
|
||
|
||
* 4. Deploying a ruby application
|
||
|
||
Now that we are logged into our environment let's move on to deplying the ~rails-example~ codebase we forked earlier, onto OpenShift. We'll do this in two different ways:
|
||
|
||
** User the web interface to import from git and deploy
|
||
1) Create a project bu clicking +Add > Create Project > Enter Project name (i.e. userXX)
|
||
2) Click on the ~Import from Git~ tile in your add menu.
|
||
3) Enter the repo-url for your repository fork.
|
||
4) Click on the ~Ruby~ on Builder Image.
|
||
5) Enter ~rails-example~ in Name field.
|
||
6) Click create button and you will be redirected to ~Topology~ screen.
|
||
7) Click on ~rails-example~ application to see check the progress of the build (this should take roughly 2 minutes).
|
||
8) Click the route once the pod is ~Running~
|
||
|
||
** Using the command line to import from git deploy
|
||
|
||
1) Click on the web terminal ~>_~ icon in the top right corner of the web console.
|
||
2) A terminal will pop up in the bottom of the window, this can sometimes take a minute or two to start.
|
||
3) Copy the following command into the termuinal and press ~Enter~.
|
||
|
||
#+begin_src bash :results output
|
||
oc --namespace user1 new-app --name rails-cli centos/ruby-25-centos7~https://github.com/sclorg/ruby-ex.git
|
||
#+end_src
|
||
|
||
#+RESULTS:
|
||
#+begin_example
|
||
--> Found container image e96bd99 (2 years old) from Docker Hub for "centos/ruby-25-centos7"
|
||
|
||
Ruby 2.5
|
||
--------
|
||
Ruby 2.5 available as container is a base platform for building and running various Ruby 2.5 applications and frameworks. Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). It is simple, straight-forward, and extensible.
|
||
|
||
Tags: builder, ruby, ruby25, rh-ruby25
|
||
|
||
,* An image stream tag will be created as "ruby-25-centos7:latest" that will track the source image
|
||
,* A source build using source code from https://github.com/sclorg/ruby-ex.git will be created
|
||
,* The resulting image will be pushed to image stream tag "rails-cli:latest"
|
||
,* Every time "ruby-25-centos7:latest" changes a new build will be triggered
|
||
|
||
--> Creating resources ...
|
||
imagestream.image.openshift.io "ruby-25-centos7" created
|
||
imagestream.image.openshift.io "rails-cli" created
|
||
buildconfig.build.openshift.io "rails-cli" created
|
||
deployment.apps "rails-cli" created
|
||
service "rails-cli" created
|
||
--> Success
|
||
Build scheduled, use 'oc logs -f buildconfig/rails-cli' to track its progress.
|
||
Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
|
||
'oc expose service/rails-cli'
|
||
Run 'oc status' to view your app.
|
||
#+end_example
|
||
|
||
4) Let's open the web console again and we should now see another application pod in our topology view!
|
||
5) Click on the pod, and open the route to see the application serving traffic.
|
||
|
||
|
||
** Creating a tekton deployment pipeline for our app
|
||
|
||
1) Click on "Pipelines" in the OpenShift web console developer view.
|
||
2) Click on ~Create~ > ~Pipeline~ in the top right hand corner.
|
||
3) Enter the name ~ruby-pipeline~.
|
||
4) Click on ~Add task~, and type in ~clone~, then select ~git-clone~ from Red Hat and click ~Add~.
|