{"id":828,"date":"2021-04-25T06:23:00","date_gmt":"2021-04-25T06:23:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=828"},"modified":"2021-04-25T06:23:00","modified_gmt":"2021-04-25T06:23:00","slug":"setup-nexus-kubernetes","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=828","title":{"rendered":"How To Setup Latest Nexus On Kubernetes &#8211; Step by Step Guide"},"content":{"rendered":"<p>Nexus is open-source artifact storage and management system. It is a widely used tool and can be seen in most CI\/CD workflows. As a <a href=\"https:\/\/devopscube.com\/become-devops-engineer\/\" rel=\"noreferrer noopener\">devops engineer<\/a>, it is essential to know about artifact management tools.<\/p>\n<p>I have covered <a href=\"https:\/\/devopscube.com\/how-to-install-latest-sonatype-nexus-3-on-linux\/\" rel=\"noopener noreferrer\">Nexus setup on Linux VM<\/a> in another article.<\/p>\n<p>This guide will walk you through the step-by-step process of deploying Sonatype Nexus OSS on a <a href=\"https:\/\/devopscube.com\/setup-kubernetes-cluster-kubeadm\/\" rel=\"noreferrer noopener\">Kubernetes cluster<\/a>.<\/p>\n<h2 id=\"important-notes\">Important Notes<\/h2>\n<p>Following are the key things to be noted about the nexus setup.<\/p>\n<ol>\n<li>Nexus deployment and service are created in the <strong>devops-tools<\/strong> namespace. 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 &amp; Nexus 3 versions.<\/li>\n<li>In this guide, we are using the host volume mount for nexus data. The intention of this guide is for POC or testing purposes. You need to replace host volume mounts with persistent volumes and tweak other nexus parameters to meet the production requirements for production workloads.<\/li>\n<li>In our Kubernetes manifests, the nexus Service is exposed as NodePort. You can also use type LoadBalancer or use ingress object to expose the nexus endpoint.<\/li>\n<li>Minimum 2 GB RAM and 1 VCPU are required to run nexus. Please check the <a href=\"https:\/\/help.sonatype.com\/repomanager3\/installation\/system-requirements?ref=devopscube.com\" rel=\"noreferrer noopener\">official system requirements<\/a> for more details.<\/li>\n<\/ol>\n<h2 id=\"kubernetes-nexus-manifests\">Kubernetes Nexus Manifests<\/h2>\n<p>All the Kubernetes manifests used in this guide is hosted on an Github repository. Clone the repository to you local workstation to directly execute it.<\/p>\n<pre><code>git clone https:\/\/github.com\/bibinwilson\/kubernetes-nexus.git<\/code><\/pre>\n<h2 id=\"setup-nexus-oss-on-kubernetes\">Setup Nexus OSS On Kubernetes<\/h2>\n<p>Let&#8217;s get started with the setting up nexus on Kubernetes.<\/p>\n<p><strong>Step 1:<\/strong> Create a namespace called <code>devops-tools<\/code><\/p>\n<p>kubectl create namespace devops-tools<\/p>\n<p><strong>Step 2:<\/strong>  Create a <code>deployment.yaml<\/code> 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.<\/p>\n<blockquote><p><em><strong>Note<\/strong>: <\/em>The images used in this deployment are from the public official Sonatype docker repo.(<a href=\"https:\/\/hub.docker.com\/r\/sonatype\/nexus\/?ref=devopscube.com\" rel=\"noopener noreferrer\">Nexus2 image<\/a>  &amp; <a href=\"https:\/\/github.com\/sonatype\/docker-nexus\/blob\/master\/oss\/Dockerfile?ref=devopscube.com\" rel=\"noopener noreferrer\">Dockerfile<\/a> )  (<a href=\"https:\/\/hub.docker.com\/r\/sonatype\/nexus3\/?ref=devopscube.com\" rel=\"noopener noreferrer\">nexus 3 image<\/a> &amp; <a href=\"https:\/\/github.com\/sonatype\/docker-nexus3\/blob\/master\/Dockerfile?ref=devopscube.com\" rel=\"noopener noreferrer\">Dockerfile<\/a>)<\/p><\/blockquote>\n<p><strong>Deployment YAML for Nexus 2.x:<\/strong> If you want to deploy nexus 2, you can use the following deployment file. As explained before, the nexus data directory will be added as a volume in the host server.<\/p>\n<pre><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: nexus\n  namespace: devops-tools\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: nexus-server\n  template:\n    metadata:\n      labels:\n        app: nexus-server\n    spec:\n      containers:\n        - name: nexus\n          image: sonatype\/nexus:latest\n          env:\n          - name: MAX_HEAP\n            value: \"800m\"\n          - name: MIN_HEAP\n            value: \"300m\"\n          resources:\n            limits:\n              memory: \"4Gi\"\n              cpu: \"1000m\"\n            requests:\n              memory: \"2Gi\"\n              cpu: \"500m\"\n          ports:\n            - containerPort: 8081\n          volumeMounts:\n            - name: nexus-data\n              mountPath: \/sonatype-work\n      volumes:\n        - name: nexus-data\n          emptyDir: {}<\/code><\/pre>\n<p><strong>Deployment YAML for Nexus 3.x: <\/strong>Following deployment is for Sonatype nexus 3. It also has the host data volume for nexus data.<\/p>\n<pre><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: nexus\n  namespace: devops-tools\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: nexus-server\n  template:\n    metadata:\n      labels:\n        app: nexus-server\n    spec:\n      containers:\n        - name: nexus\n          image: sonatype\/nexus3:latest\n          resources:\n            limits:\n              memory: \"4Gi\"\n              cpu: \"1000m\"\n            requests:\n              memory: \"2Gi\"\n              cpu: \"500m\"\n          ports:\n            - containerPort: 8081\n          volumeMounts:\n            - name: nexus-data\n              mountPath: \/nexus-data\n      volumes:\n        - name: nexus-data\n          emptyDir: {}<\/code><\/pre>\n<p><strong>Step 3:<\/strong> Create the deployment using kubectl command.<\/p>\n<pre><code>kubectl create -f deployment.yaml<\/code><\/pre>\n<p>Check the deployment pod status<\/p>\n<pre><code>kubectl get po -n devops-tools<\/code><\/pre>\n<p><strong>Step 4:<\/strong> Create a <code>service.yaml<\/code> file with the following contents to expose the nexus endpoint using NodePort.<\/p>\n<blockquote><p><strong>Note:<\/strong> 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.<\/p><\/blockquote>\n<pre><code>apiVersion: v1\nkind: Service\nmetadata:\n  name: nexus-service\n  namespace: devops-tools\n  annotations:\n      prometheus.io\/scrape: 'true'\n      prometheus.io\/path:   \/\n      prometheus.io\/port:   '8081'\nspec:\n  selector: \n    app: nexus-server\n  type: NodePort  \n  ports:\n    - port: 8081\n      targetPort: 8081\n      nodePort: 32000<\/code><\/pre>\n<p>Check the service configuration using kubectl.<\/p>\n<pre><code>kubectl describe service nexus-service -n devops-tools<\/code><\/pre>\n<p><strong>Step 5: <\/strong>Now you will be able to access nexus on any of the Kubernetes node IP on port <code>32000<\/code> as we have exposed the node port. For example,<\/p>\n<p><strong>For Nexus 2,<\/strong><\/p>\n<pre><code>http:\/\/35.144.130.153:32000\/nexus<\/code><\/pre>\n<p>For nexus 2, The default username and the password will be <code>admin<\/code> and <code>admin123<\/code><\/p>\n<p><strong>For Nexus 3,<\/strong><\/p>\n<pre><code>http:\/\/35.144.130.153:32000<\/code><\/pre>\n<p>The default user name for nexus 3 is admin and the default password is stored inside the pod.<\/p>\n<p>First list the pods and get the nexus pod name.<\/p>\n<pre><code>kubectl get pods -n devops-tools<\/code><\/pre>\n<p>Use the kubectl command as shown below to get the password stored in <code>\/nexus-data\/admin.password<\/code> location . Replace <code>nexus-55976bf6fd-cvhxb<\/code> with your pod name.<\/p>\n<pre><code>kubectl exec nexus-55976bf6fd-cvhxb -n devops-tools cat \/nexus-data\/admin.password<\/code><\/pre>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/setup-nexus-kubernetes\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Setup Latest Nexus On Kubernetes &#8211; Step by Step Guide \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/setup-nexus-kubernetes\/<\/p>\n","protected":false},"author":1,"featured_media":829,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-828","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=828"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/828\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/829"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}