How To Setup Latest Nexus OSS On Kubernetes
- Last Updated On: November 28, 2018
- By: devopscube
Nexus is an opensource artifact storage and management system. It is a widely used tool and can be seen in most of the CI/CD workflows. We have covered Nexus setup on Linux VM in another article.
This guide will walk you through the step by step process of deploying Sonatype Nexus OSS on a Kubernetes cluster.
Setup Nexus OSS On Kubernetes
Key things to be noted,
- Nexus deployment and service are created in the devops-tools namespace. So make sure you have the namespace created or you can edit the YAML to deploy in a different namespace. Also, we have different deployment files for Nexus 2 & Nexus 3 versions.
- In this guide, we are using the volume mount for nexus data. For production workloads, you need to replace host volume mounts with persistent volumes.
- Service is exposed as NodePort. It can be replaced with LoadBalancer type on a cloud.
Let’s get started with the setup.
Step 1: Create a namespace called devops-tools
kubectl create namespace devops-tools
Step 2: Create a Deployment.yaml file. It is different for nexus 2.x and 3.x. We have given both. Create the YAML based on the Nexus version you need. Note: The images used in this deployment is from public official Sonatype docker repo.(Nexus2 image & Dockerfile ) (nexus 3 image & Dockerfile)
- Deployment YAML for Nexus 2.x: Here we are passing a few customizable ENV variable and adding a volume mount for nexus data.
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nexus namespace: devops-tools spec: replicas: 1 template: metadata: labels: app: nexus-server spec: containers: - name: nexus image: sonatype/nexus:latest env: - name: MAX_HEAP value: "800m" - name: MIN_HEAP value: "300m" resources: limits: memory: "4Gi" cpu: "1000m" requests: memory: "2Gi" cpu: "500m" ports: - containerPort: 8081 volumeMounts: - name: nexus-data mountPath: /sonatype-work volumes: - name: nexus-data emptyDir: {}
- Deployment YAML for Nexus 3.x: Here we dont have any custom env variables. You can check the official docker repo for the supported env variables.
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nexus namespace: devops-tools spec: 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 emptyDir: {}
Step 3: Create the deployment using kubectl command.
kubectl create -f Deployment.yaml
Check the deployment pod status
kubectl get po -n devops-tools
Step 4: Create a Service.yaml
 file with the following contents to expose the nexus endpoint using NodePort.
Note: If you are on a cloud, you can expose the service using a load balancer using the service type Loadbalancer. Also, the Prometheus annotations will help in service endpoint monitoring by Prometheus.
apiVersion: v1 kind: Service metadata: name: nexus-service namespace: devops-tools 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
Check the service configuration using kubectl.
kubectl describe service nexus-service -n devops-tools
Step 5: Now you will be able to access nexus on any of the Kubernetes node IP on port 32000/nexus as we have exposed the node port. For example,
For Nexus 2,
http://35.144.130.153:32000/nexus
For Nexus 3,
http://35.144.130.153:32000
Note: The default username and password will be admin & admin123
devopscube
Other Interesting Blogs
Amazon launches Amazon Lightsail, a VPS at just $5
The king of e-Commerce and cloud computing services, Amazon announced Lightsail at the AWS re: Invent conference. Lightsail is a simple tool
How To Monitor Linux Servers Using Prometheus Node Exporter
Node exporter is the best way to collect all the Linux server related metrics and statistics for monitoring. Monitor Linux Servers Using
How to set Git Upstream For a Respository and a Branch
In this blog, you will learn everything about setting up an upstream for a git repository, a branch and the –set-upstream-to command
Comments
Hey,
I just follow the steps but I’m not able to login. I’m seeing a message saying that usarname or password is incorrect.
Anyone knows how to update admin password ?
cat /nexus-data/admin.password from inside the container
@felipeespitalher:disqus please refer to the following links for Nexus 2.x and Nexus 3.x password updates:
https://support.sonatype.com/hc/en-us/articles/213465508?_ga=2.170837091.214258114.1566130312-815295320.1561402348
https://support.sonatype.com/hc/en-us/articles/213467158?_ga=2.170837091.214258114.1566130312-815295320.1561402348
please help me
doesn’t work for me
minikubeip:32000 = nothing
namespace should be devops-tools in the service