1、添加nexus仓库

  1. #Add repository
  2. helm repo add sonatype https://sonatype.github.io/helm3-charts/

2、更改values.yaml文件

配置文件values.yaml中定义了所有我们需要的配置,我们可以自定义内容

  • 修改公共镜像为私有镜像 ```css image:

    Sonatype Official Public Image

    repository: sonatype/nexus3 tag: 3.33.1 pullPolicy: IfNotPresent

拉取公共镜像sonatype/nexus3:3.33.1 并推送到私有仓库,防止官方镜像变更,影响服务稳定

  1. - **修改服务访问ingress域名**
  2. ```css
  3. ......
  4. ingress:
  5. enabled: true
  6. annotations: {kubernetes.io/ingress.class: nginx}
  7. # kubernetes.io/ingress.class: nginx
  8. # kubernetes.io/tls-acme: "true"
  9. hostPath: /
  10. hostRepo: nexus.123.top
  11. tls:
  12. - secretName: nexus-123-tls
  13. hosts:
  14. - nexus.123.top
  15. ......
  • 数据持久化

在容器中运行的服务默认随着服务死亡,数据释放,而nexus 中存放着我们所需要的依赖jar包,不能随意丢失数据。
我这里使用的是阿里云上提供的storageClass,只需要申明需要的磁盘类型和大小即可。

  1. .......
  2. persistence:
  3. enabled: true
  4. accessMode: ReadWriteOnce
  5. ## If defined, storageClass: <storageClass>
  6. ## If set to "-", storageClass: "", which disables dynamic provisioning
  7. ## If undefined (the default) or set to null, no storageClass spec is
  8. ## set, choosing the default provisioner. (gp2 on AWS, standard on
  9. ## GKE, AWS & OpenStack)
  10. ##
  11. # existingClaim:
  12. # annotations:
  13. # "helm.sh/resource-policy": keep
  14. storageClass: "alicloud-disk-essd"
  15. storageSize: 100Gi
  16. # If PersistentDisk already exists you can create a PV for it by including the 2 following keypairs.
  17. # pdName: nexus-data-disk
  18. # fsType: ext4
  19. ......
  • java垃圾回收器可用CPU内核数

在nexus 3.16.1 以后启动运行后会提示下面错误
image.png
java垃圾回收器会计算其用于各种操作 (例如GC和ForkJoinPool) 的线程池大小的CPU数量,我们可以根据提示在java运行环境变量(JAVA_OPTS)中添加 “-XX:ActiveProcessorCount=4”

  1. ......
  2. env:
  3. - name: install4jAddVmParams
  4. value: "-Xms1200M -Xmx1200M -XX:MaxDirectMemorySize=2G -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:ActiveProcessorCount=4"
  5. - name: NEXUS_SECURITY_RANDOMPASSWORD
  6. value: "true"
  7. ......

完整values.yaml文件如下:

  1. statefulset:
  2. # This is not supported
  3. enabled: false
  4. # By default deploymentStrategy is set to rollingUpdate with maxSurge of 25% and maxUnavailable of 25% . you can change type to `Recreate` or can uncomment `rollingUpdate` specification and adjust them to your usage.
  5. deploymentStrategy: Recreate
  6. image:
  7. # Sonatype Official Public Image
  8. repository: sonatype/nexus3
  9. tag: 3.33.1
  10. pullPolicy: IfNotPresent
  11. nexus:
  12. docker:
  13. enabled: false
  14. registries: []
  15. # - host: chart.local
  16. # port: 5000
  17. # secretName: registrySecret
  18. env:
  19. - name: install4jAddVmParams
  20. value: "-Xms1200M -Xmx1200M -XX:MaxDirectMemorySize=2G -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"
  21. - name: NEXUS_SECURITY_RANDOMPASSWORD
  22. value: "true"
  23. properties:
  24. override: false
  25. data:
  26. nexus.scripts.allowCreation: true
  27. # See this article for ldap configuratioon options https://support.sonatype.com/hc/en-us/articles/216597138-Setting-Advanced-LDAP-Connection-Properties-in-Nexus-Repository-Manager
  28. #nexus.ldap.env.java.naming.security.authentication: simple
  29. # nodeSelector:
  30. # cloud.google.com/gke-nodepool: default-pool
  31. resources: {}
  32. # requests:
  33. ## Based on https://support.sonatype.com/hc/en-us/articles/115006448847#mem
  34. ## and https://twitter.com/analytically/status/894592422382063616:
  35. ## Xms == Xmx
  36. ## Xmx <= 4G
  37. ## MaxDirectMemory >= 2G
  38. ## Xmx + MaxDirectMemory <= RAM * 2/3 (hence the request for 4800Mi)
  39. ## MaxRAMFraction=1 is not being set as it would allow the heap
  40. ## to use all the available memory.
  41. # cpu: 250m
  42. # memory: 4800Mi
  43. # The ports should only be changed if the nexus image uses a different port
  44. nexusPort: 8081
  45. securityContext:
  46. fsGroup: 2000
  47. podAnnotations: {}
  48. livenessProbe:
  49. initialDelaySeconds: 30
  50. periodSeconds: 30
  51. failureThreshold: 6
  52. timeoutSeconds: 10
  53. path: /
  54. readinessProbe:
  55. initialDelaySeconds: 30
  56. periodSeconds: 30
  57. failureThreshold: 6
  58. timeoutSeconds: 10
  59. path: /
  60. # hostAliases allows the modification of the hosts file inside a container
  61. hostAliases: []
  62. # - ip: "192.168.1.10"
  63. # hostnames:
  64. # - "example.com"
  65. # - "www.example.com"
  66. imagePullSecrets: []
  67. nameOverride: ""
  68. fullnameOverride: ""
  69. deployment:
  70. # # Add annotations in deployment to enhance deployment configurations
  71. annotations: {}
  72. # # Add init containers. e.g. to be used to give specific permissions for nexus-data.
  73. # # Add your own init container or uncomment and modify the given example.
  74. initContainers:
  75. # - name: fmp-volume-permission
  76. # image: busybox
  77. # imagePullPolicy: IfNotPresent
  78. # command: ['chown','-R', '200', '/nexus-data']
  79. # volumeMounts:
  80. # - name: nexus-data
  81. # mountPath: /nexus-data
  82. # # Uncomment and modify this to run a command after starting the nexus container.
  83. postStart:
  84. command: # '["/bin/sh", "-c", "ls"]'
  85. preStart:
  86. command: # '["/bin/rm", "-f", "/path/to/lockfile"]'
  87. terminationGracePeriodSeconds: 120
  88. additionalContainers:
  89. additionalVolumes:
  90. additionalVolumeMounts:
  91. ingress:
  92. enabled: true
  93. annotations: {kubernetes.io/ingress.class: nginx}
  94. # kubernetes.io/ingress.class: nginx
  95. # kubernetes.io/tls-acme: "true"
  96. hostPath: /
  97. hostRepo: nexus.123.top
  98. tls:
  99. - secretName: nexus-123-tls
  100. hosts:
  101. - nexus.123.top
  102. service:
  103. name: nexus3
  104. enabled: true
  105. labels: {}
  106. annotations: {}
  107. serviceType: ClusterIP
  108. route:
  109. enabled: false
  110. name: docker
  111. portName: docker
  112. labels:
  113. annotations:
  114. # path: /docker
  115. nexusProxyRoute:
  116. enabled: false
  117. labels:
  118. annotations:
  119. # path: /nexus
  120. persistence:
  121. enabled: true
  122. accessMode: ReadWriteOnce
  123. ## If defined, storageClass: <storageClass>
  124. ## If set to "-", storageClass: "", which disables dynamic provisioning
  125. ## If undefined (the default) or set to null, no storageClass spec is
  126. ## set, choosing the default provisioner. (gp2 on AWS, standard on
  127. ## GKE, AWS & OpenStack)
  128. ##
  129. # existingClaim:
  130. # annotations:
  131. # "helm.sh/resource-policy": keep
  132. storageClass: "alicloud-disk-essd"
  133. storageSize: 100Gi
  134. # If PersistentDisk already exists you can create a PV for it by including the 2 following keypairs.
  135. # pdName: nexus-data-disk
  136. # fsType: ext4
  137. tolerations: []
  138. # # Enable configmap and add data in configmap
  139. config:
  140. enabled: false
  141. mountPath: /sonatype-nexus-conf
  142. data: []
  143. # # To use an additional secret, set enable to true and add data
  144. secret:
  145. enabled: false
  146. mountPath: /etc/secret-volume
  147. readOnly: true
  148. data: []
  149. serviceAccount:
  150. # Specifies whether a service account should be created
  151. create: true
  152. # Annotations to add to the service account
  153. annotations: {}
  154. # The name of the service account to use.
  155. # If not set and create is true, a name is generated using the fullname template
  156. name: ""
  157. psp:
  158. create: false

3、安装

  1. #Install chart
  2. helm install nexus -f values.yaml sonatype/nexus-repository-manager --version 33.1.0 -n infra

3.1、登陆kubernetes控制台查看服务安装结果

image.png
从控制台中我们可以看到服务在运行中,而且我们设置的ingress访问域名也成功设置,接下来我们就可以去拿着端点IP解析这个域名了。

3.2、获取集群中nexus服务登陆密码

根据提示我们知道默认用户名为admin, 而密码存放于pod中/nexus-data/admin.password文件中。

  1. $ kubectl get pod -n infra
  2. NAME READY STATUS RESTARTS AGE
  3. ......
  4. nexus-nexus-repository-manager-679b5fcdc9-bjffh 1/1 Running 0 11m
  5. $ kubectl exec -it nexus-nexus-repository-manager-679b5fcdc9-bjffh -n infra /bin/bash
  6. kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
  7. bash-4.4$ cat /nexus-data/admin.password
  8. fd1f7941e1adca25b166 bash-4.4$

image.png

3.3、重新设置密码

image.png
成功获取原始密码后,接下来系统会提示我们重新设置新的密码。

3.4、禁用匿名用户访问

image.png
根据提示直接下一步,即可完成初始化过程。

4、更新配置

  1. helm upgrade --namespace infra -f values.yaml nexus sonatype/nexus-repository-manager --version 33.1.0

ref: https://artifacthub.io/packages/helm/sonatype/nexus-repository-manager/33.1.0
https://github.com/qinxi89/helm3-charts