Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: using gitlab-ci with kubernetes through kubedock guide #2943

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

amirsalarsafaei
Copy link

What does this PR do?

Adds guide for how to use testcontainers on a gitlab-ci configuration with kubernetes.
I also fixed the code blocks language issue where yamls were specified as ymls, resulting in syntax highlighting being disabled.

Why is it important?

I had a hell of time configuring testcontainers on our kubernetes runners and I think this can help other users.

Related issues

@amirsalarsafaei amirsalarsafaei requested a review from a team as a code owner January 19, 2025 08:05
Copy link

netlify bot commented Jan 19, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit cfbbfc0
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/678cb24a89dc990008c60227
😎 Deploy Preview https://deploy-preview-2943--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@amirsalarsafaei amirsalarsafaei changed the title add(docs): using gitlab-ci with kubernetes through kubedock guide docs: using gitlab-ci with kubernetes through kubedock guide Jan 19, 2025
Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@eddumelendez you probably want to take a look, to include it in Java.

@mdelapenya mdelapenya self-assigned this Jan 20, 2025
@mdelapenya mdelapenya added the documentation Docs, docs, docs. label Jan 20, 2025
@amirsalarsafaei
Copy link
Author

@mdelapenya I can include it java doc as well :D
thanks


This applies if your executor is `kubernetes` and you don't want to use DinD. One option is to use [kubedock](https://github.com/joyrex2001/kubedock). This library is a minimal implementation of the Docker API that will orchestrate containers on a Kubernetes cluster.

Here is the example Kubernetes configuration you must create:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amirsalarsafaei can you include the location of this k8s configuration file? 🙏

I'm currently reproducing this guide into Gitlab, and I don't know where to put that file.

Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should apply the configuration into the Kubernetes namespace that you are using to run your pipelines, there is no need to create any files. If you think that need clarification in guides, let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amirsalarsafaei so we first need to create the k8s cluster in gitlab, right? Please forgive me but my k8s kungfu is very limited

Copy link
Author

@amirsalarsafaei amirsalarsafaei Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's OK :D. I'd be happy to explain. So gitlab gives you the option to run your gitlab runners in Kubernetes, you can see the guide on how to do that alongside some useful information here

gitlab's kubernetes executer guide

You will need access to a Gitlab server (I believe hosted privately) and a Kubernetes namespace to do achieve this. Although I think you can test this with a minikube (it's a version of kubernetes that can run on your local machine).

Context:
Kubernetes uses containerd to spawn up docker images (kind of like docker swarm but way different). and because of this architecture there is no docker socket and server to use in runner environment unless you explicitly have a docker in the image or mount it from the sidecar or etc. The best approach is using kubedock which spawns new pod for each container that testcontainer request just like how gitlab kubernetes executer works.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After you created your minikube environment apply the configurations in the gitlab runner guide and the guide I provided.

Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help me out with this deployment? https://gitlab.com/mdelapenya/testcontainers-go-compose/-/jobs/9061157375

I created a local kind cluster with Docker Desktop, I can see the runner in the Gitlab settings page for the project, but it fails to build.

Sorry for bugging you with this, but as I said I'm neglected with k8s stuff

name: kubedock
namespace: gitlab-runner

# Role for Kubedock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: could you separate all different k8s objects with ---? My Docker Desktop's kind cluster complained with:

Error from server (BadRequest): error when creating "kubedoc.yml": Service in version "v1" cannot be handled as a Service: strict decoding error: unknown field "roleRef", unknown field "rules", unknown field "subjects"

I was able to apply the file once I added them to the file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thats odd cause in k8s you can do that, but I can separate them.

@amirsalarsafaei
Copy link
Author

amirsalarsafaei commented Feb 14, 2025

Could you help me out with this deployment? https://gitlab.com/mdelapenya/testcontainers-go-compose/-/jobs/9061157375

I've requested access to repository through Gitlab. I'll be happy to help:)

@amirsalarsafaei
Copy link
Author

@mdelapenya Hi, I looked into your project but I don't have sufficient access to determine the issue. it looks like that the CI environment is not recognizing the service at all could you give me temporary access so I can debug it?

@mdelapenya
Copy link
Member

@amirsalarsafaei I elevated you to the maintainer role in the Gitlab project. Please let me know about your findings 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Docs, docs, docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants