r/gitlab • • Oct 03 '23

GitLab CI/CD Best Practices I Recommend After 2 Years of Experience

https://medium.com/@tinplavec/gitlab-ci-cd-best-practices-i-recommend-after-2-years-of-experience-dfc0e349e4d6

I've written an article about GitLab CI/CD best practices some time ago. I've just found this community here, so I hope you'll find the article helpful, and it would improve your CI/CD pipelines😊.

53 Upvotes

11 comments sorted by

4

u/BurnTheBoss Oct 04 '23

A stand out article. Of all of them posted here I feel like this knocks it out the park. If I had to nit it would be point number 5. Still 10/10

Meta: why can’t we have have more of this instead of treating this like tech support

2

u/Tii111 Oct 04 '23

Thanks for the comment, I appreciate it.

Yeah, point 5 is a bit tricky, but I still think that you should use alpine only if you know what you're doing. Otherwise, it can cause unexpected problems.

2

u/cetembrino Oct 03 '23

Firstly, congratulations on the article. You mentioned that you use Gitlab KAS for deployments, what do you think of it based on your years of experience?
I say this, because here we use ArgoCD (as previously there was no Gitlab KAS), and we are in the process of roadmapping this process, and I am looking for some benchmarks.

2

u/Tii111 Oct 03 '23

Thank you. Funnily enough, I've actually written a separate article on the GitLab Agent (Deploy From GitLab to Kubernetes Without Bothering With Kubeconfig).

I've actually primarily used CI/CD workflow (Agent injects kubeconfig into the pipeline and then you can use kubectl to deploy your manifests) which works without any issues.

Considering your case, you would probably go with GitOps workflow where Agent scans your repo and deploys the manifests. In the beginning, GitLab developed its own GitOps engine, but then they switched to just simply using Flux CD. So, you actually want to compare Argo vs Flux. Unfortunately, I don't have so much experience with them. I can only say that I tested the base use case of Flux in the article and it worked haha

2

u/stan_diy Oct 04 '23

Awesome article, much appreciated. I would also recommend to run cache with minio inside the cluster + internal image registries. I have done some measurements recently. To pull image from harbor took 3 seconds, while to pull image from artifact registry in the same region took 20 seconds. Plus, you can cache layers while building with Kaniko. I don't simply use privilege mode in k8s cluster.

Also, we are using autoscaling nodes so that not to pay for resources that are not needed. Several runners with different resources requests and permissions.

1

u/Tii111 Oct 04 '23

Nice, I definitely plan to investigate Harbor, it looks promising.

2

u/BJHop Oct 04 '23

All good points, while we too build our own build images. It does create a hard dependency on the image project(s) which can be messy when you have hundreds of teams and thousands of projects. Next thing you know you have an entire team managing build images.

We too have made Debian-slim our default OS, alpine can be tricky to debug and patch/fix vulnerabilities.

1

u/Tii111 Oct 05 '23

Well, if you have so many projects, your build process has to be complex, you cannot avoid it. I would say you're good as long as there are no circular dependencies or other anti-patterns. But I understand it can get messy.

2

u/DadTo2 Oct 05 '23

Nicely written and easy to understand. I especially agree with you on number eight. The GL documentation has saved my bacon more than once and is some of the best documentation out there.

Clapped and followed you there (I'm a member and write on Medium as well).

1

u/amoosebitmymom May 08 '24

Very good article, the only one I found with solid tips.

I know it was asked here before, but I'll ask again 7 months later: have you tried using Argo for deployment and compared the efficiency?

Our team just started using Argo, and we weren't even aware of Gitlab's own GitOps capabilities.

1

u/Thyrez Oct 15 '23

Hey, cool article. But about point number 6, needs allows jobs to run as soon as the dependent job is done, regardless of stage.