1)nexus-data是nexus的存储目录,挂载到主机/data/maven-nexus目录上,迁移的时候拷贝这个目录即可,nexus的work目录权限必须为200:200,挂载的目录也要是此权限,执行chown R 200:200 /data/maven-nexus

2)使用官方的docker镜像,此处使用nexus3版本,docker pull sonatype/nexus3

3)从nexus目录下创建如下yaml配置文件
nexus-pv-pvc.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nexus3-data-pv
  labels:
    app: nexus3-data-pv
spec:
  capacity:
    storage: 500Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  hostPath:
    path: /data/maven-nexus

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nexus3-data-pvc
  labels:
    app: nexus3-data-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Gi
  selector:
    matchLabels:
      app: nexus3-data-pv

nexus-service.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: nexus3
  name: nexus3
spec:
  type: NodePort
  ports:
  - port: 8081
    targetPort: 8081
    nodePort: 38081
    name: web-ui
  - port: 5000
    targetPort: 5000
    nodePort: 35000
    name: docker-group
  - port: 8889
    targetPort: 8889
    nodePort: 38889
    name: docker-push
  selector:
    app: nexus3

nexus-deployment.yaml

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  labels:
    app: nexus3
  name: nexus3
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nexus3
  template:
    metadata:
      labels:
        app: nexus3
    spec:
      containers:
        - name: nexus3
          image: sonatype/nexus3:latest
          imagePullPolicy: IfNotPresent
          ports:
          - containerPort: 8081
            protocol: TCP
          volumeMounts:
          - name: nexus-data
            mountPath: /nexus-data 
      volumes:
        - name: nexus-data
          persistentVolumeClaim:
            claimName: nexus3-data-pvc
      nodeSelector:
        kubernetes.io/hostname: k8s-master1

执行kubectl apply -f nexus/,创建nexus pod及服务。

4)管理页面访问地址(admin/admin123),点击Repositories配置要缓存的远程仓库:http://ip:38081/

5)使用地址:

http://ip:38081/repository/jcenter/
http://ip:38081/repository/maven-central/

参考https://blog.csdn.net/lusyoe/article/details/79946951

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐