Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 86 additions & 119 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,184 +24,151 @@ By using different GitLab components (NGINX, Ruby on Rails, Redis, PostgreSQL, a
- [GitLab](https://about.gitlab.com/)
- [PostgreSQL](https://www.postgresql.org/)
- [Redis](https://redis.io/)
- [Minio](https://github.com/minio/minio)
- [Kubernetes Clusters](https://console.ng.bluemix.net/docs/containers/cs_ov.html#cs_ov)
- [Bluemix container service](https://console.ng.bluemix.net/catalog/?taxonomyNavigation=apps&category=containers)
- [Bluemix Compose for PostgreSQL](https://console.ng.bluemix.net/catalog/services/compose-for-postgresql)
- [IBM Cloud Kubernetes Service](https://console.ng.bluemix.net/catalog/?taxonomyNavigation=apps&category=containers)

## Objectives
This scenario provides instructions and learning for the following tasks:
# Prerequisites

- Build containers, and store them in container registry
- Use Kubernetes to create local persistent volumes to define persistent disks
- Deploy containers using Kubernetes pods and services
- Use Bluemix service in Kubernetes applications
- Deploy a distributed GitLab on Kubernetes
<!-- Use [Deploying Gitlab to IBM Cloud Private](docs/deploy-with-ICP.md) if you wish to install this on IBM Cloud Private, otherwise follow the instructions below. -->

## Deployment Scenarios
Create a Kubernetes cluster with either [Minikube](https://kubernetes.io/docs/getting-started-guides/minikube) for local testing, or with [IBM Cloud Kubernetes Service](https://console.bluemix.net/docs/containers/cs_tutorials.html#cs_cluster_tutorial) to deploy in cloud. The code here is regularly tested against [Kubernetes Cluster from IBM Cloud Kubernetes Service](https://console.ng.bluemix.net/docs/containers/cs_ov.html#cs_ov) using Travis.

### Deploy using Docker
[Helm](https://helm.sh/) to install GitLab's Cloud Native charts.

see [Deploying Gitlab with Docker](docs/deploy-with-docker.md)
# Steps

### Deploy to Kubernetes
1. [Clone the repo](#1-clone-the-repo)
2. [Create IBM Cloud Kubernetes Service](#2-create-ibm-cloud-kubernetes-service)
3. [Install Helm](#3-install-helm)
4. [Configure GitLab and Install](#4-configure-gitlab-and-install)
5. [Launch GitLab](#5-launch-gitlab)

Use [Deploying Gitlab to IBM Cloud Private](docs/deploy-with-ICP.md) if you wish to install this on IBM Cloud Private, otherwise follow the instructions below.
### 1. Clone the repo

Create a Kubernetes cluster with either [Minikube](https://kubernetes.io/docs/getting-started-guides/minikube) for local testing, or with [IBM Bluemix Container Service](https://github.com/IBM/container-journey-template#container-journey-template---creating-a-kubernetes-cluster) to deploy in cloud. The code here is regularly tested against [Kubernetes Cluster from Bluemix Container Service](https://console.ng.bluemix.net/docs/containers/cs_ov.html#cs_ov) using Travis.
Clone the repo and go in the cloned directory
```
$ git clone https://github.com/IBM/Kubernetes-container-service-GitLab-sample/
```

If you want to use the Bluemix Container Registry start by [Uploading the images](docs/use-bluemix-container-registry.md) to the Bluemix Container Registry.
### 2. Create IBM Cloud Kubernetes Service

### 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](https://console.ng.bluemix.net/docs/services/ContinuousDelivery/toolchains_about.html#toolchains_about) for deploying the Gitlab sample, else jump to [Steps](#steps)
Create an IBM Cloud Kubernetes Service if you don't already have one:

[![Create Toolchain](https://github.com/IBM/container-journey-template/blob/master/images/button.png)](https://console.ng.bluemix.net/devops/setup/deploy/)
* [IBM Cloud Kubernetes Service](https://console.bluemix.net/containers-kubernetes/catalog/cluster)

Please follow the [Toolchain instructions](https://github.com/IBM/container-journey-template/blob/master/Toolchain_Instructions_new.md) to complete your toolchain and pipeline.
### 3. Install Helm

#### Steps
If you don't have the Helm client in your machine, you can find one in the [official releases page](https://github.com/helm/helm/releases).

1. [Use Kubernetes to create Services and Deployments](#1-use-kubernetes-to-create-services-and-deployments-for-gitlab-redis-and-postgresql)
- 1.1 [Use PostgreSQL in container](#11-use-postgresql-in-container) or
- 1.2 [Use PostgreSQL from Bluemix](#12-use-postgresql-from-bluemix)
2. [Retrieve external ip and port for GitLab](#2-retrieve-external-ip-and-port-for-gitlab)
3. [GitLab is ready! Use GitLab to host your repositories](#3-gitlab-is-ready-use-gitlab-to-host-your-repositories)
To install Helm in your Kubernetes Cluster, do:

#### 1. Use Kubernetes to create Services and Deployments for GitLab, Redis, and PostgreSQL
```
$ helm init
```

Ensure your kubernetes cluster is reachable by running the `kubectl` command.
Add the official gitlab repo:

```bash
$ kubectl get nodes
NAME STATUS AGE VERSION
x.x.x.x Ready 17h v1.5.3-2+be7137fd3ad68f
```
$ helm repo add gitlab https://charts.gitlab.io/
$ helm repo update
```

> Note: If this step fails see troubleshooting docs at [Minikube](https://kubernetes.io/docs/getting-started-guides/minikube) or [IBM Bluemix Container Service](https://console.ng.bluemix.net/docs/containers/cs_troubleshoot.html#cs_troubleshoot).

##### 1.1 Use PostgreSQL in container
To verify installation of Helm in your cluster:

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.
```
$ helm version

```bash
$ kubectl create -f kubernetes/local-volumes.yaml
$ kubectl create -f kubernetes/postgres.yaml
$ kubectl create -f kubernetes/redis.yaml
$ kubectl create -f kubernetes/gitlab.yaml
Client: &version.Version{SemVer:"v2.11.0", GitCommit:"2e55dbe1fdb5fdb96b75ff144a339489417b146b", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.11.0", GitCommit:"2e55dbe1fdb5fdb96b75ff144a339489417b146b", GitTreeState:"clean"}
```

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.
> For more info in installing helm, you can find the official documentation [here](https://docs.helm.sh/using_helm/#installing-helm).

![Kubernetes Status Page](images/kube_ui.png)
### 4. Configure GitLab and Install

Next [retrieve your external ip and port for GitLab](#2-retrieve-external-ip-and-port-for-GitLab)
You can find the official helm chart repo for Cloud Native GitLab deployment [here](https://gitlab.com/charts/gitlab). This can guide you in configuring your own deployment for production use.

##### 1.2 Use PostgreSQL from Bluemix
A sample configuration `config.yaml` in this repo can helm you get started with GitLab in IKS. This yaml file is configured to use the provided ingress controller with IKS. The components (Gitaly, Postgres, Redis, Minio) will not use any persistent storage for now.

Use the Bluemix catalog or the `bx` command to create a service instance of Compose for PostgreSQL and add a set of credentials.
Modify `config.yaml` file to use your own Ingress Subdomain, certificate, and IP.

```bash
$ bx service create compose-for-postgresql Standard "Compose for PostgreSQL-GL"
$ bx service key-create "Compose for PostgreSQL-GL" Credentials-1
```
$ bx cs cluster-get <CLUSTER_NAME>

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

```bash
$ bx service key-show "Compose for PostgreSQL-GL" "Credentials-1" | grep "postgres:"
## You should look for these values
## ...
## Ingress Subdomain: anthony-dev.us-south.containers.appdomain.cloud
## Ingress Secret: anthony-dev
## ...
```

![Postgres Connection String example](images/pg_credentials.png)

Modify your ```kubernetes/gitlab-postgres-svc.yaml``` file and replace `COMPOSE_PG_PASSWORD` with the password, `COMPOSE_PG_HOST` with the hostname, and `COMPOSE_PG_PORT` with the port.
To get the ALB (Application Load Balancer) IP address of your cluster:

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

```yaml
env:
- name: GITLAB_OMNIBUS_CONFIG
value: |
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'
```
$ bx cs albs --cluster <CLUSTER_NAME>

## Get the IP Address from the public ALB
## ALB ID Enabled Status Type ALB IP Zone
## private-...-alb1 false disabled private - -
## public-...-alb1 true enabled public 169.XX.XX.XX dal13
```

You can now fill in your own values of `INGERSS_SUBDOMAIN`, `INGRESS_SECRET`, and `ALB_IP` in `config.yaml`

Run the following commands or run the quickstart script `./scripts/quickstart-postgres-svc.sh` with your Kubernetes cluster.
Install GitLab by doing:

```bash
$ kubectl create -f kubernetes/local-volumes.yaml
$ kubectl create -f kubernetes/redis.yaml
$ kubectl create -f kubernetes/gitlab-postgres-svc.yaml
```
$ helm upgrade --install gitlab gitlab/gitlab -f config.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](images/kube_ui_gr.png)

### 2. Retrieve external ip and port for GitLab
### 5. Launch GitLab

After few minutes run the following commands to get your public IP and NodePort number.
Installing GitLab can take minutes to setup. You can check the status of your deployment:

```bash
$ $ bx cs workers <cluster_name>
OK
ID Public IP Private IP Machine Type State Status
kube-hou02-pa817264f1244245d38c4de72fffd527ca-w1 169.47.241.22 10.10.10.148 free normal Ready
$ kubectl get svc gitlab
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
gitlab 10.10.10.148 <nodes> 80:30080/TCP,22:30022/TCP 2s
```
$ kubectl get pods

NAME READY STATUS RESTARTS AGE
gitlab-gitaly-0 1/1 Running 0 3m
gitlab-gitlab-runner-7554ff7c9d-2rt7x 0/1 Running 4 3m
gitlab-gitlab-shell-78b8677b59-9z9m2 1/1 Running 0 3m
gitlab-gitlab-shell-78b8677b59-hssqc 1/1 Running 0 2m
gitlab-migrations.1-74xqt 0/1 Completed 0 3m
gitlab-minio-7b67585cf5-tc4gh 1/1 Running 0 3m
gitlab-minio-create-buckets.1-bdbhk 0/1 Completed 0 3m
gitlab-postgresql-7756f9c75f-pzvlj 1/1 Running 0 3m
gitlab-redis-554dc46b4c-jlkps 2/2 Running 0 3m
gitlab-registry-75cdd8cc6d-n6fx6 1/1 Running 0 2m
gitlab-registry-75cdd8cc6d-nz9sq 1/1 Running 0 3m
gitlab-sidekiq-all-in-1-5865f7f999-wvg6c 1/1 Running 0 3m
gitlab-task-runner-d84b7b9b9-9mc9k 1/1 Running 0 3m
gitlab-unicorn-596cbf98cc-kqrsr 2/2 Running 0 3m
gitlab-unicorn-596cbf98cc-mjbtn 2/2 Running 0 2m
```

> 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.
If all your pods are now running, you can now go to your GitLab installation by visiting `https://gitlab.<INGRESS_SUBDOMAIN>`

Congratulations. Now you can use the link [http://gitlab.example.com:30080](http://gitlab.example.com:30080) or http://<node_ip>:30080 to access your gitlab service from your web browser.
Now that Gitlab is running you can [register as a new user and create a project](docs/using-gitlab.md).

### 3. GitLab is ready! Use GitLab to host your repositories
To try GitLab with persistent storage, you can explore `config-persistent.yaml` and use that instead of `config.yaml`. This will use dynamic storage provisioning that's provided with IKS.

Now that Gitlab is running you can [register as a new user and create a project](docs/using-gitlab.md).
You can learn how to expose the port `22` [here](docs/ssh-port-ingress.md) with the ingress controller to clone repositories using SSH.

### Troubleshooting
# Troubleshooting

If a pod doesn't start examine the logs.
```bash
kubectl get pods
kubectl logs <pod name>
```

### Cleanup

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

```bash
kubectl delete deployment,service,pvc -l app=gitlab
```

To delete your persistent volume, run

```bash
kubectl delete pv local-volume-1 local-volume-2 local-volume-3
```
# Cleanup

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

```bash
bx service key-delete "Compose for PostgreSQL-GL" Credentials-1
bx service delete "Compose for PostgreSQL-GL"
$ helm delete gitlab --purge
```

# License
Expand Down
56 changes: 56 additions & 0 deletions config-persistent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
# note: this is using a forked repo of
# the gitlab chart for minio security context
# https://gitlab.com/AnthonyAmanse/gitlab
global:
hosts:
domain: <INGRESS_SUBDOMAIN>
externalIP: <ALB_IP>
ingress:
configureCertmanager: false
tls:
secretName: <INGRESS_SECRET>
class: ""
annotations:
ingress.bluemix.net/client-max-body-size: size=0
edition: ce

gitlab:
gitaly:
persistence:
size: 20Gi
storageClass: ibmc-file-gold
securityContext:
runAsUser: 0

postgresql:
persistence:
size: 20Gi
storageClass: ibmc-file-gold
securityContext:
runAsUser: 0
metrics:
enabled: false

minio:
persistence:
size: 20Gi
storageClass: ibmc-file-gold
securityContext:
runAsUser: 0

redis:
persistence:
size: 20Gi
storageClass: ibmc-file-gold
securityContext:
runAsUser: 0

certmanager:
install: false

nginx-ingress:
enabled: false

prometheus:
install: false
41 changes: 41 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
global:
hosts:
domain: <INGRESS_SUBDOMAIN>
externalIP: <ALB_IP>
ingress:
configureCertmanager: false
tls:
secretName: <INGRESS_SECRET>
class: ""
annotations:
ingress.bluemix.net/client-max-body-size: size=0
edition: ce

gitlab:
gitaly:
persistence:
enabled: false

postgresql:
persistence:
enabled: false
metrics:
enabled: false

minio:
persistence:
enabled: false

redis:
persistence:
enabled: false

certmanager:
install: false

nginx-ingress:
enabled: false

prometheus:
install: false
Loading