Cloud Experts Documentation

Azure DevOps with Managed OpenShift

This content is authored by Red Hat experts, but has not yet been tested on every supported configuration.

Author: Kevin Collins

Last edited: 03/14/2023

Adopted from Hosting an Azure Pipelines Build Agent in OpenShift and Kevin Chung Azure Pipelines OpenShift exampleexternal link (opens in new tab)

Azure DevOps is a very popular DevOps tool that has a host of features including the ability for developers to create CI/CD pipelines.

In this document, I will show you how to connect your Managed OpenShift Cluster to Azure DevOps end-to-end including running the pipeline build process in the cluster, setting up the OpenShift internal image registry to store the images, and then finally deploy a sample application. To demonstrate the flexibility of Azure DevOps, I will be deploying to a ROSA cluster, however the same procudures will apply to if you choose to deploy to any other OCP Cluster.

Prerequisites

  • A Public Cloud subscription (Azure Subscription)
  • Azure Dev Ops instance
  • An OpenShift Cluster (to create an Azure Red Hat OpenShift (ROSA) cluster, click here )

Clone example application and configuration files

Configure Azure Devops

While logged into your Azure DevOps Organizationexternal link (opens in new tab) , create a new project. The examples in this document will assume the project is named azure-pipelines-openshift ADO New Project

Obtain a personal access token. While in Azure DevOPs, select Personal Access Token under User Settings. azpat

On the next screen, create a New Token. In this example, we will create a token with Full Access. Once you click create your token will be displayed. Make sure to store it somewhere safe as you won’t be able to see it again.
create-pat

Set Azure DevOps environment variables for your Azure DevOps instance

Host an Azure Pipelines Build Agent in OpenShift

note: this is an abreviated version of this blog by Kevin Chung and Mark Dunnett.

In this step, we will configure OpenShift to build our container image leveraging Universal Base Images ( UBI )

Configure the Azure DevOps build agent with OpenShift

Start by creating a new project

Create the following artifacts that include a wrapper script for the build agent and an example BuildConfig that will build a .NET application using the Red Hat Universal Based Image for .NET

Update the azure build agent image

As a cluster admin, create a service account for the build agent

Make sure to be in the root directory of the Azure Pipelines OpenShift git repository you cloned in the previous step.

Create a secret with your Azure DevOps credentials

Deploy the azure build agent

Make sure the build agent is running:

expected output:

Create an Azure DevOps Pipeline

The pipeline we will create has three steps.

  1. build the image on the OpenShift cluster
  2. push the image to the internal registry of the OpenShift cluster
  3. deploy the application to the cluster

Before we can do steps 2 and 3, we need to create a service account in OpenShift to both authenticate with OpenShift to push an image and also the internal image registry.

Create a new project for our application

Create a service account and grant it cluster-admin privileges

Create a secret token for the service account

Retrieve the secret name that we just created that was a token associated with it.

expected output:

note: your output will have a different name

Describe the secret to retrieve the token:

expected output:

Copy the value of the token.

Retrieve the host of your cluster image regstry.

Expected Output:

Get the cluster api endpoint

expected output:

note the api server url for usage later

Configure Azure DevOps service connections for the registry and OpenShift

From Azure DevOps, click on Project settings ( the gear icon ), then Service Connections, and finally Create service connection.

create-service-connection

Select Docker registry

docker-registry

Enter the settings we retrieved in the previous step:

  • Select Others for Docker Registry
  • Docker Registry - make sure to add https:// in front of the hostname you retrieved
  • Docker ID - the service account you created
  • Docker Password - the service account token
  • Service connection name - enter openshift-registry

Next, let’s create a another serivce connection for our cluster.

Click New service connection:

new-service-connection

Select Kubernetes

select-kubernetes
  • Server Url - the api server you retrieved in the previous step

  • Secret - using the name of the secret that we retieved earlier that has token in the name run:

    Copy the entire json results and paste it in the Secret field

  • Service connection name - select openshift

openshift-settings

Create an Azure DevOps Pipeline

We will be deploying an application from a GitHub repo. Fork the following Git Repo: https://github.com/rh-mobb/azure-pipelines-openshiftexternal link (opens in new tab)

In Azure DevOPs, click on Pipelines and then Create Pipeline

new-pipeline

On the next screen, select GitHub

pipeline-github

On the next screen, select your github repo that you forked to.

Review the azure-pipelines.yml file and then click run.

If this is the first time running, you might see a message like the following:

build-permissions

Clickad on the Build and Push Image tile, and then view permissions, and grat permissions to both the Default queue and the openshift-registry service connection.

grant-build-permissions

Like we saw with permissions on the build and push, we also need to give permissions to deploy.

permission-deploy

On the next screen, click on Permit to give access to the OpenShift connection.

grand-openshift-permission

After a few minutes, you should see both the Build and Push Image and Deploy to DEV stages complete.

successful-pipeline

To verify the application was successfully deployed in openshift run:

expected output:

Interested in contributing to these docs?

Collaboration drives progress. Help improve our documentation The Red Hat Way.

Red Hat logo LinkedIn YouTube Facebook Twitter

Products

Tools

Try, buy & sell

Communicate

About Red Hat

We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Subscribe to our newsletter, Red Hat Shares

Sign up now
© 2023 Red Hat, Inc.