This is the first day of my participation in the August Text Challenge.More challenges in August

Life belongs to everyone’s own feelings, not to anyone else’s opinion. — Yu Hua, To Live

Summary of a.

Before we can learn to use a tool, we need to know how to install it. In this paper, I will record my learning process, on the one hand to consolidate the learning content, and on the other hand, I hope to provide some help to my friends who have the same needs.

Open source tools describe The official documentation Official Installation Documentation Docker installation
nexus Maven repository management tool The nexus website Nexus Quick Installation Docker installation

The table above lists the official installation address. If you need a quick experience, it is recommended to use Docker directly to install the application, and a single command can start the application:

docker run -d -p 8081:8081 --name nexus sonatype/nexus3
Copy the code

Here’s how to install and use the Nexus in K8S:

  • Write your own deployment manifest nexus-deploy.yaml installation

  • Installation using helm

Installation environment

Minikube is used for the installation, which is basically the same in a K8S cluster

  • Minikube: v1.18.1
  • Helm: v3.5.3

Write deployment listsnexus-deploy.yamlThe installation

Since nexus requires persistent data, we need to create a PVC. It is recommended to use storageClass to create a PVC dynamically. There is a default storageClass in minikube named: standard, which can be checked by using the following command:

# kubectl get sc
NAME                 PROVISIONER                RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
standard (default)   k8s.io/minikube-hostpath   Delete          Immediate           false                  50m
Copy the code

The use of storageClass can view the website: kubernetes. IO/useful/docs/con…

Create the nexus-deploy.yaml file with the following contents:

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nexus-data-pvc
  namespace: default
spec:
  accessModes:
    - ReadWriteMany
  # specify the storageClass name, using the default standard
  storageClassName: "standard"
  resources:
    requests:
      storage: 10Gi

---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: default
  name: nexus3
  labels:
    app: nexus3
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nexus3
  template:
    metadata:
      labels:
        app: nexus3
    spec:
      containers:
      - name: nexus3
        image: Sonatype/nexus3:3.32.0
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 8081
            name: web
            protocol: TCP
        livenessProbe:
          httpGet:
            path: /
            port: 8081
          initialDelaySeconds: 100
          periodSeconds: 30
          failureThreshold: 6
        readinessProbe:
          httpGet:
            path: /
            port: 8081
          initialDelaySeconds: 100
          periodSeconds: 30
          failureThreshold: 6
        resources:
          limits:
            cpu: 4000m
            memory: 2Gi
          requests:
            cpu: 500m
            memory: 512Mi
        volumeMounts:
        - name: nexus-data
          mountPath: /nexus-data
      volumes:
        - name: nexus-data
          persistentVolumeClaim:
            claimName: nexus-data-pvc


apiVersion: v1
kind: Service
metadata:
  name: nexus3
  namespace: default
  labels:
    app: nexus3
spec:
  selector:
    app: nexus3
  type: ClusterIP
  ports:
    - name: web
      protocol: TCP
      port: 8081
      targetPort: 8081
Copy the code

Run the following command to deploy the application:

# kubectl apply -f nexus-deploy.yaml

deployment.apps/nexus3 created
persistentvolumeclaim/nexus-data-pvc created
service/nexus3 created
Copy the code

Run the following command to check whether the POD is running properly:

# kubectl get pod
NAME                      READY   STATUS    RESTARTS   AGE
nexus3-6c75965bcf-6tj5w   1/1     Running   0          5m37s
Copy the code

Run the following command to view the pod logs:

kubectl logs -f nexus3-6c75965bcf-6tj5w -n default
Copy the code

If the following information is displayed, the application is successfully started:

Use the following command to expose the POD port to the machine for external access:

#Kubectl port-forward TYPE/NAME [options] [LOCAL_PORT:]REMOTE_PORT kubectl port-forward TYPE/NAME [options] [LOCAL_PORT:]REMOTE_PORT
kubectl port-forward service/nexus3 8081:8081
Copy the code

Production use is recommended to expose the service via ingress, in this case via port-forward temporary exposure

Visit http://localhost:8081/

The default account and password for logging in to the Nexus are:

  • User name: admin
  • Password: The default initial password in the server/nexus-data/admin.passwordIn the file

Use the following command to obtain the default password:

kubectl exec nexus3-6c75965bcf-6tj5w -- cat /nexus-data/admin.password
Copy the code

Log on to the nexus:

After successful login, you need to set a new password:

After the password is updated, configure whether to enable anonymous access. Enabling anonymous access means that by default, users can search, browse, and download components from the repository without credentials. For security reasons, anonymous access is disabled.

After installation, the picture is as follows:

You can use the following command to remove the nexus related resources installed:

# kubectl delete -f nexus-deploy.yaml

deployment.apps "nexus3" deleted
persistentvolumeclaim "nexus-data-pvc" deleted
service "nexus3" deleted
Copy the code

Install nexus using helm

Go to the helm’s official package management repository to find the application to install.

Helm package management address: artifacthub. IO /

Here, I choose to install the nexus as shown in the picture below :(you can choose the chart with more star installation and frequent updates according to your own needs)

The following installation will follow the documentation:

Add the HELM repository using the following command:

helm repo add sonatype https://sonatype.github.io/helm3-charts/
Copy the code

Update the repository with the following command:

helm repo update
Copy the code

Search nexus using the following command:

helm search repo nexus
Copy the code

Use the following command to download chart locally:

helm pull sonatype/nexus-repository-manager
Copy the code

You can use tar -zxvf to decompress the package and modify the values. Yaml file as required. After the modification, you can use the following command to install the Nexus:

helm install sonatype-nexus ./
Copy the code

If you do not need to customize the configuration, you can run the following command to install it:

helm install nexus-rm sonatype/nexus-repository-manager
Copy the code