Skip to content

cdelaitre/gitlab-rancher-kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

gitlab-rancher-kubernetes

Context

In order to enable GitLab's AutoDevOps feature you need to fill the form "connecting GitLab with a Kubernetes cluster". As I write this, the official documentation focuses on GKE cluster solution, so we only consider here an existing cluster managed by Rancher (which is my case).

The purpose here is to provide a script to help people to configure the existing cluster and fill the required GitLab fields marked by (*) :

  • Kubernetes cluster name
  • Environment scope
  • API URL *
  • CA Certificate *
  • Token *
  • Project namespace (optional, unique)
  • RBAC-enabled cluster

Features

  • validate kubectl configuration
  • display API URL
  • create namespace gitlab-managed-apps
  • create service account gitlab-sa
  • create role gitlab-role
  • create rolebinding gitlab-rb
  • displays CA Certificate from secret gitlab-sa-token-XXXX
  • displays token from secret gitlab-sa-token-XXXX
  • set role permissive-binding

Requirements

  • ssh terminal session
  • kubectl installed (snap recommended) and configured (~/.kube/config recommended)

Setup

3 VM Ubuntu 18.04 with Docker 18.06 installed

  • VM1 ubuntu1 192.168.56.11 : GitLab 11.9.6-ce installed (omnibus docker-compose installation)
  • VM2 cluster1 192.168.56.101 : Rancher server stable 2.1.8, nfs server (for persistence volume claim)
  • VM3 cluster2 192.168.56.102 : Rancher agent worker1 node

Commands

Clone this repo, execute autodevops.sh

git clone https://github.com/cdelaitre/gitlab-rancher-kubernetes.git
cd gitlab-rancher-kubernetes
./autodevops.sh

Example

cdelaitre@ubuntu1 ~/workspace/gitlab-rancher-kubernetes (master) $ ./autodevops.sh

#-----------------------
kubectl check configuration
#-----------------------
kubectl Api Url
API URL => https://192.168.56.101/k8s/clusters/c-6qr44
#-----------------------
kubectl apply account
namespace/gitlab-managed-apps created
serviceaccount/gitlab-sa created
role.rbac.authorization.k8s.io/gitlab-role created
rolebinding.rbac.authorization.k8s.io/gitlab-rb created
#-----------------------
Get Secret
Secret => gitlab-sa-token-q5wmm
#-----------------------
Get CA Certificate
-----BEGIN CERTIFIC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J8lfLG5fDEQhGUoxD1yDTTjHNQzZc75jBYGuaRhBOsuWsJrZnpHbX9qbTEjfdxzuLWwy4cdU8a8T791Br6ivxVIkz1T5n2bgFWmYoahB3dEoYv5P18GvT7nXxIlJVhhmhcIq8B6mAk7B4Xs_1lsL_3M1isbeZp3Y493G6LcuOokPxdpvPrVLnVCXdh5frqrSg-2tB-82w
#-----------------------
clusterrolebinding.rbac.authorization.k8s.io/permissive-binding created

Notice

I need to change the API URL to the cluster agent worker1 node end-point : https://192.168.56.102:6443

References

About

Connect GitLab CI/CD to Rancher managed Kubernetes Cluster

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages