쿠버네티스에서 gitlab 사용하기(k8s+gitlab, Helm, ingress)

이현우·2022년 5월 2일
0

쿠버네티스

목록 보기
11/11

1. 준비 사항

2. 설치

크게 나눠보면 4가지 방법이 있다.
1. helm 레포지토리에서 수정 없이 인스톨 하여 사용하는 방법 (비추천)
2. helm 레포지토리에서 인스톨 명령어에 수정사항을 추가하여 사용하는 방법 (간단한 수정 내용에는 편함)
3. 수정이 필요한 부분만 yaml파일을 작성하여 오버라이드하는 방법 (4가지 방법 중 수정 및 적용이 가장 편하다 생각됨) - 맨 마지막에 간단한 예시 첨부함
4. 전체 파일을 다운로드 받아 values.yaml파일을 수정하여 사용하는 방법 (이 포스트에서 사용한 방법)
위의 네 가지 방법 모두 values.yaml파일의 구조를 먼저 파악하는게 우선!

설치 가이드 - https://docs.gitlab.com/charts/installation/deployment.html
gitlab - https://gitlab.com/gitlab-org/charts/gitlab

2.1 repo등록 및 압축파일 다운로드, NameSpace 생성

# repo 등록
$ helm repo add gitlab https://charts.gitlab.io/

# 압축파일 다운로드
$ helm fetch gitlab/gitlab

# 압축 파일 해제
$ tar xvfz gitlab-5.9.3.tgz

# namespace 생성
$ kubectl create ns gitlab

2.2 values.yaml 수정

  • global.edition → ce(community-edition)으로 설정
  • global.hosts → 도메인 설정
  • global.ingress → 인그레스 설정 클래스로 nginx 사용
  • certmanager-issuer → 이메일 주소 설정
  • certmanager → 공인 IP, 도메인이 없어 cert-manager 컴포넌트 미사용
  • nginx-ingress → 기존에 설치한 ingress nginx 컨트롤러 로드밸런서 타입 사용할 것이기 때문에 false 설정
  • gitlab-runner → cert-manager를 사용한 자동 TLS인증서 생성을 비활성화 하고 자체 서명 인증서를 생성했으므로 false로 설정

2.2.1 global.edition

  • community-edition을 사용할 것이기 때문에 ce로 설정하였다.

2.2.2 global.hosts

  • domain부분에 localhost.com을 붙여주었다. 다른설정을 안하면 기본적으로 앞에 gitlab이 붙는다고 한다.
  • gitlab과 minio, registry 부분에 각자의 이름을 넣어주었다. 후에 ingress에서 해당 이름을 가지고 도메인을 만들어 준다. 따로 설정하지 않으면 domain부분에 각자의 이름(gitlab, minio, registry)가 앞에 붙는게 디폴트인듯 하다.

2.2.3 global.ingress

  • class 부분에 niginx를 추가하여 nginx 클래스로 ingress를 생성(설정 안하면 gitlab-nginx 클래스로 생성됨)
    • 원래 gitlab은 nginx-ingress를 따로 생성하는데 이 글에선 사용하지 않을 예정
    • 또한 기존의 설정한 ingress-nginx-controller를 사용할 것이기 때문에 nginx로 설정하면 됨
  • configureCertmanager는 사용하지 않으므로 false

2.2.4 certmanager-issuer 및 certmanager

  • certmanager-issuer는 encrypt를 사용하는 경우에 요구된다고 적혀있는데(사실 잘모르겠다.) 임의에 이메일을 적어주었음
  • certmanager.install을 false로 바꾸었다.

2.2.5 nginx-ingress

  • nginx-ingress.enabled를 false로 바꾸어 사용하지 않도록 함.

2.2.6 gitlab-runner

  • gitlab-runner는 자체 서명된 인증서에서는 작동하지 않는다.
  • certmanager를 사용하지 않았기 때문에 certmanager를 사용한 자동 TLS 인증서 생성이 비활성화 되었고 자체 서명된 인증서가 생성되었다.
  • 따라서 gitlab-runner가 작동하지 않을 것이기 때문에 gitlab-runner.install : false로 설정함

2.2.7 설치

  • values.yaml 파일 위치에서 helm 명령어를 통해 설치함
$ helm install gitlab -f values.yaml . -n gitlab

2.2.8 인그레스 확인

$ helm get ingress -n gitlab

3. 외부 접속 확인

3.1 hosts 설정

  • hosts 파일 - 위치 - C:\Windows\System32\drivers\etc 경로의 hosts 파일
  • hosts 파일 참고 내용
    • 관리자 모드로 편집 가능
    • 어려우면 다른 곳으로 파일을 복사하여 복사본을 수정한 뒤 원본에 덮어쓰기하는 방법도 있음
  • hosts 파일에 추가할 내용
127.0.0.1 gitlab.localhost.com
127.0.0.1 minio.localhost.com
127.0.0.1 registry.localhost.com

3.2 설정한 gitlab.localhost.com 주소로 접속 및 루트 계정 로그인

루트 아이디 : root
루트 비밀번호 : gitlab-gitlab-initial-root-password secret에 저장되어 있다.

# 비밀번호 찾는 명령어
$ kubectl get secret -n gitlab gitlab-gitlab-initial-root-password -o jsonpath="{.data.password}" | base64 -d ; echo

3.3 접속

3.4 계정 생성 및 git clone, commit, push

3.4.1 문제1. 계정 생성 하고서 관리자 승인이 필요하다고 뜸

  1. 루트 계정 접속(root)
  2. 좌측 상단 Menu → admin → Users → Pending approval에서 계정 우측 메뉴클릭 → 승인
  3. 위의 단계 완료 후 다시 로그인

3.4.2 Test 프로젝트 생성

3.4.3 문제2. git clone시 서버 certificate 인증에 실패했다고 뜸

  • 무시 명령어를 통해 해결
$ git config --global http.sslVerify false

3.4.4 test용 텍스트 파일 작성 후 푸쉬

$ git add .
$ git commit -m 'test'
$ git push
아이디
비번 입력

3.5 확인

4. (추가내용)설치3 수정이 필요한 부분만 yaml파일을 작성하여 오버라이드하는 방법의 간단한 예시

  • override_values.yaml파일 생성
global:
  edition: ce
  hosts:
    domain: localhost.com # ingress 도메인 설정 / 앞에 gitlab이 알아서 붙음
    gitlab:
      name: gitlab.localhost.com
      https: true
    registry:
      name: registry.localhost.com
      https: true
    minio:
      name: minio.localhost.com
      https: true
  ingress:
    configureCertmanager: false
    # gitlab-nginx 클래스로 설정되어 있을 건데 ingress-nginx-controller를 사용할 예정이므로 nginx 클래스로 변경한다.
    class: "nginx"
    tls:
      enabled: true
certmanager: # 공인 IP, 도메인이 없어 cert-manager 컴포넌트 미사용
  install: false


# gitlab nginx-ingress 컴포넌트 미사용
# 준비사항에서 설치한 쿠버네티스 ingress를 이용함
nginx-ingress:
  enabled: false
  • 설치
# repo 등록
$ helm repo add gitlab https://charts.gitlab.io/

# 등록한 gitlab 레포지토리에서 gitlab이라는 namespace에 override_values.yaml을 오버라이드하여 gitlab이라는 이름으로 설치
$ helm install gitlab -f override_values.yaml . -n gitlab gitlab/gitlab
profile
GitHub - https://github.com/jenu8628

0개의 댓글