From 31f2a56bb09707bbc23da867e69d2cafeb44ff45 Mon Sep 17 00:00:00 2001 From: thakertanya <60537067+thakertanya@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:33:33 -0500 Subject: [PATCH 1/6] Create OpenShift.md --- Topics/Tech_Stacks/OpenShift.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Topics/Tech_Stacks/OpenShift.md diff --git a/Topics/Tech_Stacks/OpenShift.md b/Topics/Tech_Stacks/OpenShift.md new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Topics/Tech_Stacks/OpenShift.md @@ -0,0 +1 @@ + From b9ff7711ed9edff77f4556255d3f6af6b7270561 Mon Sep 17 00:00:00 2001 From: thakertanya <60537067+thakertanya@users.noreply.github.com> Date: Mon, 27 Nov 2023 18:07:11 -0500 Subject: [PATCH 2/6] Update OpenShift.md --- Topics/Tech_Stacks/OpenShift.md | 146 ++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/Topics/Tech_Stacks/OpenShift.md b/Topics/Tech_Stacks/OpenShift.md index 8b1378917..93b74b574 100644 --- a/Topics/Tech_Stacks/OpenShift.md +++ b/Topics/Tech_Stacks/OpenShift.md @@ -1 +1,147 @@ +## Table of Contents + +- [Introduction](#introduction-to-openshift) +- [Key Features](#key-features) +- [Architecture](#architecture) +- [Deploying an Application](#deploying-a-simple-application) + - [Prerequisites](#prerequisites) + - [Accessing your Cluster](#accessing-your-cluster) + - [Creating an Application](#creating-an-application) + - [Deploying an application](#deploying-an-application) + - [Accessing application](#accessing-application)z +- [Additional Resources](#additional-resources) + +## Introduction to OpenShift + +Red Hat OpenShift is an open source container application platform that runs on Red Hat Enterprise Linux CoreOS (RHCOS). It is built on existing Kubernetes features with additional features specific to OpenShift. It takes care of scaling, monitoring, logging, and metering functions like Kubernetes but also provides an in cluster docker registry, developer friendly environment amongst other features. + +## Key Features: + +- **Security**: It provides features such as role-based access control (RBAC), image scanning to ensure images have less vulnerabilities and applications can run in a secure environment with restricted access. + +- **Container Registry**: It includes an integrated container registry, that allows storage and management of container images in the cluster. + +- **Container Orchestration**: It uses Kubernetes to automate the deployment, scaling, and management of containers. These features allow developers to focus on application code rather than infrastructure. + +- **Developer**: It provides several features that enhances development process by provided a user-friendly UI that allows developers to manage application, resources, and pod health. Additionally, it includes Source-to-Image (S2I) a tool which simplifies building and deploying container images from source code. + +- **Operator**: This is a key feature that distinguishes OpenShift from Kubernetes. Operators are a method for packaging and running Kubernetes applications. It greatly simplifies installation, updates, and management. In essence, it automates the entire lifecycle management process. + + +## Architecture + +In order to understand OpenShift, it is crucial to know the architecture. It has several layers with dedicated responsibilities. + +### Infrastructure Layer + +This layer allows the cluster to be deployed on the cloud either private or public or on physical or virtual servers. + +### Service Layer + +This layer is an abstraction provided by Kubernetes primarily used to expose and access applications within the cluster. It facilitates communication between different components. It primarily consists of 2 types of nodes: master and worker node. Each node has a host and IP address that can be accessed within the cluster. Only the master node has a public IP address that can be accessed from outside the cluster. + +#### Master node +- **API and authentication**: To ensure the security of the cluster, any administration/ access request goes through the API. +- **Data Store**: Stores the state and information related to the environment and application. +- **Scheduler**: Determines where pods and jobs will run while considering current memory, CPU, and other environment factors. +**Health/scaling**: Monitors the well-being of pods and adjusts their scale according to CPU utilization. In the event of pod failure, the primary node initiates an automatic restart. In case of frequent failures, the pod is flagged as bas and is temporarily withheld from further restart attempts. + + +#### Worker node + The worker node is made of pods, pods are the smallest unit that can be deployed, and it can contain one or more containers. Containers typically include requirements and dependencies your applications need to run. It is important to note that containers are ephemeral, and containers restart often which can lead to loss of data. To prevent that, persistent storage is used to save data. It also consists of registry to store images. + + +### Routing Layer + +It provides routes that allow for external access to applications. + +## Deploying a Simple Application + +### Prerequisites +- RedHat OpenShift Cluster + - You can create a minimal preconfigured cluster using the Developer Sandbox package [here](https://www.redhat.com/en/technologies/cloud-computing/openshift/try-it). +- Python +- OpenShift CLI - Instructions can be found [here](https://docs.openshift.com/container-platform/4.11/cli_reference/openshift_cli/getting-started-cli.html) +- Docker + +### Accessing your Cluster +- To log in to your cluster use `oc login -u kubeadmin -p ` in your terminal. The password can be found on the Openshift console web page. On the upper right corner of the toolbar, there you will find your username `kubeadmin`, click on it to get your password. +- Alternatively, you can ssh into your cluster with the public IP address of the master node and kubeadmin password. + +### Creating an Application +- Create a simple python file app.py as follows +``` +from flask import Flask +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return 'Hello, World!' + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=8080) +``` + +- Create a requirements file called requirements.txt: +``` +Flask==2.1.0 +``` + +- Create a docker file named Dockerfile as follows: +``` +FROM python:3.9-slim + +WORKDIR /app +COPY . . + +RUN pip install --no-cache-dir -r requirements.txt + +CMD ["python", "app.py"] +``` + +### Deploying an application + +Now, we will create an image and push the image to our registry. In order to do so, we need to find our registry name, username and password +- `oc get route -n openshift-image-registry` will provide you with the name of your image registry in your Openshift Cluster. +- `oc whoami -t` will output the password for the registry + +Once you have your registry's URL, username and password, you can login with the following command: +``` +docker login -u -p $(oc whoami -t) +``` + +Then, we can build our image and push it to the registry with the following commands: +``` +docker build -t /hello-world-app +docker push /hello-world-app +``` + +Now, lets deploy an application using this image. + +``` +oc new-app /hello-world-app +``` + +### Accessing application + +In order to the application and make it accessible, we will have to "expose" the service. This can be done with the following command: +``` +oc expose svc/hello-world-app +``` + +With the following command, you can find the URL where the app has been deployed, i.e. there will be a "Hello World!" +``` +oc get route | grep hello-word-app +``` + + + +## Additional Resources +You can find additional information and details here: + +- [Openshift 101: Introduction, architecture, and operators](https://developer.ibm.com/blogs/openshift-101-architecture) +- [OpenShift 101: Web console and CLI](https://developer.ibm.com/blogs/openshift-101-web-console-and-cli) + + + From 6262824a560cf12971787bb2e391bacf9246e4c7 Mon Sep 17 00:00:00 2001 From: thakertanya <60537067+thakertanya@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:44:51 -0500 Subject: [PATCH 3/6] Update OpenShift.md --- Topics/Tech_Stacks/OpenShift.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Topics/Tech_Stacks/OpenShift.md b/Topics/Tech_Stacks/OpenShift.md index 93b74b574..030238c26 100644 --- a/Topics/Tech_Stacks/OpenShift.md +++ b/Topics/Tech_Stacks/OpenShift.md @@ -1,6 +1,6 @@ - ## Table of Contents +- [Understanding Containers & Kubernetes](#understanding-containers-&-kubernetes) - [Introduction](#introduction-to-openshift) - [Key Features](#key-features) - [Architecture](#architecture) @@ -9,12 +9,17 @@ - [Accessing your Cluster](#accessing-your-cluster) - [Creating an Application](#creating-an-application) - [Deploying an application](#deploying-an-application) - - [Accessing application](#accessing-application)z + - [Accessing application](#accessing-application) - [Additional Resources](#additional-resources) +## Understanding Containers & Kubernetes + +Containers are units that can run applications and their dependencies in isolated environments. They package an application and its dependencies together, ensuring consistency across different environments. An example of containerization technology is Docker. +Kubernetes is an open-source container orchestration platform. It provides a framework for automating the deployment, scaling, and management of containerized applications. + ## Introduction to OpenShift -Red Hat OpenShift is an open source container application platform that runs on Red Hat Enterprise Linux CoreOS (RHCOS). It is built on existing Kubernetes features with additional features specific to OpenShift. It takes care of scaling, monitoring, logging, and metering functions like Kubernetes but also provides an in cluster docker registry, developer friendly environment amongst other features. +Red Hat OpenShift is an open-source container application platform that runs on Red Hat Enterprise Linux CoreOS (RHCOS). It is built on existing Kubernetes features with additional features specific to OpenShift. It takes care of scaling, monitoring, logging, and metering functions like Kubernetes but also provides an in-cluster docker registry, developer-friendly environment, amongst other features. ## Key Features: @@ -82,6 +87,7 @@ def hello_world(): if __name__ == '__main__': app.run(host='0.0.0.0', port=8080) ``` +Flask is a framework that is used to create web application. The code above creates a simple web app that prints Hello Word. - Create a requirements file called requirements.txt: ``` @@ -99,6 +105,7 @@ RUN pip install --no-cache-dir -r requirements.txt CMD ["python", "app.py"] ``` +The docker file above is essentially used to build a docker image. It first imports a python base image for the container since it the application requires python to run. Then, it sets the working directory inside the container to /app. The `COPY . .` line copies the content of the /app folder to the container (i.e. app.py and requirements.txt). Then, it installs python dependencies based on the requirements.txt file. Finally, it runs the application. ### Deploying an application @@ -106,6 +113,8 @@ Now, we will create an image and push the image to our registry. In order to do - `oc get route -n openshift-image-registry` will provide you with the name of your image registry in your Openshift Cluster. - `oc whoami -t` will output the password for the registry +**Note**: Openshift CLI is often abbreviated as oc thus it is the primary tool to interact with openshift + Once you have your registry's URL, username and password, you can login with the following command: ``` docker login -u -p $(oc whoami -t) @@ -132,7 +141,7 @@ oc expose svc/hello-world-app With the following command, you can find the URL where the app has been deployed, i.e. there will be a "Hello World!" ``` -oc get route | grep hello-word-app +oc get route | grep hello-world-app ``` From 13c8987f6be8fa484bbb48caa62b886f7521bbc1 Mon Sep 17 00:00:00 2001 From: thakertanya <60537067+thakertanya@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:45:14 -0500 Subject: [PATCH 4/6] Update OpenShift.md --- Topics/Tech_Stacks/OpenShift.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Topics/Tech_Stacks/OpenShift.md b/Topics/Tech_Stacks/OpenShift.md index 030238c26..f94291b28 100644 --- a/Topics/Tech_Stacks/OpenShift.md +++ b/Topics/Tech_Stacks/OpenShift.md @@ -1,6 +1,6 @@ ## Table of Contents -- [Understanding Containers & Kubernetes](#understanding-containers-&-kubernetes) +- [Understanding Containers & Kubernetes](#understanding-containers--kubernetes) - [Introduction](#introduction-to-openshift) - [Key Features](#key-features) - [Architecture](#architecture) From 44a24ff9d94be580054e7ce8c233914e698115d0 Mon Sep 17 00:00:00 2001 From: thakertanya <60537067+thakertanya@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:46:56 -0500 Subject: [PATCH 5/6] Update Tech_Stacks.md with link to Openshift --- Topics/Tech_Stacks.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Topics/Tech_Stacks.md b/Topics/Tech_Stacks.md index 8e29f2bac..a3ead1c08 100644 --- a/Topics/Tech_Stacks.md +++ b/Topics/Tech_Stacks.md @@ -41,3 +41,4 @@ ### [Setting up Firebase and Intro to Firestore](./Tech_Stacks/Firebase_and_Firestore.md) ### [Learning Odata](./Tech_Stacks/Odata.md) ### [Learning Github Actions](./Development_Process/Github_Actions.md) +### [Introduction to OpenShift](./Tech_Stacks/OpenShift.md) From 562dd983ce02bf62f09c218928bff7c310247357 Mon Sep 17 00:00:00 2001 From: thakertanya <60537067+thakertanya@users.noreply.github.com> Date: Thu, 30 Nov 2023 00:52:36 -0500 Subject: [PATCH 6/6] Update OpenShift.md fix typos --- Topics/Tech_Stacks/OpenShift.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Topics/Tech_Stacks/OpenShift.md b/Topics/Tech_Stacks/OpenShift.md index f94291b28..5c8cc556d 100644 --- a/Topics/Tech_Stacks/OpenShift.md +++ b/Topics/Tech_Stacks/OpenShift.md @@ -29,7 +29,7 @@ Red Hat OpenShift is an open-source container application platform that runs on - **Container Orchestration**: It uses Kubernetes to automate the deployment, scaling, and management of containers. These features allow developers to focus on application code rather than infrastructure. -- **Developer**: It provides several features that enhances development process by provided a user-friendly UI that allows developers to manage application, resources, and pod health. Additionally, it includes Source-to-Image (S2I) a tool which simplifies building and deploying container images from source code. +- **Developer**: It provides several features that enhances development process by providing a user-friendly UI that allows developers to manage application, resources, and pod health. Additionally, it includes Source-to-Image (S2I) a tool which simplifies building and deploying container images from source code. - **Operator**: This is a key feature that distinguishes OpenShift from Kubernetes. Operators are a method for packaging and running Kubernetes applications. It greatly simplifies installation, updates, and management. In essence, it automates the entire lifecycle management process. @@ -50,7 +50,7 @@ This layer is an abstraction provided by Kubernetes primarily used to expose and - **API and authentication**: To ensure the security of the cluster, any administration/ access request goes through the API. - **Data Store**: Stores the state and information related to the environment and application. - **Scheduler**: Determines where pods and jobs will run while considering current memory, CPU, and other environment factors. -**Health/scaling**: Monitors the well-being of pods and adjusts their scale according to CPU utilization. In the event of pod failure, the primary node initiates an automatic restart. In case of frequent failures, the pod is flagged as bas and is temporarily withheld from further restart attempts. +**Health/scaling**: Monitors the well-being of pods and adjusts their scale according to CPU utilization. In the event of pod failure, the primary node initiates an automatic restart. In case of frequent failures, the pod is flagged as bad and is temporarily withheld from further restart attempts. #### Worker node @@ -87,7 +87,7 @@ def hello_world(): if __name__ == '__main__': app.run(host='0.0.0.0', port=8080) ``` -Flask is a framework that is used to create web application. The code above creates a simple web app that prints Hello Word. +Flask is a framework that is used to create web application. The code above creates a simple web app that prints Hello World. - Create a requirements file called requirements.txt: ```