Last active
April 17, 2024 10:07
-
-
Save trondhindenes/0307fbe9cda1164115353b4632a31ea9 to your computer and use it in GitHub Desktop.
Run KinD (Kubernetes in Docker) as part of Gitlab CI job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Spin up Kubernetes control plane as part of before_script, and destroys it using after_script | |
#Some custom logic to get to the right ip address | |
#Requres the gitlab docker runner, with "pass-thru" to the host docker socket. | |
stages: | |
- test | |
image: python:3.6.6 #the docker image you run in needs Docker installed, and access to the host docker socket. | |
test_integration_k8s: | |
tags: | |
- linux-docker | |
stage: test | |
before_script: | |
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.12.0/bin/linux/amd64/kubectl | |
- chmod +x kubectl | |
- mv kubectl /usr/local/bin/ | |
- curl -Lo kind https://github.com/kubernetes-sigs/kind/releases/download/0.1.0/kind-linux-amd64 | |
- chmod +x kind | |
- mv kind /usr/local/bin/ | |
- kind create cluster --name $CI_PIPELINE_ID --wait 180s | |
- export KUBECONFIG="$(kind get kubeconfig-path --name $CI_PIPELINE_ID)" | |
- REAL_IP=$(ip route|awk '/default/ { print $3 }') | |
- sed -i -e "s/localhost/$REAL_IP/g" $KUBECONFIG | |
script: | |
- kubectl get nodes --insecure-skip-tls-verify=true | |
after_script: | |
- kind delete cluster --name $CI_PIPELINE_ID |
@pirolas001, I don't know if this would help, but when doing local testing, I was able to make my web service that's running in the cluster accessible like this: kubectl port-forward service/<service name> <local port>:<service's target port>
. Perhaps kubectl proxy
might also help?
I am having issues with using a local GH Runner and building the cluster locally, it seems that I can't reconnect to the cluster in a seperate stage, has anyone successfully done this with kind and podman on wsl2?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, glad it helped you! I'm afraid I haven't worked on this for many years so I don't have any helpful tips to share, sorry!