사설 레지스트리를 설치함으로 안전하게 빌드한 이미지를 관리합니다.
Docker Harbor
엔터프라이즈급의 컨테이너 이미지 레지스트리로, Docker 이미지를 안전하고 효율적으로 관리할 수 있게 해주는 도구입니다. Harbor는 CNCF(Cloud Native Computing Foundation)의 일부로, 오픈 소스 프로젝트로 제공되며, 특히 기업 환경에서 필요한 고급 기능들을 제공합니다.
Docker Harbor의 주요 특징
- 컨테이너 이미지 저장소
- Harbor는 Docker 이미지를 저장하고 관리하는 데 특화된 레지스트리입니다. 기본적으로 Docker Hub와 유사한 역할을 하지만, 보다 세밀한 보안 및 관리 기능을 제공합니다. 이를 통해 개발자들이 이미지를 안전하게 저장하고, 배포할 수 있도록 지원합니다.
- 다중 프로젝트 지원
- Harbor는 다중 프로젝트를 지원하여, 각 프로젝트별로 별도의 레지스트리를 만들 수 있습니다. 이는 여러 팀이 각각 다른 이미지 레포지토리를 관리하는 데 유용합니다.
- 이미지 스캔 기능
- Harbor는 이미지의 취약점 스캔을 제공하여, 보안 취약점이 있는 이미지를 미리 확인하고, 이를 해결할 수 있게 돕습니다. 이를 통해 보안적인 문제를 사전에 예방할 수 있습니다.
- RBAC (Role-Based Access Control)
- Harbor는 사용자 권한을 세부적으로 설정할 수 있는 RBAC 기능을 제공합니다. 각 사용자나 그룹에게 역할을 부여하여, 특정 레포지토리나 프로젝트에 대한 접근을 제어할 수 있습니다. 이로 인해 보안성이 높아지고, 관리가 용이해집니다.
- Replication (이미지 복제)
- Harbor는 이미지를 다른 Harbor 인스턴스나 외부 레지스트리로 복제하는 기능을 제공합니다. 이를 통해 다중 지역에서 이미지의 가용성을 높이고, 장애 발생 시 빠르게 대체할 수 있습니다.
- LDAP 통합
- Harbor는 LDAP(경량 디렉토리 접근 프로토콜)을 지원하여, 기존의 인증 시스템과 통합할 수 있습니다. 이를 통해 조직 내 사용자 인증을 중앙 집중식으로 관리할 수 있습니다.
- 헬름 차트 지원
- Harbor는 Helm 차트를 사용하여 Kubernetes와 연동할 수 있습니다. Helm을 사용하면 Harbor 설치 및 구성을 보다 쉽게 관리할 수 있으며, Kubernetes 환경에서의 이미지 관리가 효율적입니다.
- API 및 CLI 지원
- Harbor는 RESTful API와 CLI 도구를 제공하여, 자동화된 스크립팅 및 다양한 개발 도구와의 통합을 지원합니다. 이를 통해 이미지를 배포하고 관리하는 작업을 자동화할 수 있습니다.
- 다양한 구축 방법
- 인증키만 있다면 여러 클러스터에 단일 레지스트리로 구축할 수 있습니다.
Docker Harbor 설치 및 구성
1. os 업데이트 & 도커 컴포즈 설치
apt update && apt install -y docker.io docker-compose
2. Harbor 설치
wget https://github.com/goharbor/harbor/releases/download/v2.10.0/harbor-offline-installer-v2.10.0.tgz
tar -zxvf harbor-offline-installer-v2.10.0.tgz
cd harbor
2-1. harbor 설정 편집
# vim harbor.yml
```
# 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.60.162
# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 80
# https related config
https:
# https port for harbor, default is 443
port: 443
# The path of cert and key files for nginx
certificate: /etc/harbor/cert.pem
private_key: /etc/harbor/key.pem
# # Uncomment following will enable tls communication between all harbor components
# internal_tls:
# # set enabled to true means internal tls is enabled
# enabled: true
# # put your cert and key files on dir
# dir: /etc/harbor/tls/internal
# # enable strong ssl ciphers (default: false)
# strong_ssl_ciphers: false
# 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: innoverse!
# Harbor DB configuration
database:
# The password for the root user of Harbor DB. Change this before any production use.
password: innoversedb!
# The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
max_idle_conns: 100
# The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
# Note: the default number of connections is 1024 for postgres of harbor.
max_open_conns: 900
# The maximum amount of time a connection may be reused. Expired connections may be closed lazily before reuse. If it <= 0, connections are not closed due to a connection's age.
# The value is a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
conn_max_lifetime: 5m
# The maximum amount of time a connection may be idle. Expired connections may be closed lazily before reuse. If it <= 0, connections are not closed due to a connection's idle time.
# The value is a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
conn_max_idle_time: 0
```
3. harbor install
./install.sh
접속을 위한 인증키 생성
1. 인증키 생성
# 인증키 생성
sudo mkdir -p /etc/harbor
cd /etc/harbor
# 개인 키 생성 (4096bit 강력한 암호화)
openssl genrsa -out key.pem 4096
# CSR (인증서 서명 요청) 생성
openssl req -new -key key.pem -out cert.csr -config san.cnf
# 자체 서명 인증서 생성 (SAN 포함)
openssl x509 -req -days 365 -in cert.csr -signkey key.pem -out cert.pem -extensions v3_req -extfile san.cnf
2. 모든 노드에서 인증서 다운로드
sudo mkdir -p /etc/containerd/certs.d/192.168.60.162
sudo wget -O /etc/containerd/certs.d/192.168.60.162/ca.crt https://192.168.60.162/cert.pem --no-check-certificate
3. containerd 레지스트리 설정
# sudo vi /etc/containerd/config.toml
```
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."192.168.60.162"]
endpoint = ["https://192.168.60.162"]
[plugins."io.containerd.grpc.v1.cri".registry.configs."192.168.60.162".tls]
ca_file = "/etc/containerd/certs.d/192.168.60.162/ca.crt"
```
4. containerd 재시작
sudo systemctl restart containerd
5. DaemonSet 을 통한 자동 배포
apiVersion: v1
kind: ConfigMap
metadata:
name: registry-ca-cert
data:
ca.crt: |
-----BEGIN CERTIFICATE-----
~~~ ca.crt 값 입력 ~~~
-----END CERTIFICATE-----
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: registry-ca-deploy
spec:
selector:
matchLabels:
app: registry-ca-deploy
template:
metadata:
labels:
app: registry-ca-deploy
spec:
initContainers:
- name: deploy-ca
image: debian
command: ["sh", "-c"]
args:
- mkdir -p /etc/containerd/certs.d/192.168.60.162 &&
cp /ca/ca.crt /etc/containerd/certs.d/192.168.60.162/ca.crt &&
chmod 644 /etc/containerd/certs.d/192.168.60.162/ca.crt
volumeMounts:
- name: ca-cert
mountPath: /ca
- name: containerd-certs
mountPath: /etc/containerd/certs.d
containers:
- name: pause
image: k8s.gcr.io/pause:3.6
volumes:
- name: ca-cert
configMap:
name: registry-ca-cert
- name: containerd-certs
hostPath:
path: /etc/containerd/certs.d
type: DirectoryOrCreate
hostPID: true
tolerations:
- operator: Exists
6. containerd 재시작
sudo systemctl restart containerd
6-1. 인증서 유효성 검증
openssl x509 -in ca.crt -text -noout | grep "IP Address"
7. 테스트 풀링
# 이미지 풀링 테스트
crictl pull 192.168.60.162/test/nginx:latest
# 파드 생성 테스트
kubectl run test --image 192.168.60.162/test/nginx
하버 설치 자체는 어렵지 않습니다.
인증키를 어떤 방법으로 관리해야 추후 관리적인 측면에서 용이할까 생각해 보았는데, 노드에 직접 인증키를 옮기고 시크릿으로 인증을 하는 방법 보다 데몬셋으로 배포 해주는 것이 추후 관리적인 측면에서도 용이하다 생각해 작성해보았습니다.
더 나은 방법이 있다면 정보 공유주세요.
감사합니다.
'Infra > Kubernetes' 카테고리의 다른 글
RBAC (0) | 2025.04.25 |
---|---|
StorageClass (0) | 2025.03.26 |
HAProxy 고가용성 (0) | 2025.03.21 |
Vanilla Kubernetes install (0) | 2025.03.20 |
secret (0) | 2025.03.10 |