Skip to content

Instantly share code, notes, and snippets.

@karthikjeeyar
Created June 19, 2024 08:06
Show Gist options
  • Save karthikjeeyar/e9336826e3eae286a6c15eb92a4cd0f6 to your computer and use it in GitHub Desktop.
Save karthikjeeyar/e9336826e3eae286a6c15eb92a4cd0f6 to your computer and use it in GitHub Desktop.
Install nexus in openshift

Install Nexus repository on openshift cluster.

  1. Create a new namespace 'nexus' in your cluster.
oc new-project nexus
  1. Create a new PersistentVolumeClaim
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nexus-data
  namespace: nexus
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  1. Create a new deployment called nexus which exposes two ports 8081 and 8082
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
        ports:
        - containerPort: 8081
        - containerPort: 8082
        volumeMounts:
        - mountPath: /nexus-data
          name: nexus-data
      volumes:
      - name: nexus-data
        persistentVolumeClaim:
          claimName: nexus-data
  1. Create a service for the nexus deployment
apiVersion: v1
kind: Service
metadata:
  name: nexus
  namespace: nexus
spec:
  ports:
  - port: 8081
    name: nexus-web
  - port: 8082
    name: nexus-repo
  selector:
    app: nexus
  type: LoadBalancer
  1. expose the service targetting different ports.

oc expose svc/nexus --name=nexus-web --port=nexus-web --namespace=nexus
oc expose svc/nexus --name=nexus-repo --port=nexus-repo --namespace=nexus

  1. Go to the Administrator -> Networking -> routes section in openshift and open the nexus-web ui link.

image

  1. Click on the Sign In button from the top right corner.
Screenshot 2024-06-18 at 3 19 22 PM
username: admin
password: xxx // This can be found in the /nexus-data/admin-password file in the nexus pod.
  1. Change the admin password and click next to finish the intial setup.
Screenshot 2024-06-18 at 3 20 27 PM
  1. Now click on Settings -> repository -> Create repository and choose docker (hosted) repository.
Screenshot 2024-06-18 at 3 20 54 PM Screenshot 2024-06-18 at 3 21 04 PM
  1. Provide the port number 8082 and enable the docker v1 api and click on save at the bottom of the file.
Screenshot 2024-06-18 at 3 21 42 PM
  1. Go to the realms on the left navigation bar and click on Docker bearer token and save the settings.
Screenshot 2024-06-18 at 3 21 58 PM
  1. Now you should be able to login to the docker repo
podman login -u admin http://nexus-repo-nexus.<cluster-host-name> --tls-verify=false
Password:xxx
Login Succeeded!
  1. Tag and push an image to the nexus docker repo
❯ podman pull hello:latest
❯ podman tag 5dd467fce50b nexus-repo-nexus.apps.cluster-s274l.sandbox2448.opentlc.com/sample/hello
❯ podman push nexus-repo-nexus.apps.cluster-s274l.sandbox2448.opentlc.com/sample/hello:latest --tls-verify=false

Now the image will be available on the nexus repo.

image

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment