Pages

Sunday, December 24, 2023

Deploying Applications on OpenShift: A Step-by-Step Guide

OpenShift, Red Hat's container application platform, offers a streamlined environment for deploying and managing applications. This guide will walk you through deploying a MySQL database and a Ruby application using the oc command-line tool.

Prerequisites:

  • An active OpenShift cluster.
  • oc command-line tool installed and configured.

Step 1: Port Forwarding with OpenShift

Before deploying your applications, you might want to access services like databases from your local machine. OpenShift’s oc port-forward command allows you to access remote services locally.

Forward a MySQL service port to your local machine:

oc port-forward mysql-openshift-1-glqrp 3306:3306

This command forwards the local port 3306 to the same port on the pod mysql-openshift-1-glqrp, allowing local applications to interact with the MySQL database as if it were running on your machine.

Step 2: Deploying MySQL

Deploying a MySQL instance on OpenShift can be done with a single oc new-app command.

Create a new MySQL application:

oc new-app mysql MYSQL_USER=user MYSQL_PASSWORD=pass MYSQL_DATABASE=testdb -l db=mysql

This command creates a new MySQL application with the specified user, password, and database name. The -l db=mysql portion labels the application for easier management.

Step 3: Deploying a Ruby Application

Deploying an application from a source code repository is straightforward with OpenShift.

Create a new Ruby application from a GitHub repository:

oc new-app https://github.com/openshift/ruby-hello-world --name=ruby-hello

This command fetches the code from the specified GitHub repository and initiates a build and deployment process.

Step 4: Deploying a Persistent MySQL Instance

For applications requiring data persistence, OpenShift provides templates for deploying databases with persistent storage.

Deploy a persistent MySQL instance:

oc new-app \

--template=mysql-persistent \

-p MYSQL_USER=user1 -p MYSQL_PASSWORD=mypa55 -p MYSQL_DATABASE=testdb \

-p MYSQL_ROOT_PASSWORD=r00tpa55 -p VOLUME_CAPACITY=10Gi

This command creates a new MySQL application with persistent storage, ensuring that your data survives pod restarts and redeployments.


Step 5: Checking Your Application Status

After deploying your applications, it's essential to check their status and ensure everything is running as expected.

Check the status of your applications:

oc status

This command provides a quick overview of the current state of your applications, including running pods, services, and routes.

Conclusion

OpenShift simplifies the process of deploying and managing applications in a containerized environment. By utilizing the oc command-line tool, you can quickly deploy a MySQL database and a Ruby application, ensuring your services are up and running in no time. Remember, while these commands provide a quick way to get started, always tailor your deployments to the specific needs of your application and environment. Happy deploying!

No comments:

Post a Comment