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.txtInstallation 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 OpenStackNext 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.yamlNow wait until the cluster has the status "CREATE_COMPLETE"
openstack coe cluster listThe next step is to configure the newly created Kubernetes cluster, this needs Docker and Docker Compose to run locally.
vim .envThe 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_) >>.envLast step is to build and run docker-composer to establish a connection between Kubernetes and GitLab.
docker-compose build
docker-compose upWhen 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 nodesIf lost connection:
export KUBECONFIG=~/clusters/kubernetes-cluster/configIf you want to remove everything connected to gitlab-runner.
kubectl delete deployment,configmap,rolebinding,role,serviceaccount --all --namespace=gitlab-runner
kubectl delete namespace gitlab-runnerTo 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 upTo 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: XTo 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.yamlwhen running Docker Compose. - Support for GitHub CI/CD.