DevOps/DevOps기초

Harbor Repository구성하기

치킨맛코드 2022. 9. 15. 16:43

Docker와 k8s을 사용하고 관리하다 보면 cil환경이라 관리하기 불편할때가 종종 있다. 이런것들을 극복하기 위해 다양한 도구들이 나왔는데 이번에는 Harbor라는 도구를 사용해서 gui환경으로 접근해 보도록 하자.

Harbor는 오픈소스 리포지토리로써 k8s의 효자tool인 Helm Chart와 Docker repository를 함께 관리해 주는 오픈소스 리포지토리이다. Trivy와 같은 도커 취약점 점검을 할 수 있으며 이런 기능들을 통합한 클라우드 환경기반의 repository를 구축할 수 있게 된다.

https://github.com/goharbor/harbor/releases

 

Releases · goharbor/harbor

An open source trusted cloud native registry project that stores, signs, and scans content. - goharbor/harbor

github.com

이런 repository는 보통 인터넷이 되지않는  offline환경에서 구축되기에, 그것을 기반으로 샐행해 보고자 한다. 먼저 git에서 원하는 버전의 파일을 다운로드 받도록 하자. 이번 포스팅에서는 habor-offine-instealler-v2.6.0을 사용했다.

* docker와 docker compose가 설치되어 있어야한다. 혹시 설치되어 있지 않다면 아래의 명령어를 통해 설치하기 바란다.

yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io
systemctl enabel docker
systemctl start docker
curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
==> docker 및 docker compose를 설치하는 과정이다.

tar파일을 받았다면 아래의 명령어를 실행하도록 하자.

# tar -xvf harbor-offline-installer-v2.6.0.tgz
==> harbor 파일의 압축을 해제한다.
# cd harbor
==> 압축해제된 harbor로 들어간다.
# ls
common.sh  harbor.v2.6.0.tar.gz  harbor.yml.tmpl  install.sh  LICENSE  prepare
==> harbor의 파일들이다. 이 중 harbor.yml.tmpl 에는 설정파일이 존제한다.
# vi harbor.yml.tmpl
harbor의 내부 설정을 확인할 수 있다.

harbor.yml파일을 열어보면 아래의 내용이 나타나는데 잘 읽고 본인이 원하는 파트를 수정하도록 하자. 대표적으로 port번호, dns, password등을 수정할 수 있다.

harbor.yml.tmpl의 내부 내용이다.

# Configuration file of Harbor

# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: 192.168.0.134
==> 도매인 혹은 ip를 기입하도록 하자.

# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 8080
==> 사용하고자 하는 port를 수정할 수 있다. 8080을 사용했다.

# https related config
https:
# https port for harbor, default is 443
#  port: 443
# The path of cert and key files for nginx
#  certificate: /your/certificate/path
#  private_key: /your/private/key/path
==> 443번포트에 대한 내용이다. 사용하지 않는다면 주석처리를 하도록 하자.

# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
# external_url: https://reg.mydomain.com:8433

# The initial password of Harbor admin
# It only works in first time to install harbor
# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: Harbor12345
==> harbor에 접근하기 위한 admin계정의 password를 설정할 수 있다.

이러한 설정을 다 마친 후 저장을 하고나서 daemon.json파일을 수정하도록 하자. daemon.json파일은 docker파일을 받아오는곳에서 반드시 수정해 줘야지 http로 로그인을 할 수 있다.

# vi /etc/docker/daemon.json
{

"insecure-registries": ["192.168.0.134:8080"]
==> 해당하는 ip와 port를 기입한다.
}

이 후 당연히 도커를 제시작 하도록 하자.

# systemctl restart docker

모든 준비가 마쳤다면 아래의 명령어를 통해 harbor를 설치하자. 이때 --with-trivy라는 명령어를 사용하여서 docker 취약점 스켄을 위한 tool인 trivy도 함께 설치할 수 있다. 이 과정을 스킵하고 그냥 ./install.sh명령어를 사용했다면 gui환경에서도 수정가능하니 크게 걱정은 하지말자.

#./install.sh --with-trivy

https://github.com/aquasecurity/harbor-scanner-trivy/blob/main/docs/images/add_scanner.png

 

GitHub - aquasecurity/harbor-scanner-trivy: Use Trivy as a plug-in vulnerability scanner in the Harbor registry

Use Trivy as a plug-in vulnerability scanner in the Harbor registry - GitHub - aquasecurity/harbor-scanner-trivy: Use Trivy as a plug-in vulnerability scanner in the Harbor registry

github.com

gui환경에서의 수정

이제 ip로 접근을 해 보도록하자. 아래와 같이 잘 접근되는것을 확인할 수 있을것이다. password를 따로 수정하지 않았더라면 Harbor12345가 고정적인 password일 것이다.

로그인을 한다면 아래의 화면이 나타날 것이다. 기본적으로 생성되어 있는 파일은 library하나뿐이다.

저장소의 총 용량과 프로젝트와 리포지토리의 갯수 등이 나타난다. 새로운 프로젝트는 클릭 몇 번이면 금방 생성할 수 있다.

생성한 프로젝트 혹은 기존에 있는 library에 이제 docker 파일을 업로드 해 보도록 하자. 방법은 다른 레지스트리에 업로드하는것과 마찬가지이다.

docker login 192.168.0.134:8080
==> 해당하는 서버(harbor)에 docker 로그인을 한다.
id와 password는 admin/Harbor12345로 동일하다.

docker tag [업로드하고싶은 이미지명]:[버전명] [업로드할 서버의 위치(ip)]:[포트]/[프로젝트명]/[이미지명]:[버전]
==> tag정책을 활용해 이미지에 테그를 붙인다.

docker push [업로드할 서버의 위치(ip)]:[포트]/[프로젝트명]/[이미지명]:[버전]
==> push명령어를 통해 이미지를 푸쉬한다.