Sonatype Nexus 3 on Kubernetes

Sonatype Nexus 3 repository

Overview

In this installment, we will deploy and setup Sonatype nexus 3 repository on Kubernetes.

Table

  • Introduction
  • prerequisites
  • Creating deployment
  • Accessing web UI
  • Complete resources

1. Introduction

maven central has been always a go to and convenient resource for every java developer for any libraries. There are over 18M artifacts available for download. https://mvnrepository.com

That’s great, but what if we want to host our own artifacts in order for us to reuse but don't necessarily want to make them public?

That’s where self-hosted private repository comes in to picture. Nexus in one among many options available out there and is quite popular.

There are other ways of course to run nexus 3. But we will focus on Kubernetes in this article.

so let’s go ahead and see how can we run nexus in our own Kubernetes cluster.

2. prerequisites

  • Basic understanding of Kubernetes
  • Kubernetes cluster (any Kubernetes distro)

3. creating deployment

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: sonatype-registry
labels:
app: sonatype-registry
spec:
replicas: 1
selector:
matchLabels:
app: sonatype-registry
template:
metadata:
labels:
app: sonatype-registry
spec:
containers:
- image: sonatype/nexus3
name: nexus
ports:
- containerPort: 8081

now run

$ kubectl create -f deployment.yaml

This will create a deployment with 1 pod. We are pulling nexus 3 images from docker hub specified by containers:

containers:
- image: sonatype/nexus3

now if you check logs for pod,

$ kubectl get podsNAME                                  READY   STATUS    RESTARTS   AGEsonatype-registry-cb5d64895-czgdx     1/1     Running   0          20s

you will find something like this in the logs. Which means nexus is started.

bootstrap.jetty.JettyServer -
— — — — — — — — — — — — — — — — — — —
Started Sonatype Nexus OSS 3.29.2–02— — — — — — — — — — — — — — — — — — — — — — — — -

Your first time password will be store in /nexus-data/admin.password

$ kubectl exec -it sonatype-registry-cb5d64895-czgdx -- cat /nexus-data/admin.password<your first time password>

4. Accessing web UI

In order to access the web UI, we will create a service of type NodePort

apiVersion: v1
kind: Service
metadata:
name: sonatype-service
spec:
ports:
- name: sonatype-registry
port: 8081
protocol: TCP
targetPort: 8081
nodePort: 32323
selector:
app: sonatype-registry
type: ClusterIP

Now you can access Web UI at http://<node ip>:32323

That’s it. We deployed nexus in Kubernetes. But if we restart the pod, all the data get deleted. We need to use persistence. Lets do that.

In order for PVC to work, you need some kind of previsioner like NFS.
To set up NFS you can refer this link https://github.com/justmeandopensource/Kubernetes/tree/master/yamls/nfs-provisioner

Below is the complete yamls to create service, deployment and volumes.

5. Complete resources

---
apiVersion: v1
kind: PersistentVolume
metadata:
name: sonatypestorage
labels:
name: sonatypestorage # claim for volume
spec:
storageClassName: sonatypestorage # same storage class as pvc
capacity:
storage: 40Gi
accessModes:
- ReadWriteOnce
nfs:
server: 192.168.14.117 # ip addres of nfs server
path: "/mnt/nfs-volume" # path to directory, make sure directory is available
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: sonatype-registry-data
spec:
storageClassName: sonatypestorage
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: Service
metadata:
name: sonatype-service
spec:
ports:
- name: sonatype-registry
port: 8081
protocol: TCP
targetPort: 8081
selector:
app: sonatype-registry
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: sonatype-registry
labels:
app: sonatype-registry
spec:
replicas: 1
selector:
matchLabels:
app: sonatype-registry
template:
metadata:
labels:
app: sonatype-registry
spec:
volumes:
- name: registry-vol
persistentVolumeClaim:
claimName: sonatype-registry-data
containers:
- image: sonatype/nexus3
name: nexus
ports:
- containerPort: 8081
volumeMounts:
- name: registry-vol
mountPath: /nexus-data
subPath: sonatype

And that is it. Thanks.

Cloud Engineer, Java progammer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Context Manager — Python

My First Full-Stack Application and How I Used Active Record Models and Associations

Harnessing the Power of Hackathons

Introducing Atomic Counters and Batch Sets for Serverless Data

Ace your Oracle Certification — 1Z0–1085–20 Oracle Cloud Infrastructure Foundations 2020 Associate

GDF Biweekly Progress Report

I Get My Website On The First Page Of DuckDuckGo, doing nothing ?

GSoC ’20 with Codeuino: Week 1 Blog

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arfat Bin Kileb

Arfat Bin Kileb

Cloud Engineer, Java progammer

More from Medium

Automate Apigee Hybrid — Control Plane Provisioning

Providing external access to Kafka Cluster

How to Create Deployments and Services in Kubernetes? | ARMO

Riding the Back to School Wave with ProxySQL