This post was originally written by Akram Ben Aissi in his blog: http://akrambenaissi.com/2016/02/23/deploy-gitlab-on-openshift/
GitLab is a great web git repository application for everyone that wants to run his own Git repository at home or office. Unfortunately, the home made GitLab installation requires some skills that I don’t have time to learn. The good thing is that some Docker images exists on Docker Hub, even the one from GitLab team. In this blog post, we will use
the sameersbn docker-gitlab image which demonstrated to working very well, supports volumes and also bring separate containers for postgresql and redis.
Installing postgres
For convenience reasons (and also for support if your are using OpenShift Enterprise), we are using the PostgreSQL image provided by OpenShift team to start ou postgresql instance. The image supports persistent volumes and will create the Persistent Volume Claim for you.
Simply use the oc new-app command to get your PostgreSQL instance up and running. Note that there an issue with this image that runs with a predefined user, you will have to allow it to run as AnyUid by using the corresponding Security Context Constraint.
oc new-app --template=postgresql-persistent \
-p POSTGRESQL_USER=admin,POSTGRESQL_PASSWORD=redhat,POSTGRESQL_DATABASE=gitlab
--> Deploying template postgresql-persistent in project openshift for "postgresql-persistent"
With parameters:
DATABASE_SERVICE_NAME=postgresql
POSTGRESQL_USER=admin
POSTGRESQL_PASSWORD=admin
POSTGRESQL_DATABASE=gitlab
VOLUME_CAPACITY=512Mi
--> Creating resources ...
Service "postgresql" created
Persistentvolumeclaims "postgresql" created
DeploymentConfig "postgresql" created
Configuring Security Context
Some of the containers that we will use need to run as root (GitLab) or any other user (Postgres has hardcoded user 26 but this will be fixed soon).
Hence, it is required to used the project’s service account (here we created a project called gitlab) to the SCC named anyuid.
oc edit scc anyuid
[...]
supplementalGroups:
type: RunAsAny
users:
- system:serviceaccount:gitlab:default
This configuration will work for postgres and gitlab image.
Installing Redis
Use the oc new-app command here again and directly pass it the Docker image name and you will get a redis instance up and running in seconds.
oc new-app sameersbn/redis
[...]
Service "redis" created
--> Success
Run 'oc status' to view your app.
<pre>
The new-app command will create Services, EndPoints and associated pods.
It is still required to add a persistent volume to the Deployment Configuration using the following command:
<pre>
oc volume dc/redis --add --overwrite -t persistentVolumeClaim \
--claim-name=redis-data --name=redis-volume-1 \
--mount-path=/var/lib/redis
Installing GitLab itself
The sameersbn image allows several parameters to be injected in order to configure the GitLab instance to be created.
For some reasons Services name resolutions are not working with the provided startup script, although going into the container and pinging the services works.
So, we will inject the PostgreSQL and Redis Services IP addresses manually using the parameters.
To get the Services IP addresses:
oc get svc postgresql redis
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
postgresql 172.30.25.83 <none> 5432/TCP app=postgresql,deploymentconfig=postgresql 1h
redis 172.30.198.140 <none> 6379/TCP app=redis,deploymentconfig=redis 1h
Use these IP addresses to start the GitLab container, again by using the new-app command:
One important thing to note: You need to use the –name parameter and the name to anything else than gitlab otherwise all your OpenShift injected environment variables will be named GITLAB_* , and gitlab already uses some of those. In our case the variables will be name GITLAB_CE_* which fixes troubles.
oc new-app sameersbn/gitlab --name=gitlab-ce
-e 'GITLAB_HOST=http://gitlab.apps.mycompany.com' \
-e 'DB_TYPE=postgres' -e 'DB_HOST=172.30.25.83' \
-e 'DB_PORT=5432' -e 'DB_NAME=gitlab' -e 'DB_USER=admin' \
-e 'DB_PASS=admin' -e 'REDIS_HOST=172.30.198.140 -e 'REDIS_PORT=6379' \
-e 'GITLAB_SECRETS_DB_KEY_BASE=1234567890' -e 'SMTP_ENABLED=true' \
-e 'SMTP_HOST=smtp.mycompany.com' -e 'SMTP_PORT=25' \
-e 'GITLAB_EMAIL=no-reply@mycompany.com'
[...]
Service "gitlab-ce" created
--> Success
Run 'oc status' to view your app.
Of course, do not forget to add the volumes to make your repositories and logs persistent:
oc volumes dc/gitlab-ce --add --claim-name=gitlab-log --mount-path=/var/log/gitlab \
-t persistentVolumeClaim --overwrite
oc volumes dc/gitlab-ce --add --claim-name=gitlab-data --mount-path=/home/git/data \
-t persistentVolumeClaim --overwrite
A word on persistent volumes
The persistent volumes that you will have to create may require specific configuration: This is because both postgresql and postgres uses some hardcoded uid/gid and tries to make chown on some files.
If you are using NFS backed Persistent Volume, you will run into permission denied issues on chmod and chown.
To bypass this, you will have to add supplementalGroups in the DeploymentConfig’s SecurityContext:
– for postgres: add 26
– for gitlab-ce: add 1000
You will have then to create the tow persistent volumes and chown to those UID/GID and use all_squash option.
chown -R 26:26 /srv/nfs/pv0001
chow -R 1000:1000 /srv/nfs/pv0002cat >> /etc/exports << EOF
/srv/nfs/pv0001 *(rw,all_squash)
/srv/nfs/pv0002 *(rw,all_squash)
EOFexportfs -a
Create then your PV and PVC using the following definitions:
apiVersion: v1
kind: PersistentVolume
metadata:
creationTimestamp: null
name: pv0005
spec:
accessModes:
- ReadWriteOnce
- ReadWriteMany
capacity:
storage: 8Gi
claimRef:
apiVersion: v1
kind: PersistentVolumeClaim
name: gitlab-data
namespace: gitlab
nfs:
path: /srv/nfs/pv0005
server: nfs-server.mycompany.com
persistentVolumeReclaimPolicy: Retain
status: {}
And for the PVC:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
name: gitlab-data
spec:
accessModes:
- ReadWriteOnce
- ReadWriteMany
resources:
requests:
storage: 5Gi
status: {}
Now, you have your GitLab running in OpenShift on the URL http://gitlab.apps.mycompany.com ! enjoy.
Author
Akram Ben Aissi
Cloud and Platform Architect,
Red Hat Consulting
LinkedIn: https://linkedin.
Twitter: @akrambenaissi
GitHub: https://github.com/akram
About the author
More like this
Browse by channel
Automation
The latest on IT automation that spans tech, teams, and environments
Artificial intelligence
Explore the platforms and partners building a faster path for AI
Open hybrid cloud
Explore how we build a more flexible future with hybrid cloud
Security
Explore how we reduce risks across environments and technologies
Edge computing
Updates on the solutions that simplify infrastructure at the edge
Infrastructure
Stay up to date on the world’s leading enterprise Linux platform
Applications
The latest on our solutions to the toughest application challenges
Original shows
Entertaining stories from the makers and leaders in enterprise tech
Products
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud services
- See all products
Tools
- Training and certification
- My account
- Developer resources
- Customer support
- Red Hat value calculator
- Red Hat Ecosystem Catalog
- Find a partner
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.
Select a language
Red Hat legal and privacy links
- About Red Hat
- Jobs
- Events
- Locations
- Contact Red Hat
- Red Hat Blog
- Diversity, equity, and inclusion
- Cool Stuff Store
- Red Hat Summit