Deployment of a Kubernetes Cluster and GitLab CI/CD
Prerequisites:
- Docker
- Docker Compose
- Python 3
- python-magnumclient
- python-openstackclient
You also need basic understanding of OpenStack Heat Templates and Docker.
git clone https://github.com/DiFronzo/OpenStack-Magnum-GitLab.git
cd OpenStack-Magnum-GitLab
pip3 install -r requirements.txt
Installation of Docker is found her and Docker Compose is found her for Linux.
First you will need to log in to your OpenStack infrastructure and download the openrc file.
source openrc.sh #source your own openrc from OpenStack
Next edit iac_cluster_env.yaml
and enter name of your keypair
and external_network
. You don't have a keypair? Look at this guide. You will also need to edit parameters in iac_cluster.yaml
for flavor
, node_count
, and etc.
Once you have finished the steps above, you can now deploy the stack. Change <name-of-stack>
with a name of your choosing.
openstack stack create <name-of-stack> -t iac_cluster.yaml -e iac_cluster_env.yaml
Now wait until the cluster has the status "CREATE_COMPLETE"
openstack coe cluster list
The next step is to configure the newly created Kubernetes cluster, this needs Docker and Docker Compose to run locally.
vim .env
The file should look something similar to the following with URL and TOKEN from your prefered gitlab and follow "project-specific runner". Add the UUID or name of the cluster in "CLUSTER=" (workes best with UUID (use openstack coe cluster list
to find this).
# .env.compose
URL=https://gitlab.com/
TOKEN=
CLUSTER=
Then add env. variables for OpenStack access. This include you password in clear text! Do not upload this file anywhere!
(env | grep OS_) >>.env
Last step is to build and run docker-composer to establish a connection between Kubernetes and GitLab.
docker-compose build
docker-compose up
When the cluster is created you can do the following to connect.
mkdir -p ~/clusters/kubernetes-cluster
$(openstack coe cluster config <your-cluster> --dir ~/clusters/kubernetes-cluster)
kubectl get nodes
If lost connection:
export KUBECONFIG=~/clusters/kubernetes-cluster/config
If you want to remove everything connected to gitlab-runner.
kubectl delete deployment,configmap,rolebinding,role,serviceaccount --all --namespace=gitlab-runner
kubectl delete namespace gitlab-runner
To add the configuration again. You will have to first remove your token from gitlab-runner-k8s.yaml
so, it look like this token =
.
docker-compose build
docker-compose up
To change the number of nodes in your cluster, you can do the following:
openstack coe cluster update <your-cluster> replace node_count=<N>
To change the number of pods in your cluster, you can change the following line in the YAML template (gitlab-runner-k8s.yaml
):
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitlab-runner
namespace: gitlab-runner
spec:
replicas: X
To change the amount of requested or limit the amount of the gitlab-runners, you can change or add the following line(s) in the YAML template. Further information on Kubernetes.io.
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitlab-runner
namespace: gitlab-runner
...
...
image: gitlab/gitlab-runner:latest
imagePullPolicy: Always
name: gitlab-runner
resources:
requests:
cpu: "X"
memory: "X"
limits:
cpu: "X"
memory: "X"
This repo is for easy deplyment of a Kubernetes Cluster and for adding a connection to a GitLab repo CI/CD.
Please see the road map section of the README.md to see upcoming functionality and releases of the module.
There is a bug in OpenStack Magnum that does not allow activating "Docker Registry" in the Heat Template.
Here is the functionality that is on the road map for this repo
- Overwrite the token in
gitlab-runner-k8s.yaml
when running Docker Compose. - Support for GitHub CI/CD.