containersget-started-openshift

Get Started with Bitnami containers on OpenShift

Introduction

OpenShift Online is a container-based platform that can be accessed as a public cloud service. It is designed for individuals and teams that want to deploy a functional Kubernetes cluster on their local computers and use remote services as if they were running locally.

Some of the Bitnami containers have been developed as non-root containers, following the Red Hat guidelines for deploying containers on OpenShift. You can find a wide selection of Bitnami containers in the Red Hat Container Catalog.

This tutorial will walk you through the process of using OpenShift Online to deploy the Bitnami Docker image for PHP-FPM on an OpenShift cluster. Since OpenShift Online offers a free starter plan, you can learn and experiment with OpenShift and Bitnami containers without worrying about being billed.

Overview

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features that are useful for sites of any size, especially for busier sites.

This tutorial shows you how to obtain the Bitnami Docker image for PHP-FPM from the Red Hat Container Catalog and how to push it to and deploy it on an OpenShift cluster using OpenShift Online. But PHP-FPM it is just an example: you can find more Bitnami containers in the Red Hat Container Catalog. They are available to run in the OpenShift deployment model of your choice.

Here are the steps to follow in this tutorial:

  • Step 1: Register with OpenShift Online
  • Step 2: Create a new project
  • Step 3: Obtain the Bitnami PHP-FPM image from the Red Hat Container Catalog and pull it to your OpenShift project
  • Step 4: Deploy the Bitnami Docker PHP-FPM on OpenShift
  • Step 5: Scale up (and down) and perform rolling updates (and rollbacks)

This tutorial assumes that you have basic understanding of Docker containers and Kubernetes.

Step 1: Register with OpenShift Online

At the end of this step, you will have signed up for OpenShift Online with a “Starter Plan” free account. If you already have a Red Hat or an OpenShift account, you may skip this step.

  • Begin by creating an OpenShift account by browsing https://www.openshift.com/ and clicking “Learn More” in the Red Hat OpenShift Online deployment option.
  • You will be redirected to the “Plans & Pricing” page. Select the “Sign up for free” option of the “Starter Plan”:

    Select Starter plan free account

  • In the resulting screen, click the “Sign up for OpenShift Online” link:

    Sign up OpenShift

  • If you already have an OpenShift account, enter your email address or Red Hat login ID and your password. If you don’t, click the “Create one now” link:

    Log In to OpenShift

  • To register for OpenShift Online, enter the required information in the form, accept the terms and conditions, and click “Create my account” to proceed.

    Register for OpenShift

  • The next step is to verify your email address. Once you have done so, to confirm your selection and to finish the registration, click “Confirm Subscription”.

    Confirm your Subscription

Congratulations! Your subscription is now active and ready to operate on OpenShift Online!

Step 2: Create a new project

At the end of this step, you will have created a new project on OpenShift Online.

To start managing containers and creating deployments, you should have, at least, one project created. (Remember that if you chose the “Starter Plan”, the maximum number of projects you can create is just one). Follow these steps to create a new project on OpenShift Online:

  • Log in to OpenShift Online. Then click “Open Web Console”:

    Active subscription

  • To create a new project, click the “+ Create Project” button located in the right-side menu of the screen. This opens a window in which you have to enter a name and a description of the project:

    Create a project

  • Once the project is created, you will see it in the list of available projects:

    List of projects

If you click on the recently created project, you will see the “Overview” screen that shows the different options you have. In this case, “Deploy Image” will be the option selected. To do so it is necessary to push an image to our project. Check the step 3 to learn how to provision your project with a Bitnami PHP-FPM image.

Get started project

Step 3: Obtain the Bitnami PHP-FPM image from the Red Hat Container Catalog and pull it to your OpenShift project

At the end of this step, you will have the command that allows you to pull a Bitnami PHP-FPM image to your OpenShift project and the image ready to deploy from the OpenShift Web Console.

To deploy an image in your project, first you need to pull it to OpenShift. In the Red Hat Container Catalog you can search for the container image you want to deploy and find the specific command you need to pull it to OpenShift Online. Follow these instructions to learn how to obtain a Bitnami Docker image for PHP-FPM.

  • In the Red Hat Container Catalog main page, enter “Bitnami PHP-FPM” in the search box to find the Bitnami PHP-FPM images available.
  • Once you have selected the image you want to deploy, in the resulting screen select the “Get Latest Image” tab and choose “Red Hat OpenShift” from the “Choose your platform” dropdown menu. This displays the oc import-image command for this image:

    Select the latest Docker Image

  • Return to the OpenShift Web Console, click your username and select the “Copy Login Command”:

    OpenShift login command

  • Open a terminal window on your local system and paste the login command. If you have more than one project, execute oc project PROJECTNAME. (Remember that PROJECTNAME is a placeholder for the project where you want to deploy the PHP-FPM image).

Now it is time to add the image to your project “Image Streams”. The image will be available to use in your deployments. To do so:

  • Execute the oc import-image IMAGE/TAG –confirm command you have obtained in the Red Hat Container Catalog. The image will be pulled to your OpenShift project.

TIP: The output of this command will show you the attributes and variables defined for the image.

Pull the MariaDB image to your OpenShift project

Step 4: Deploy the Bitnami Docker PHP-FPM on OpenShift

At the end of this step, you will have a Bitnami PHP-FPM image deployed and running on a OpenShift cluster using OpenShift Online.

Once you have imported the image to OpenShift Online, you can manage and deploy it directly from the Web Console. Follow these steps:

  • On the OpenShift Online Web Console, navigate to your project and click “Builds -> Images”.
  • In the resulting screen, you will see the “Image Streams” screen with a list of all the images that have been pulled to your project. Click “php-fpm-redhat” to see more details:

    PHP-FPM image stream details

  • To deploy the image, back to the “Overview” screen, click “Deploy Image” to start the deployment of PHP-FPM:

    Start PHP-FPM deployment

  • In the “Deploy Image” screen, select “Image Stream Tag”, your project, the image stream, and tag:

    Specific parameters for deployment

  • To set environment variables just scroll down. For demo purposes, this deployment is set to allow an empty password. This is not recommended in production environments. Click “Deploy” to proceed.

  • Once the cluster is successfully deployed, you can see it in the “Overview” screen. Click on it to see the details of the deployment configuration such as the number of pods, network parameters or memory usage:

    Deployment configuration

Congratulations! You have a OpenShift cluster up and running with one PHP-FPM container running in one pod.

Step 5: Scale up (and down) and perform rolling updates (and rollbacks)

At the end of this step, you will have explored some of the possibilities that OpenShift Online offers you to manage and automate your clusters. In this example, you will learn how to scale up and down and how to perform updates on your deployments.

Now that your PHP-FPM cluster is deployed, it is time to explore some of the infinite possibilities that OpenShift offers to manage your Kubernetes clusters easily and quickly. First let’s see how to scale up and down your running deployment.

Scale up (and down)

You can scale up and down your deployment from the OpenShift Online Web Console at any moment without the need of a terminal.

Scale up
  • To scale up your deployment, in the “Overview” screen, click on your deployment to access its information.
  • In the resulting screen, click the “Configuration” tab and you will see the deployment configuration. Edit the number of replicas (pods) you want to add to the cluster:

    Scale up

TIP: In the “Configuration” tab, you can select the option “Add Autoscaler” on the right side of the screen. Use this to automate the deployment scaling. You can specify both the minimum and the maximum number of replicas that your deployment can add depending on the CPU usage.

  • If you return to the “Overview” screen, you see that your deployment has two replicas now. Click on it for more information:

    Scale up

Scroll down to see the “Pods” section:

Pods details

Scale down

You can scroll down from the same “Deployments” screen. To do so:

  • Edit the number of replicas or use the arrows to decrease the number of available pods in your cluster.
  • Once you confirm your selection, the deployment will be updated automatically. This process can take a few minutes.

Perform rolling updates (and rollbacks)

To show you how to perform rolling updates and rollbacks, we will add a new environment variable so we will have two different versions of the deployment. Follow these steps:

Rolling updates
  • Navigate to “Applications -> Deployments” and click the deployment you want to update. In the resulting screen, select the “Environment” tab:

    Edit deployment configuration

  • Scroll down to see the “Environment Variables” section. Click the “Add Value” link and enter the BITNAMI_APP_NAME variable. Add “php-fpm-cluster” as the value for that variable. Click “Save” to make the changes take effect.

    Add a new environment variable

  • Your deployment will be automatically updated. To check the deployment versions, navigate to the left-side menu and click “Applications -> Deployments”.

  • Click the deployment name to see all the versions available and a summary of the changes made:

    Deployment versions

  • To see the new BITNAMI_APP_NAME variable, you can check its YAML file. To do so, select the latest version of the deployment and click “Actions”. Then select “Edit YAML”.

  • Navigate to the containers environment variable specification. You will see the environment variables added from the Web Console:

    Environment variables

Rollbacks

Rollbacks are equally simple. Just need to click on the version you want to return to and in the deployment details screen, click “Roll Back”. This displays a menu with different setting options. Once you have selected the settings, click “Roll Back” to create a new deployment with the same settings as the selected version:

Rollback the deployment

When you view the YAML file to check the environment variables of the new deployment, you will see that revision #2 will have been superseded by a copy of revision #1, but this time it is labelled as revision #3.

To learn more about the topics discussed in this guide, use the links below: