GitLab Runner: Step-by-Step Guide¶
What to Do¶
To integrate GitLab with your Kubernetes cluster using KubeDNA, follow these steps:
- Configure a GitLab runner in your environment.
- Configure kubeconfig in your GitLab environment variables.
Configuring GitLab Runner: Step-by-Step Guide¶
- Navigate to the Home Page and select your cluster.
- Go to CI/CD and click Add GitLab.
- Select the architecture you want to use (ARM or x86).
- Choose the machine type you want to use (Note: This is based on the datacenter you are using).
- Enter your GitLab Registration Token (you can copy this from GitLab.com – click here for instructions).
- Click Save.
Once you save, KubeDNA will spin up a new resource inside your environment to configure a GitLab Runner named:
kubedna-<clustername>-<architecture>
This will also be the default tag for the runner inside your GitLab project. You can change it later within GitLab settings.
Configure Kubeconfig as a File Variable¶
- Download the kubeconfig file from Access & Security in the KubeDNA dashboard.
- Go to your GitLab project or subgroup settings.
- Create a variable (e.g., variable name:
KUBECONFIG). - Select type:
File. - Paste the contents of the downloaded kubeconfig file into the variable’s value.
- Save the variable.
Now you are ready to run GitLab pipelines!
Example .gitlab-ci.yml File¶
stages:
- deploy
deploy:
image: google/cloud-sdk:latest # Google Cloud SDK with kubectl
stage: deploy
before_script:
- export KUBECONFIG=/builds/remefox/demo.tmp/KUBECONFIG
script:
- kubectl apply -f deployment/
only:
- main
environment:
name: production
when: manual
tags:
- kubedna-wade-x86 # this can be change in gitlab runner config
Deployment Folder Structure¶
Inside the deployment/ folder, you should have three YAML files:
deployment.yml¶
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
spec:
replicas: 3
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-kubernetes
image: paulbouwer/hello-kubernetes:1.8
ports:
- containerPort: 8080
env:
- name: MESSAGE
value: I just deployed this app with the help of KubeDNA
service.yml¶
apiVersion: v1
kind: Service
metadata:
name: hello-world-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: hello-world
ingress.yml¶
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hello-world-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx-intern
rules:
- host: demo.kubedna.io
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello-world-service
port:
number: 80