Open In App

Setup Latest Nexus OSS On Kubernetes

Last Updated : 14 Aug, 2024
Comments
Improve
Suggest changes
1 Likes
Like
Report

Nexus OSS is a popular repository manager that helps you manage your binaries and build artifacts efficiently. Deploying Nexus OSS on Kubernetes allows you to leverage Kubernetes' orchestration capabilities for better scalability and management. Here’s a clear, step-by-step guide to setting up the latest Nexus OSS on Kubernetes.

Pre-requisite

Before starting, ensure you have the following:

1. Kubernetes Cluster: Ensure you have access to a running Kubernetes cluster. You can use a managed service like GKE, EKS, AKS, or set up your own cluster using tools like Minikube or K3s.

2. kubectl: Ensure kubectl is installed and configured to interact with your Kubernetes cluster.

3. Helm: Install Helm if you prefer using Helm charts for deployment (This is optional but recommended for a simplified deployment process).

Minikube start

Step By Step Process To Setup Nexus OSS On Kubernetes

Step 1: Create a Namespace

Namespaces in Kubernetes help organize and manage resources. Create a dedicated namespace for Nexus:

kubectl create namespace nexus
namespace-created
namespace created

Step 2: Set Up Persistent Storage

Nexus OSS requires persistent storage to save its data. Create a PersistentVolume (PV) and a PersistentVolumeClaim (PVC).

Create PersistentVolume (pv.yaml)

apiVersion: v1
kind: PersistentVolume
metadata:
name: nexus-pv
namespace: nexus
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data/nexus"

Create PersistentVolumeClaim (pvc.yaml)

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nexus-pvc
namespace: nexus
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi

Apply these configurations:

kubectl apply -f pv.yaml
kubectl apply -f pvc.yaml

Step 3: Deploy Nexus OSS

Below is a step-by-step guide to deploying Nexus OSS using Kubernetes manifests or Helm charts, including instructions on verifying the deployment, configuring access, and securing your Nexus OSS instance.

Option 1: Using Kubernetes Manifests

We can deploy Nexus OSS using Kubernetes manifests.

1. Create a namespace

First, create a namespace for Nexus.

kubectl create namespace nexus

2. Create Deployment and Service for Nexus OSS.

Create a file named nexus-deployment.yaml with the following content:

apiVersion: apps/v1
kind: Deployment
metadata:
name: nexus
namespace: nexus
spec:
replicas: 1
selector:
matchLabels:
app: nexus
template:
metadata:
labels:
app: nexus
spec:
containers:
- name: nexus
image: sonatype/nexus3:latest
ports:
- containerPort: 8081
volumeMounts:
- name: nexus-data
mountPath: /nexus-data
volumes:
- name: nexus-data
persistentVolumeClaim:
claimName: nexus-pvc

Now, create a file named nexus-service.yaml with the following content:

apiVersion: v1
kind: Service
metadata:
name: nexus-service
namespace: nexus
spec:
selector:
app: nexus
ports:
- protocol: TCP
port: 8081
targetPort: 8081
type: LoadBalancer

After doing above .yaml script, apply the below command to see kubernetes manifests to deploy Nexus OSS.

kubectl apply -f nexus-deployment.yaml
kubectl apply -f nexus-service.yaml
deployment.yaml

3. Verify the Deployment

Now, check the status of the Nexus pod.

kubectl get pods -n nexus
verification of deployment


4. Access Nexus OSS

After deploying Nexus OSS, you need to access it. If you used a LoadBalancer service, get the external IP:

kubectl get svc --namespace nexus

Find the EXTERNAL-IP under nexus-service and open it in your browser on port 8081,

e.g., ' http://<EXTERNAL-IP>:8081 '.

Option 2: Using Helm Chart

Now we are going to perform deploying Nexus OSS task Using Helm Charts

1. Add the Helm Repository

First, you need to add the Helm repository that contains the Nexus Helm chart.

helm repo add sonatype https://sonatype.github.io/helm3-charts/
helm repo update

2. Install Nexus OSS using Helm:

helm install nexus sonatype/nexus-repository-manager --namespace nexus

3. Verify the Deployment

After the installation, check the status of your Nexus pods.

kubectl get pods

You should see a pod named nexus-<hash> in the Running state.

4. Access Nexus OSS

To access the Nexus OSS web interface, we are using port forwarding or expose the service.

Port Forwarding:

kubectl port-forward service/nexus 8081:8081

Now, open your browser and navigate to http://localhost:8081. You should see the Nexus OSS login page.

Nexus login page

Step 4: Configuring Access and Securing Nexus OSS

1. Set Admin Password

Upon first access, you’ll be prompted to set an admin password.

  • Username: admin
  • Password: Retrieve the default password from the Nexus pod:
kubectl exec -it <nexus-pod> -- cat /nexus-data/admin.password

2. Configure Security Settings

  • Navigate to Settings > Security in the Nexus interface.
  • Set up SSL/TLS, configure user roles, and enforce strong passwords.

Conclusion

You have successfully set up the latest Nexus OSS on Kubernetes. This setup ensures that your Nexus OSS instance is scalable, manageable, and ready to use for storing and managing your build artifacts. For production use, remember to secure your instance and set up backup and monitoring systems. Here we have created a basic set of latest nexus OSS on Kubernetes. Hope you find this article helpful and understandable.


Article Tags :

Explore