IBM/Kubernetes-container-service-GitLab-sample

Name: Kubernetes-container-service-GitLab-sample

Owner: International Business Machines

Description: This code shows how a common multi-component GitLab can be deployed on Kubernetes cluster. Each component (NGINX, Ruby on Rails, Redis, PostgreSQL, and more) runs in a separate container or group of containers.

Created: 2017-03-24 17:40:15.0

Updated: 2018-05-23 13:28:36.0

Pushed: 2018-05-24 06:46:44.0

Homepage: https://developer.ibm.com/code/patterns/run-gitlab-kubernetes

Size: 1306

Language: Shell

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

GitLab deployment on Kubernetes Cluster

Read this in other languages: ?????? .

This project shows how a common multi-component workload, in this case GitLab, can be deployed on Kubernetes Cluster. GitLab is famous for its Git-based and code-tracking tool. GitLab represents a typical multi-tier app and each component will have their own container(s). The microservice containers will be for the web tier, the state/job database with Redis and PostgreSQL as the database.

By using different GitLab components (NGINX, Ruby on Rails, Redis, PostgreSQL, and more), you can deploy it to Kubernetes. This example is also deployable using Compose for PostgreSQL in Bluemix as the database.

Flow

  1. The user interacts with GitLab via the web interface or by pushing code to a GitHub repository. The GitLab container runs the main Ruby on Rails application behind NGINX and gitlab-workhorse, which is a reverse proxy for large HTTP requests like file downloads and Git push/pull. While serving repositories over HTTP/HTTPS, GitLab utilizes the GitLab API to resolve authorization and access and serves Git objects.

  2. After authentication and authorization, the GitLab Rails application puts the incoming jobs, job information, and metadata on the Redis job queue that acts as a non-persistent database.

  3. Repositories are created in a local file system.

  4. The user creates users, roles, merge requests, groups, and more?all are then stored in PostgreSQL.

  5. The user accesses the repository by going through the Git shell.

Included Components
Objectives

This scenario provides instructions and learning for the following tasks:

Deployment Scenarios
Deploy using Docker

see Deploying Gitlab with Docker

Deploy to Kubernetes

Use Deploying Gitlab to IBM Cloud Private if you wish to install this on IBM Cloud Private, otherwise follow the instructions below.

Create a Kubernetes cluster with either Minikube for local testing, or with IBM Bluemix Container Service to deploy in cloud. The code here is regularly tested against Kubernetes Cluster from Bluemix Container Service using Travis.

If you want to use the Bluemix Container Registry start by Uploading the images to the Bluemix Container Registry.

Deploy using DevOps Toolchain to Kubernetes Cluster from Bluemix Container Service

If you want to deploy the Gitlab directly to Bluemix, click on Deploy to Bluemix button below to create a Bluemix DevOps service toolchain and pipeline for deploying the Gitlab sample, else jump to Steps

Create Toolchain

Please follow the Toolchain instructions to complete your toolchain and pipeline.

Steps
  1. Use Kubernetes to create Services and Deployments
  2. 1.1 Use PostgreSQL in container or
  3. 1.2 Use PostgreSQL from Bluemix
  4. Retrieve external ip and port for GitLab
  5. GitLab is ready! Use GitLab to host your repositories
1. Use Kubernetes to create Services and Deployments for GitLab, Redis, and PostgreSQL

Ensure your kubernetes cluster is reachable by running the kubectl command.

bectl get nodes
             STATUS    AGE       VERSION
x.x          Ready     17h       v1.5.3-2+be7137fd3ad68f

Note: If this step fails see troubleshooting docs at Minikube or IBM Bluemix Container Service.

1.1 Use PostgreSQL in container

If you are using a container image to run PostgreSQL, run the following commands or run the quickstart script ./scripts/quickstart.sh with your Kubernetes cluster.

bectl create -f kubernetes/local-volumes.yaml
bectl create -f kubernetes/postgres.yaml
bectl create -f kubernetes/redis.yaml
bectl create -f kubernetes/gitlab.yaml

After you have created all the services and deployments, wait for 3 to 5 minutes. You can check the status of your deployment on Kubernetes UI. Run kubectl proxy and go to URL 'http://127.0.0.1:8001/ui' to check when the GitLab container becomes ready.

Kubernetes Status Page

Next retrieve your external ip and port for GitLab

1.2 Use PostgreSQL from Bluemix

Use the Bluemix catalog or the bx command to create a service instance of Compose for PostgreSQL and add a set of credentials.

 service create compose-for-postgresql Standard "Compose for PostgreSQL-GL"
 service key-create "Compose for PostgreSQL-GL" Credentials-1

Retrieve the connection string from the credentials object for the service on Bluemix.

 service key-show "Compose for PostgreSQL-GL" "Credentials-1" | grep "postgres:"

Postgres Connection String example

Modify your `kubernetes/gitlab-postgres-svc.yamlfile and replaceCOMPOSE_PG_PASSWORDwith the password,COMPOSE_PG_HOSTwith the hostname, andCOMPOSE_PG_PORT` with the port.

Using the above example, the `env:` section will look like this.

v:
name: GITLAB_OMNIBUS_CONFIG
lue: |
  postgresql['enable'] = false
  gitlab_rails['db_username'] = "admin"
  gitlab_rails['db_password'] = "ETIDRKCGOEIGBMZA"
  gitlab_rails['db_host'] = "bluemix-sandbox-dal-9-portal.6.dblayer.com"
  gitlab_rails['db_port'] = "26576"
  gitlab_rails['db_database'] = "compose"
  gitlab_rails['db_adapter'] = 'postgresql'
  gitlab_rails['db_encoding'] = 'utf8'
  redis['enable'] = false
  gitlab_rails['redis_host'] = 'redis'
  gitlab_rails['redis_port'] = '6379'
  gitlab_rails['gitlab_shell_ssh_port'] = 30022
  external_url 'http://gitlab.example.com:30080'

Run the following commands or run the quickstart script ./scripts/quickstart-postgres-svc.sh with your Kubernetes cluster.

bectl create -f kubernetes/local-volumes.yaml
bectl create -f kubernetes/redis.yaml
bectl create -f kubernetes/gitlab-postgres-svc.yaml

After you have created all the services and deployments, wait for 3 to 5 minutes. You can check the status of your deployment on Kubernetes UI. Run kubectl proxy and go to URL 'http://127.0.0.1:8001/ui' to check when the GitLab container becomes ready.

Kubernetes Status Page

2. Retrieve external ip and port for GitLab

After few minutes run the following commands to get your public IP and NodePort number.

bx cs workers <cluster_name>

                                               Public IP       Private IP     Machine Type   State    Status   
-hou02-pa817264f1244245d38c4de72fffd527ca-w1   169.47.241.22   10.10.10.148   free           normal   Ready 
bectl get svc gitlab
      CLUSTER-IP     EXTERNAL-IP   PORT(S)                     AGE
ab    10.10.10.148   <nodes>       80:30080/TCP,22:30022/TCP   2s

Note: The 30080 port is for gitlab UI and the 30022 port is for ssh.

Note: The gitlab external url is set to gitlab.example.com add this to your hosts file pointing to your IP address from above in order to use the url that gitlab expects. If you can't do this, then using the IP (in this example 169.47.241.22) should work.

Note: If you using Minikube for local kubernetes deployment, you can access the list of service IPs using the minikube service list command.

Congratulations. Now you can use the link http://gitlab.example.com:30080 or http://:30080 to access your gitlab service from your web browser.

3. GitLab is ready! Use GitLab to host your repositories

Now that Gitlab is running you can register as a new user and create a project.

Troubleshooting

If a pod doesn't start examine the logs.

ctl get pods
ctl logs <pod name>
Cleanup

To delete all your services, deployments, and persistent volume claim, run

ctl delete deployment,service,pvc -l app=gitlab

To delete your persistent volume, run

ctl delete pv local-volume-1 local-volume-2 local-volume-3

To delete your PostgreSQL credentials and remove the service instance from Bluemix, run

ervice key-delete "Compose for PostgreSQL-GL" Credentials-1
ervice delete "Compose for PostgreSQL-GL"

License

Apache 2.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.