本地数据盘模式

把数据保存在node2和pod容器跑在node2

  1. mkdir -p /var/nexus-data
  2. chown -R 200 /var/nexus-data
  1. apiVersion: v1
  2. kind: PersistentVolume
  3. metadata:
  4. name: nexus-data
  5. spec:
  6. capacity:
  7. storage: 5Gi
  8. volumeMode: Filesystem
  9. accessModes:
  10. - ReadWriteOnce
  11. persistentVolumeReclaimPolicy: Retain
  12. storageClassName: local-storage
  13. local:
  14. path: /var/nexus-data
  15. nodeAffinity:
  16. required:
  17. nodeSelectorTerms:
  18. - matchExpressions:
  19. - key: kubernetes.io/hostname
  20. operator: In
  21. values:
  22. - node2
  23. ---
  24. apiVersion: v1
  25. kind: PersistentVolumeClaim
  26. metadata:
  27. name: nexus-data-pvc
  28. spec:
  29. accessModes:
  30. - ReadWriteOnce
  31. volumeMode: Filesystem
  32. resources:
  33. requests:
  34. storage: 5Gi
  35. storageClassName: local-storage
  36. ---
  37. apiVersion: apps/v1
  38. kind: Deployment
  39. metadata:
  40. name: nexus-deployment
  41. spec:
  42. replicas: 1
  43. selector:
  44. matchLabels:
  45. app: nexus
  46. template:
  47. metadata:
  48. labels:
  49. app: nexus
  50. spec:
  51. nodeSelector:
  52. kubernetes.io/hostname: "node2"
  53. containers:
  54. - name: nexus
  55. image: sonatype/nexus3
  56. ports:
  57. - containerPort: 8081
  58. - containerPort: 8082
  59. - containerPort: 8083
  60. volumeMounts:
  61. - mountPath: /nexus-data
  62. name: nexus-data
  63. volumes:
  64. - name: nexus-data
  65. persistentVolumeClaim:
  66. claimName: nexus-data-pvc
  67. ---
  68. apiVersion: v1
  69. kind: Service
  70. metadata:
  71. name: nexus-svc
  72. spec:
  73. selector:
  74. app: nexus
  75. type: NodePort
  76. ports:
  77. - name: web
  78. protocol: TCP
  79. port: 8081
  80. targetPort: 8081
  81. nodePort: 30081
  82. - name: docker
  83. protocol: TCP
  84. port: 8082
  85. targetPort: 8082
  86. nodePort: 30082
  87. - name: maven
  88. protocol: TCP
  89. port: 8083
  90. targetPort: 8083
  91. nodePort: 30083
  1. [root@master ~]# kubectl get all |grep nexus*
  2. pod/nexus-deployment-787578c7f6-w747l 1/1 Running 0 153m
  3. service/nexus-svc NodePort 10.233.25.187 <none> 8081:30081/TCP,8082:30082/TCP,8083:30083/TCP 6h54m
  4. deployment.apps/nexus-deployment 1/1 1 1 6h54m
  5. replicaset.apps/nexus-deployment-787578c7f6 1 1 1 156m
  6. [root@master ~]#
  1. apiVersion: extensions/v1beta1
  2. kind: Ingress
  3. metadata:
  4. name: nexus
  5. annotations:
  6. kubernetes.io/ingress.class: "nginx"
  7. spec:
  8. rules:
  9. - host: nexus.riyimei.cn
  10. http:
  11. paths:
  12. - path: /
  13. pathType: ImplementationSpecific
  14. backend:
  15. serviceName: nexus-svc
  16. servicePort: 8081
  17. - path: /
  18. pathType: ImplementationSpecific
  19. backend:
  20. serviceName: nexus-svc
  21. servicePort: 8082
  22. - path: /
  23. pathType: ImplementationSpecific
  24. backend:
  25. serviceName: nexus-svc
  26. servicePort: 8083

Ingress 暴露服务

  1. apiVersion: v1
  2. kind: PersistentVolume
  3. metadata:
  4. name: nexus-data
  5. spec:
  6. capacity:
  7. storage: 5Gi
  8. volumeMode: Filesystem
  9. accessModes:
  10. - ReadWriteOnce
  11. persistentVolumeReclaimPolicy: Retain
  12. storageClassName: local-storage
  13. local:
  14. path: /var/nexus-data
  15. nodeAffinity:
  16. required:
  17. nodeSelectorTerms:
  18. - matchExpressions:
  19. - key: kubernetes.io/hostname
  20. operator: In
  21. values:
  22. - node2
  23. #storageClassName: nfs
  24. #nfs:
  25. #path: /var/nexus-data
  26. #server: 192.168.0.250
  27. ---
  28. apiVersion: v1
  29. kind: PersistentVolumeClaim
  30. metadata:
  31. name: nexus-data-pvc
  32. spec:
  33. accessModes:
  34. - ReadWriteOnce
  35. volumeMode: Filesystem
  36. resources:
  37. requests:
  38. storage: 5Gi
  39. storageClassName: local-storage
  40. ---
  41. apiVersion: apps/v1
  42. kind: Deployment
  43. metadata:
  44. name: nexus-deployment
  45. spec:
  46. replicas: 1
  47. selector:
  48. matchLabels:
  49. app: nexus
  50. template:
  51. metadata:
  52. labels:
  53. app: nexus
  54. spec:
  55. nodeSelector:
  56. kubernetes.io/hostname: "node2"
  57. containers:
  58. - name: nexus
  59. image: sonatype/nexus3
  60. ports:
  61. - containerPort: 8081
  62. - containerPort: 8082
  63. - containerPort: 8083
  64. volumeMounts:
  65. - mountPath: /nexus-data
  66. name: nexus-data
  67. volumes:
  68. - name: nexus-data
  69. persistentVolumeClaim:
  70. claimName: nexus-data-pvc
  71. ---
  72. apiVersion: v1
  73. kind: Service
  74. metadata:
  75. name: nexus-svc
  76. spec:
  77. selector:
  78. app: nexus
  79. type: ClusterIP
  80. ports:
  81. - name: web
  82. protocol: TCP
  83. port: 8081
  84. - name: docker
  85. protocol: TCP
  86. port: 8082
  87. - name: maven
  88. protocol: TCP
  89. port: 8083
  90. ---
  91. apiVersion: extensions/v1beta1
  92. kind: Ingress
  93. metadata:
  94. name: nexus
  95. annotations:
  96. kubernetes.io/ingress.class: "nginx"
  97. spec:
  98. rules:
  99. - host: nexus.riyimei.cn
  100. http:
  101. paths:
  102. - path: /
  103. pathType: ImplementationSpecific
  104. backend:
  105. serviceName: nexus-svc
  106. servicePort: 8081
  107. - path: /
  108. pathType: ImplementationSpecific
  109. backend:
  110. serviceName: nexus-svc
  111. servicePort: 8082
  112. - path: /
  113. pathType: ImplementationSpecific
  114. backend:
  115. serviceName: nexus-svc
  116. servicePort: 8083
  1. [root@master ~]# kubectl get all |grep nexus*
  2. pod/nexus-deployment-787578c7f6-w747l 1/1 Running 0 172m
  3. service/nexus-svc ClusterIP 10.233.25.187 <none> 8081/TCP,8082/TCP,8083/TCP 7h14m
  4. deployment.apps/nexus-deployment 1/1 1 1 7h14m
  5. replicaset.apps/nexus-deployment-787578c7f6 1 1 1 176m
  6. [root@master ~]# kubectl get ingress |grep nexus*
  7. Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
  8. nexus <none> nexus.riyimei.cn 192.168.11.151,192.168.11.152 80 15m
  9. [root@master ~]# kubectl get pvc |grep nexus*
  10. nexus-data-pvc Bound nexus-data 5Gi RWO local-storage 7h15m
  11. [root@master ~]# kubectl get pv |grep nexus*
  12. nexus-data 5Gi RWO Retain Bound default/nexus-data-pvc local-storage 7h15m
  13. [root@master ~]#

nfs共享模式

  1. apiVersion: v1
  2. kind: PersistentVolume
  3. metadata:
  4. name: nexus-data
  5. spec:
  6. capacity:
  7. storage: 5Gi
  8. volumeMode: Filesystem
  9. accessModes:
  10. - ReadWriteOnce
  11. persistentVolumeReclaimPolicy: Retain
  12. storageClassName: nfs
  13. nfs:
  14. path: /var/nfs/nexus-data
  15. server: 192.168.0.250
  16. ---
  17. apiVersion: v1
  18. kind: PersistentVolumeClaim
  19. metadata:
  20. name: nexus-data-pvc
  21. spec:
  22. accessModes:
  23. - ReadWriteOnce
  24. volumeMode: Filesystem
  25. resources:
  26. requests:
  27. storage: 5Gi
  28. storageClassName: nfs
  29. ---
  30. apiVersion: apps/v1
  31. kind: Deployment
  32. metadata:
  33. name: nexus-deployment
  34. spec:
  35. replicas: 1
  36. selector:
  37. matchLabels:
  38. app: nexus
  39. template:
  40. metadata:
  41. labels:
  42. app: nexus
  43. spec:
  44. containers:
  45. - name: nexus
  46. image: sonatype/nexus3
  47. ports:
  48. - containerPort: 8081
  49. - containerPort: 8082
  50. - containerPort: 8083
  51. volumeMounts:
  52. - mountPath: /nexus-data
  53. name: nexus-data
  54. volumes:
  55. - name: nexus-data
  56. persistentVolumeClaim:
  57. claimName: nexus-data-pvc
  58. ---
  59. apiVersion: v1
  60. kind: Service
  61. metadata:
  62. name: nexus-svc
  63. spec:
  64. selector:
  65. app: nexus
  66. type: NodePort
  67. ports:
  68. - name: web
  69. protocol: TCP
  70. port: 8081
  71. targetPort: 8081
  72. nodePort: 30081
  73. - name: docker
  74. protocol: TCP
  75. port: 8082
  76. targetPort: 8082
  77. nodePort: 30082
  78. - name: maven
  79. protocol: TCP
  80. port: 8083
  81. targetPort: 8083
  82. nodePort: 30083

软件初始化密码

[root@node2 ~]#
[root@node2 ~]# cd /var/nexus-data/
[root@node2 nexus-data]# ls -l
total 28
-rw-r--r--   1 200 200   36 Jul 31 16:23 admin.password
drwxr-xr-x   3 200 200   21 Jul 31 16:23 blobs
drwxr-xr-x 331 200 200 8192 Jul 31 16:22 cache
drwxr-xr-x   6 200 200  113 Jul 31 16:23 db
drwxr-xr-x   3 200 200   19 Jul 31 16:23 elasticsearch
drwxr-xr-x   3 200 200   45 Jul 31 16:03 etc
drwxr-xr-x   2 200 200    6 Jul 31 16:02 generated-bundles
drwxr-xr-x   2 200 200   33 Jul 31 16:02 instances
drwxr-xr-x   3 200 200   19 Jul 31 16:02 javaprefs
-rw-r--r--   1 200 200    1 Jul 31 16:22 karaf.pid
drwxr-xr-x   3 200 200   18 Jul 31 16:03 keystores
-rw-r--r--   1 200 200   35 Jul 31 16:22 lock
drwxr-xr-x   3 200 200  112 Jul 31 16:23 log
drwxr-xr-x   2 200 200    6 Jul 31 16:03 orient
-rw-r--r--   1 200 200    5 Jul 31 16:22 port
drwxr-xr-x   2 200 200    6 Jul 31 16:03 restore-from-backup
drwxr-xr-x   8 200 200  281 Jul 31 16:23 tmp
[root@node2 nexus-data]# cat admin.password
3218527c-1c47-497c-867c-8b72188b01d0[root@node2 nexus-data]# pwd
/var/nexus-data
[root@node2 nexus-data]#

1627727816(1).png

1627727917(1).png