This blog will guide you through the creation of a functional GitLab CI/CD pipeline for applications that will be deployed to OpenShift.
GitLab is a tool that developers can use to not only host a repository for the code that they write but also use it to create CI/CD pipelines. The ability to create these pipelines is a function that is built into GitLab itself; to get started you simply need to have a configuration file, .gitlab-ci.yml, present in the root directory of your repository.
The major steps in the pipeline are defined by stages. In each of the stages you have the ability to create multiple jobs that will run a shell script to execute commands. One thing to keep in mind is that a stage defined in the configuration file does not necessarily have to run for each execution of the pipeline; the steps that are chosen will depend on the rules for triggering that stage.
Further information on GitLab CI/CD can be found here.
Requirements
Helm is a major component of this pipeline. It is used to apply a general template to all deployments and builds which you can then use to create the corresponding OpenShift resources. You can download and find more info on helm here.
CI/CD Pipeline Configuration
Follow the steps in the README within the repo to configure the pipeline to work with your project.
Notes on Branching
Feature Branch Mechanics
Feature branches operate on a different set of rules than non-feature branches (ex. master). Whenever a feature branch is created, the first execution of that pipeline for that branch will create a namespace in OpenShift. This will allow the developers to test their new functionality without any contention for a single “dev” environment. Once the feature is complete and the branch in the git repo is deleted, a cleanup job in the pipeline will be triggered, deleting the feature branch namespaces and reclaiming the resources.
Non-Feature Branch Mechanics
The non-feature branches, such as master, are a known entity, and can be created ahead of time and configured to grant fewer privileges to the service account, to ensure an accidental unwanted change or project deletion is not possible through the pipeline.
GitLab Runners on OpenShift
The GitLab Runner is the application that processes the GitLab pipeline. For each job to be processed, the Runner will spawn a pod to execute the commands in that job. Runners can be deployed on many different operating systems and there are several ways to deploy a Runner on OpenShift. In addition to the Kubernetes installation provided by GitLab, the Red Hat Community of Practice (CoP) provides a Runner container image which does not require a privileged SCC to run. The deployment of the CoP container image uses the standard Helm chart provided for Kubernetes installation. There are also other sources for the Runner but in this post, we will focus on the Runner provided by the GitLab Operator.
Deploying the Runner Operator and Runner
The deployment of a GitLab Runner using the OpenShift GitLab Operator has been documented in detail here: Installing the GitLab Runner the OpenShift Way
Configuring the Runner
Scripts for managing the Runner are created as ConfigMaps in your runner project. These scripts have some parameters for configuring the Runner within the scripts themselves. For example, `register-runner` has MAX_REGISTER_ATTEMPTS=30 hard coded into it. Most configuration parameters, however, are set as environment variables in the Runner Deployment resource.
To see the current settings, one can look at either the Deployment or the running Pod. For example:
$ oc rsh example-runner-787df7bf58-jpgjn env | grep MEM KUBERNETES_SERVICE_MEMORY_REQUEST= KUBERNETES_HELPER_MEMORY_LIMIT= KUBERNETES_MEMORY_REQUEST= KUBERNETES_MEMORY_LIMIT= KUBERNETES_HELPER_MEMORY_REQUEST= KUBERNETES_SERVICE_MEMORY_LIMIT= |
To set KUBERNETES_HELPER_MEMORY_REQUEST to 3G, you can run oc patch with json code similar to the following.
$ oc patch deployment example-runner -p '{"spec":{"template":{"spec":{"containers":[{"image":"registry.connect.redhat.com/gitlab/gitlab-runner:12.9","name":"runner","env":[{"name":"KUBERNETES_HELPER_MEMORY_REQUEST","value":"3G"}]}]}}}}' |
On success, you should see a message like this:
deployment.apps/example-runner patched |
Another oc rsh command into the pod will confirm that your new setting is part of the running environment of the Runner pod:
$ oc rsh example-runner-f5b546b76-dvkjk env | grep MEM KUBERNETES_MEMORY_LIMIT= KUBERNETES_HELPER_MEMORY_REQUEST=3G KUBERNETES_SERVICE_MEMORY_REQUEST= KUBERNETES_HELPER_MEMORY_LIMIT= KUBERNETES_MEMORY_REQUEST= KUBERNETES_SERVICE_MEMORY_LIMIT= |
저자 소개
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.