Connect DigitalOcean Kubernetes to GitLab - Tutorial for Windows 10 Users
Published: 2021-01-21 15:09:16

It requires many step and there is no complete guide available. Hence, this tutorial exist.

#### Step 1: Create DigitalOcean Kubernetes
It's fairly straight forward process. Once it done, click on `Download config file` button. It will download `.yaml` file.

#### Step 2: Install `kubectl`
- Download  [kubectl.exe](https://storage.googleapis.com/kubernetes-release/release/v1.20.0/bin/windows/amd64/kubectl.exe "kubectl.exe")

More information: https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-windows
- Open  `C:\Users\<windows-user>\` and create `kubectl` folder
-  Copy `kubectl.exe` in  `C:\Users\<windows-user>\kubectl`
- Press Windows + R keys together, type the command "ysdm.cpl" in the Run dialog box and press Enter.
- Click on `Advanced` > `Environment Variables` > Under `System Variables` > Select `Path` > Click `Edit` > Click `New` > Enter `C:\Users\<windows-user>\kubectl`
- Open `Command Prompt`  and type `kubectl` and press enter. If you get message instead error that mean `kubectl` is configured.

#### Step 3: Install `awk`
- Download and install [awk](http://gnuwin32.sourceforge.net/packages/gawk.htm "awk")

- Similary like previus example, add new path to  `Environment Variables` and Path will be  `C:\Program Files (x86)\GnuWin32\bin`

- Open `Command Prompt`  and type `awk` and press enter. If you get message instead error that mean `awk` is configured.

#### Step 4: Install `doctl`
- Download and install windows version from [doctl](https://github.com/digitalocean/doctl/releases "doctl")

- Create DigitalOcean (DO) `Token`. Login to `DO > Click API > Generate New Token` . Copy token.

- Open `C:\Users\<windows-user>\kubectl` in `Command Prompt` and run `doctl auth init` command. It will ask you the `Token` to enter.

- Run the command provided in DO [Screenshot](https://drive.google.com/file/d/1aFcxquU-ddTI5R8EPcwGLjAhq8oMZ58X/view "Screenshot")



#### Step 5: Create `gitlab-setup.yml`
- Open `C:\Users\<windows-user>\kubectl` and create `gitlab-setup.yml` file with following content:
```yml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: gitlab
  namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: gitlab-cluster-admin
subjects:
- kind: ServiceAccount
  name: gitlab
  namespace: default
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io
```
- Open `cmd` and type `cd C:\Users\<windows-user>\kubectl`

- Type `kubectl apply -f gitlab-setup.yml` and press enter;

### 

#### Step 6: Get Gitlab Kubernetes cluster details
Reference: https://www.youtube.com/watch?v=7ycuOLa5mtM

##### App URL:
- Run following command to get `APP URL`:
```sh
kubectl cluster-info | findstr "Kubernetes master" | awk "/http/ {print $NF}"
```

- Get `secrete`, run 
```sh
kubectl get secrets --all-namespaces|awk "/gitlab-token/ {print $2}"
```
Note the text `echo/printed` on the screen. Let's call this text as `$SECRETE`

- Get `CA Certificate`, run following command:
```sh
kubectl get secret $SECRETE -o jsonpath="{['data']['ca\.crt']}"
```
Note: replace `$SECRETE` with the actual text which was printed.

This command will give you a string/text. Copy that text and paste at `https://www.base64decode.org/` then click on decode, this give you the `CERTIFICATE` simloar to follow:

```sh
-----BEGIN CERTIFICATE-----
MIIDJzCCAg+gAwIBAgICBnUwDQYJKoZIhvcNAQELBQAwMzEVMBMGA1UEChMMRGln
....
....
DD/JYjdMdAewoEXZlXPAJIS+eQjXi6AWbLYzBTRHc55GjJoxugWYF0xrTg==
-----END CERTIFICATE-----
```

- Get `Service Token`, run following command:
```sh
kubectl get secret $SECRETE -o jsonpath="{['data']['token']}"
```
Note: replace `$SECRETE` with the actual text which was printed.

This command will give you a string/text. Copy that text and paste at `https://www.base64decode.org/` then click on decode, this give you the `CERTIFICATE` simloar to follow:
```sh
eyJhbGciOi......66GmIE4KH4OHr44Py-4HA
```

#### Step 4: Configure Gitlab Kubernetes
- Visit: `<gitlab-url>/admin/clusters`
- Enter the details that you collected in `previous` steps and Click on save
- In `Helm Tiller`, click `Install`
- Then, in `Ingress`, click `Install`. After install it will give an IP and an URL in `Base domain`, copy this URL and enter in `Base domain` input and click save.
- In `Cert-Manager`, click `Install`.
- In `GitLab Runner`, click `Install`.

#### Step 5: Test Project
- Visit `<gitlab-url>/admin/runners`, here you will see a new `runner`. You can edit the runner and remove `tags` so that it can pick all the CI jobs. You can also assign project to this runner.

- Create New Project.
- Auto DevOps will automatically kick and run the pipelines.