OPENSHIFT — CONTAINER PLATFORM
INTRODUCTION:
Red Hat OpenShift is a unified platform to build, modernize, and deploy applications at scale.
When we install OpenShift, Kubernetes is automatically installed as it is the underlying container orchestration platform that powers OpenShift. OpenShift builds on top of Kubernetes and adds additional features and functionalities to enhance the developer experience and provide a more comprehensive platform for containerized applications.
OpenShift includes its own distribution of Kubernetes, which is pre-configured and optimized for running on OpenShift.
ARCHITECTURE:
OpenShift architecture consists of several key components that work together to provide a robust and scalable platform for deploying and managing applications. Let’s break down the main components:-
- Master Nodes: The Master nodes are the central control plane of the OpenShift cluster. They manage the overall cluster operations, orchestrate deployments, and handle administrative tasks. The master nodes include components like the API server, controller manager, and etcd, which is a distributed key-value store for storing cluster data.
- Worker Nodes: Worker nodes are where the application workloads are executed. They run containers and handle the actual running of applications. Each worker node has a container runtime engine, such as Docker or containerd, to manage containers. They also have a component called the Kubelet, which communicates with the master nodes and handles container lifecycle management.
- Kubernetes: OpenShift is built on top of Kubernetes, an open-source container orchestration platform. Kubernetes manages and schedules containers on the worker nodes, ensuring high availability, scalability, and resource efficiency. It provides features like load balancing, scaling, and container networking.
- Containers: OpenShift uses containers, which are lightweight and isolated environments that package applications and their dependencies. Containers provide consistency and portability, allowing applications to run reliably across different environments. OpenShift supports popular container technologies like Docker and containerd.
- Operators: Operators are an important concept in OpenShift. They are software extensions that help automate the management of complex applications and services running on OpenShift. Operators use custom resources and controllers to automate tasks like installation, configuration, scaling, and upgrades of applications.
- Projects and Namespaces: OpenShift uses projects and namespaces to provide logical separation and multi-tenancy. Projects are organizational units that group related applications, resources, and users. Namespaces, on the other hand, are Kubernetes constructs that provide isolation and resource quotas within a project.
- Image Registry: OpenShift has an integrated image registry that allows developers to store and distribute container images. The registry provides a central repository for sharing and versioning container images, making it easy to deploy and update applications.
- Web Console and CLI: OpenShift provides a web-based console and a command-line interface (CLI) for managing and interacting with the platform. The web console offers a graphical user interface (GUI) for performing various operations, while the CLI allows automation and scripting of tasks.
MANAGING OPENSHIFT:-
OpenShift cluster can be managed using -
- WebUI or
- Openshift client (oc).
About the OpenShift CLI:
With OpenShift command-line interface (CLI), the oc
command, we can create applications and manage OpenShift Container Platform projects from a terminal.
Installing the OpenShift CLI on Linux:
- Navigate to the OpenShift Container Platform downloads page on the Red Hat Customer Portal.
- Select the appropriate version in the Version drop-down menu.
- Click Download Now next to the OpenShift v4.8 Linux Client entry and save the file.
4. Unpack the archive:
$ tar xvzf <file>
5. Place the oc
binary in a directory that is on your PATH
.
To check your PATH
, execute the following command:
$ echo $PATH
After you install the OpenShift CLI, it is available using the oc
command:
$ oc <command>
Logging in to the OpenShift CLI:
We can log in to the OpenShift CLI (oc
) to access and manage your cluster.
Prerequisites:
- You must have access to an OpenShift Container Platform cluster.
- You must have installed the OpenShift CLI (
oc
).
Procedure
- Enter the
oc login
command and pass in a user name:
$ oc login -u user1
2. When prompted, enter the required information:
Using the OpenShift CLI
Review the following sections to learn how to complete common tasks using the openshift CLI ( oc ).
Creating a project:
Use the oc new-project
command to create a new project ( namespace).
# create new project.
$ oc new-project my-project
# To change to the project from the command line run the command.
$ oc project myproject
# To fetch the pod details without getting inside the project.
$ oc get pods -n <<Project_Name>>
Example output:
Now using project "my-project" on server "https://openshift.example.com:6443".
Viewing the current project
Use the oc project
command to view the current project.
$ oc project
Example output:
Using project "my-project" on server "https://openshift.example.com:6443".
# Viewing the status for the current project:
Use the oc status
command to view information about the current project, such as services, deployments, and build configs.
$ oc status
Example output:-
In project my-project on server https://openshift.example.com:6443
svc/cakephp-ex - 172.30.236.80 ports 8080, 8443
dc/cakephp-ex deploys istag/cakephp-ex:latest <-
bc/cakephp-ex source builds https://github.com/sclorg/cakephp-ex on openshift/php:7.2
deployment #1 deployed 2 minutes ago - 1 pod
3 infos identified, use 'oc status --suggest' to see details.
# Creating a new app:
Use the oc new-app
command to create a new application.
$ oc new-app https://github.com/sclorg/cakephp-ex
Example output:
--> Found image 40de956 (9 days old) in imagestream "openshift/php" under tag "7.2" for "php"
... Run 'oc status' to view your app.
# Viewing pods:
Use the oc get pods
command to view the pods for the current project.
When you run oc
inside a pod and do not specify a namespace, the namespace of the pod is used by default.
$ oc get pods -o wide
Example output
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
cakephp-ex-1-build 0/1 Completed 0 5m45s 10.131.0.10 ip-10-0-141-74.ec2.internal <none>
cakephp-ex-1-deploy 0/1 Completed 0 3m44s 10.129.2.9 ip-10-0-147-65.ec2.internal <none>
cakephp-ex-1-ktz97 1/1 Running 0 3m33s 10.128.2.11 ip-10-0-168-105.ec2.internal <none>
# Viewing pod logs
Use the oc logs
command to view logs for a particular pod.
$ oc logs cakephp-ex-1-deploy
Example output
--> Scaling cakephp-ex-1 to 1
--> Success
# Get the NODE details:
To get node details run the below command.
$ oc get nodes
Show the system resource usage:
For this we need admin command
# This command shows the usage statistics of resource on the server.
$ oc admin top
# To check the resource usage for node
$ oc adm top node
# To shoe the metrics for a given node
$ oc adm top node <<NODE_NAME>>
Using the labels find the system’s resource usage. In this case for all worker nodes:
# Get Inside the worker node:
To start a shell session on the working node, and then use the chroot command to enter the local file system of the host.
$ oc debug node/<<NODE_NAME>>
# Describe the pod the see pod information:
We can describe the pod with below command.
# Get insidde the project.
$ oc project <<project_name>>
# Describe the pod
$ oc describe pod <<Pod_Name>>
# Using the skopeo to find the information about the container image from the events.
$ skopeo inspect <<Registry_URL>>