본문 바로가기

Cloud/MSA

[Sonatype Nexus] Kubernetes Deployment 배포

Private 환경에서 Kubernetes 설치나 관련된 서비스를 올리는 과정을 진행하다 보면, 외부 레포지토리에 접근하여 필요한 패키지들을 다운로드 하는 것은 어렵다. 그렇기 때문에 필요한 라이브러리를 다운받을 수 있게 하는 것이 꼭 필요하게 되는데, 이번 포스팅에서 Docker Registry와 연동을 하기 위해 Nexus를 설치하여 배포하는 과정을 진행한다.

이번 설치를 참고한 블로그는 아래와 같다.

url : blog.sonatype.com/kubernetes-recipe-sonatype-nexus-3-as-a-private-docker-registry

 

Kubernetes Recipe: Sonatype Nexus 3 as a Private Docker Registry

With Sonatype Nexus 3 we can easily get private docker registry for Kubernetes cluster, npm and maven registry for applications.

blog.sonatype.com


Sonatype Nexus 3

- Kubernetes 클러스터 용 개인 도커 레지스트리 관리

- 애플리케이션 용 npm 및 maven 레지스트리 생성

 

필요 Object 목록

- PV, PVC (해당 포스팅에서는 rook-ceph의 프로비저닝 사용)

- Deployment

- Service

 

1. PV, PVC 생성

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nx-pv-claim
  namespace: nexus
  labels:
    app: nexus-server
spec:
  storageClassName: csi-cephfs-sc
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi

# kubectl apply -f nx-pvc.yaml

# kubectl get pvc -n nexus

 

2. Deployment 생성

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nexus
  namespace: nexus
spec:
  selector:
    matchLabels:
      app: nexus-server
  replicas: 1
  template:
    metadata:
      labels:
        app: nexus-server
    spec:
      containers:
        - name: nexus
          image: sonatype/nexus3:latest
          resources:
            limits:
              memory: "4Gi"
              cpu: "1000m"
            requests:
              memory: "2Gi"
              cpu: "500m"
          ports:
            - containerPort: 8081
          volumeMounts:
            - name: nexus-data
              mountPath: /nexus-data
      volumes:
        - name: nexus-data
          persistentVolumeClaim:
            claimName: nx-pv-claim

# kubectl apply -f nx-deploy.yaml

# kubectl get pods -n nexus

# kubectl logs -f -n nexus {nx_pod_name}

--- 아래 로그 메시지 확인

3. Service 생성

apiVersion: v1
kind: Service
metadata:
  name: nexus-service
  namespace: nexus
  annotations:
    prometheus.io/scrape: 'true'
    prometheus.io/path: /
    prometheus.io/port: '8081'
spec:
  selector:
    app: nexus-server
  type: NodePort
  ports:
    - port: 8081
      targetPort: 8081
      nodePort: 32000

# kubectl apply -f nx-service.yaml

# kubectl get svc -n nexus

 

IE를 통한 접근 확인

 

로그인 PassWord 확인

# kubectl get pods -n nexus 

# kubectl exec -it -n nexus {nexus_pod_name} bash

# cat /nexus-data/admin.password

 

 

Hash 값으로 들어가며, 최초 로그인 시, 비밀번호 변경이 뜬다. 이 후, 비밀번호를 변경하게 되면 해당 파일은 자동으로 삭제 된다.