背景
机房搬迁,趁此时机,将 Nexus3也容器化管理
docker 容器化测试
1.复制之前数据到另一个目录进行 docker测试
cp -a /some/dir/nexus-data/db/ /opt/nexus-data/
cp -a /some/dir/nexus-data/blobs/ /opt/nexus-data/
docker rm -f nexus-test
docker run -d -p 8085:8081 --name nexus-test -v /opt/nexus-data/db:/nexus-data/db -v /opt/nexus-data/blobs:/nexus-data/blobs sonatype/nexus3:3.14.0
#docker restart nexus-test
docker logs -f nexus-test
# 注 这里覆盖了/nexus-data/db 所以也不会有密码文件产生,服务将会沿用之前密码
# 容器版本最好也和之前服务的版本一致,不然可能会出现迁移数据不生效问题
- 访问 http://172.18.154.185:8085/#browse/search/maven 测试文件已都存在 ok 准备迁移k8s
k8s yaml文件
cat nex.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: nexus3
name: nexus3
namespace: log-others
spec:
replicas: 1
selector:
matchLabels:
k8s-app: nexus3
template:
metadata:
labels:
k8s-app: nexus3
name: nexus3
namespace: log-others
spec:
containers:
- name: nexus3
image: sonatype/nexus3:3.14.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8081
name: web
protocol: TCP
#livenessProbe:
# httpGet:
# path: /
# port: 8081
# initialDelaySeconds: 60
# periodSeconds: 30
# failureThreshold: 6
#readinessProbe:
# httpGet:
# path: /
# port: 8081
# initialDelaySeconds: 60
# periodSeconds: 30
# failureThreshold: 6
resources:
limits:
cpu: 2000m
memory: 4Gi
requests:
cpu: 500m
memory: 512Mi
volumeMounts:
- name: nexus-data
mountPath: /nexus-data
volumes:
- name: nexus-data
persistentVolumeClaim:
claimName: nexus-data-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nexus-data-pvc
namespace: log-others
spec:
accessModes:
- ReadWriteOnce
storageClassName: "csi-rbd-sc"
resources:
requests:
storage: 30Gi
---
apiVersion: v1
kind: Service
metadata:
name: nexus3
namespace: log-others
labels:
k8s-app: nexus3
spec:
selector:
k8s-app: nexus3
type: ClusterIP
ports:
- name: web
protocol: TCP
port: 8081
targetPort: 8081
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nexus3
namespace: log-others
labels:
k8s-app: nexus3
spec:
rules:
- host: "xxx.com"
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: nexus3
port:
number: 8081
我们这里直接访问域名进行验证 xxx.com , 测试没问题再手动迁移一下数据(这里比较着急,优雅可以写个初始化镜像)
kubectl -n log-others exec -it nexus3-7c7f5bcbb5-hw67s -- sh
#这里吧之前的文件已经压缩上传到了公司的下载服务器上 进行下载、解压目录
curl -o wj.tgz http://xxx/wj.tgz
tar xvf wj.tgz
...
#完事之后重启pod
kubectl -n log-others delete nexus3-7c7f5bcbb5-hw67s
参考文档
在k8s集群部署Nexus:https://www.cnblogs.com/ssgeek/p/12270079.html