[OpenShift Origin][openshift] is an open source container application
platform created by [RedHat], based on [kubernetes] and [Docker]. That means
you can host your own PaaS for free and almost with no hassle.
In this tutorial, we will see how to deploy GitLab in OpenShift using GitLab's
official Docker image while getting familiar with the web interface and CLI
tools that will help us achieve our goal.
For a video demonstration on installing GitLab on Openshift, check the article [In 13 minutes from Kubernetes to a complete application development tool](https://about.gitlab.com/2016/11/14/idea-to-production/).
---
## Prerequisites
OpenShift 3 is not yet deployed on RedHat's offered Online platform ([openshift.com]),
so in order to test it, we will use an [all-in-one Virtualbox image][vm] that is
offered by the OpenShift developers and managed by Vagrant. If you haven't done
already, go ahead and install the following components as they are essential to
test OpenShift easily:
- [VirtualBox]
- [Vagrant]
- [OpenShift Client][oc] (`oc` for short)
It is also important to mention that for the purposes of this tutorial, the
latest Origin release is used:
- **oc** `v1.3.0` (must be [installed][oc-gh] locally on your computer)
- **openshift** `v1.3.0` (is pre-installed in the [VM image][vm-new])
- **kubernetes** `v1.3.0` (is pre-installed in the [VM image][vm-new])
>**Note:**
If you intend to deploy GitLab on a production OpenShift cluster, there are some
limitations to bare in mind. Read on the [limitations](#current-limitations)
section for more information and follow the linked links for the relevant
discussions.
Now that you have all batteries, let's see how easy it is to test OpenShift
on your computer.
## Getting familiar with OpenShift Origin
The environment we are about to use is based on CentOS 7 which comes with all
the tools needed pre-installed: Docker, kubernetes, OpenShift, etcd.
### Test OpenShift using Vagrant
As of this writing, the all-in-one VM is at version 1.3, and that's
what we will use in this tutorial.
In short:
1. Open a terminal and in a new directory run:
```sh
vagrant init openshift/origin-all-in-one
```
1. This will generate a Vagrantfile based on the all-in-one VM image
1. In the same directory where you generated the Vagrantfile
enter:
```sh
vagrant up
```
This will download the VirtualBox image and fire up the VM with some preconfigured
values as you can see in the Vagrantfile. As you may have noticed, you need
plenty of RAM (5GB in our example), so make sure you have enough.
Now that OpenShift is setup, let's see how the web console looks like.
### Explore the OpenShift web console
Once Vagrant finishes its thing with the VM, you will be presented with a
message which has some important information. One of them is the IP address
of the deployed OpenShift platform and in particular <https://10.2.2.2:8443/console/>.
Open this link with your browser and accept the self-signed certificate in
order to proceed.
Let's login as admin with username/password `admin/admin`. This is what the
landing page looks like:
![openshift web console](img/web-console.png)
You can see that a number of [projects] are already created for testing purposes.
If you head over the `openshift-infra` project, a number of services with their
respective pods are there to explore.
![openshift web console](img/openshift-infra-project.png)
We are not going to explore the whole interface, but if you want to learn about
the key concepts of OpenShift, read the [core concepts reference][core] in the
official documentation.
### Explore the OpenShift CLI
OpenShift Client (`oc`), is a powerful CLI tool that talks to the OpenShift API
and performs pretty much everything you can do from the web UI and much more.
Assuming you have [installed][oc] it, let's explore some of its main
functionalities.
Let's first see the version of `oc`:
```sh
$ oc version
oc v1.3.0
kubernetes v1.3.0+52492b4
```
With `oc help` you can see the top level arguments you can run with `oc` and
interact with your cluster, kubernetes, run applications, create projects and
much more.
Let's login to the all-in-one VM and see how to achieve the same results like
when we visited the web console earlier. The username/password for the
administrator user is `admin/admin`. There is also a test user with username/
password `user/user`, with limited access. Let's login as admin for the moment:
```sh
$ oc login https://10.2.2.2:8443
Authentication required for https://10.2.2.2:8443 (openshift)
Username: admin
Password:
Login successful.
You have access to the following projects and can switch between them with 'oc project <projectname>':
* cockpit
* default (current)
* delete
* openshift
* openshift-infra
* sample
Using project "default".
```
Switch to the `openshift-infra` project with:
```sh
oc project openshift-infra
```
And finally, see its status:
```sh
oc status
```
The last command should spit a bunch of information about the statuses of the
pods and the services, which if you look closely is what we encountered in the
second image when we explored the web console.
You can always read more about `oc` in the [OpenShift CLI documentation][oc].
### Troubleshooting the all-in-one VM
Using the all-in-one VM gives you the ability to test OpenShift whenever you
want. That means you get to play with it, shutdown the VM, and pick up where
you left off.
Sometimes though, you may encounter some issues, like OpenShift not running
when booting up the VM. The web UI may not responding or you may see issues
when trying to login with `oc`, like:
```
The connection to the server 10.2.2.2:8443 was refused - did you specify the right host or port?
```
In that case, the OpenShift service might not be running, so in order to fix it:
1. SSH into the VM by going to the directory where the Vagrantfile is and then
run:
```sh
vagrant ssh
```
1. Run `systemctl` and verify by the output that the `openshift` service is not
running (it will be in red color). If that's the case start the service with:
```sh
sudo systemctl start openshift
```
1. Verify the service is up with:
```sh
systemctl status openshift -l
```
Now you will be able to login using `oc` (like we did before) and visit the web
console.
## Deploy GitLab
Now that you got a taste of what OpenShift looks like, let's deploy GitLab!
### Create a new project
First, we will create a new project to host our application. You can do this
either by running the CLI client:
```bash
$ oc new-project gitlab
```
or by using the web interface:
![Create a new project from the UI](img/create-project-ui.png)
If you used the command line, `oc` automatically uses the new project and you
can see its status with:
```sh
$ oc status
In project gitlab on server https://10.2.2.2:8443
You have no services, deployment configs, or build configs.
Run 'oc new-app' to create an application.
```
If you visit the web console, you can now see `gitlab` listed in the projects list.
The next step is to import the OpenShift template for GitLab.
### Import the template
The [template][templates] is basically a JSON file which describes a set of
related object definitions to be created together, as well as a set of
parameters for those objects.
The template for GitLab resides in the Omnibus GitLab repository under the
docker directory. Let's download it locally with `wget`: