简体   繁体   中英

How to setup one gitlab agent for all projects in gitlab group to deploy projects separately to the kuberenetes cluster

I have applied the gitlab agents separately to my kuberenetes cluster for each and every project inside the gitlab group by using helm command and separate namespaces to each project. As a example...

There are 2 projects inside my gitlab group. 1.mygroup/project1 2.mygroup/project2

And I used helm command like this...

  1. For project 1 ->> helm upgrade --install gitlab-runner gitlab/gitlab-agent --namespace gitlab-agent-project-1 --create-namespace --set image.tag=v15.1.0 --set config.token=XXXXXXXX --set config.kasAddress=wss://kas.gitlab.com

  2. For project 2 ->> helm upgrade --install gitlab-runner gitlab/gitlab-agent --namespace gitlab-agent-project-2 --create-namespace --set image.tag=v15.1.0 --set config.token=XXXXXXXX --set config.kasAddress=wss://kas.gitlab.com

The only different between these two is namespace

So I am asking is this one is the best and correct way of doing this process... Cant we use one gitlab agent for all project inside the gitlab group and can't be use it for CICD kubernetes deployments separately??

Because there are pods initializing when I have applied separate agents for each one.If I have 100 projects and I have to provide 100 Pods IP addresses for those agents.

Yes, you can use one GitLab agent for all projects inside a GitLab group. Currently, I'm implementing this.

Tree project demonstrating:

树项目展示

Inside a GitLab agent project, you define .gitlab/agents/{agent-name}/config.yaml file. Inside the config.yaml file, you set the ci_access to projects inside your GitLab group:

gitops:
  # Manifest projects are watched by the agent. Whenever a project changes,
  # GitLab deploys the changes using the agent.
  manifest_projects:
  - id: medai/vinlab/vinlab-testing/test-k8s-cicd/test-gitlab-agent
    default_namespace: gitlab-agent
ci_access:
   projects:
   - id: medai/vinlab/vinlab-testing/test-k8s-cicd/sample-go-service
   - id: medai/vinlab/vinlab-testing/test-k8s-cicd/api-test

From the project that needs access to the GitLab agent, you need to use-context in order to access gitlab-agent , then you can do the certain action you want. For example, this code from gitlab-ci.yml file in one project:

deploy:
  stage: deploy
  image:
    name: bitnami/kubectl:latest
    entrypoint: ['']
  script:
    - kubectl config get-contexts
    - kubectl config use-context medai/vinlab/vinlab-testing/test-k8s-cicd/test-gitlab-agent:dev-agent-1
    - kubectl apply -f functional-tester.yaml --namespace vinlab-testing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM