计算机系统应用教程网站

网站首页 > 技术文章 正文

Nexus in k8s

btikc 2024-09-04 03:09:49 技术文章 10 ℃ 0 评论

nexus 作为一款优秀的仓库管理工具,不仅默认支持maven、docker、npm、yum、apt等多种仓库的配置。nexus3 最新的还新增了store隔离存储功能,通过UI创建不同的store为repo指定不同的存储空间,达到物理隔离。

一、安装方式

从yaml创建


yaml文件内容

---
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: '8'
    k8s.kuboard.cn/displayName: 私有仓库
    k8s.kuboard.cn/ingress: 'false'
    k8s.kuboard.cn/service: NodePort
    k8s.kuboard.cn/workload: nexus3
  creationTimestamp: '2021-03-10T09:29:49Z'
  generation: 9
  labels:
    k8s.kuboard.cn/layer: ''
    k8s.kuboard.cn/name: nexus3
  managedFields:
    - apiVersion: apps/v1
      fieldsType: FieldsV1
      fieldsV1:
        'f:metadata': {}
        'f:spec':
          'f:selector': {}
          'f:strategy': {}
          'f:template':
            'f:metadata': {}
            'f:spec':
              'f:containers':
                'k:{"name":"nexus3"}':
                  'f:env': {}
                  'f:ports': {}
                  'f:volumeMounts': {}
              'f:volumes':
                'k:{"name":"nfs"}': {}
      manager: Mozilla
      operation: Update
      time: '2021-03-11T02:11:29Z'
    - apiVersion: apps/v1
      fieldsType: FieldsV1
      fieldsV1:
        'f:metadata': {}
      manager: kube-controller-manager
      operation: Update
      time: '2021-03-11T02:11:33Z'
  name: nexus3
  namespace: default
  resourceVersion: '303907'
  selfLink: /apis/apps/v1/namespaces/default/deployments/nexus3
  uid: 79b4d561-90d2-4111-863d-3015147cefff
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      k8s.kuboard.cn/layer: ''
      k8s.kuboard.cn/name: nexus3
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        k8s.kuboard.cn/layer: ''
        k8s.kuboard.cn/name: nexus3
    spec:
      containers:
        - env:
            - name: NEXUS_CONTEXT
              value: nexus
          image: sonatype/nexus3
          imagePullPolicy: Always
          name: nexus3
          ports:
            - containerPort: 8081
              protocol: TCP
            - containerPort: 8082
              protocol: TCP
            - containerPort: 8083
              protocol: TCP
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /nexus-data
              name: nfs
              subPath: nexus-data
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      terminationGracePeriodSeconds: 30
      volumes:
        - name: nfs
          nfs:
            path: /root/nfs_root
            server: 10.0.190.170
status:
  availableReplicas: 1
  conditions:
    - lastTransitionTime: '2021-03-10T10:09:19Z'
      lastUpdateTime: '2021-03-11T02:11:31Z'
      message: ReplicaSet "nexus3-57bc8fcc79" has successfully progressed.
      reason: NewReplicaSetAvailable
      status: 'True'
      type: Progressing
    - lastTransitionTime: '2021-03-11T02:11:33Z'
      lastUpdateTime: '2021-03-11T02:11:33Z'
      message: Deployment has minimum availability.
      reason: MinimumReplicasAvailable
      status: 'True'
      type: Available
  observedGeneration: 9
  readyReplicas: 1
  replicas: 1
  updatedReplicas: 1

---
apiVersion: v1
kind: Service
metadata:
  annotations:
    k8s.kuboard.cn/displayName: 企业级开源私有仓库
    k8s.kuboard.cn/workload: nexus3
  creationTimestamp: '2021-03-10T09:29:49Z'
  labels:
    k8s.kuboard.cn/layer: ''
    k8s.kuboard.cn/name: nexus3
  managedFields:
    - apiVersion: v1
      fieldsType: FieldsV1
      fieldsV1:
        'f:metadata': {}
        'f:spec':
          'f:ports': {}
      manager: Mozilla
      operation: Update
      time: '2021-03-11T02:11:44Z'
  name: nexus3
  namespace: default
  resourceVersion: '303910'
  selfLink: /api/v1/namespaces/default/services/nexus3
  uid: c7316b66-e540-4156-802c-7952529fe5c6
spec:
  clusterIP: 10.244.68.123
  externalTrafficPolicy: Cluster
  ports:
    - name: xn5cfx
      nodePort: 32113
      port: 8081
      protocol: TCP
      targetPort: 8081
    - name: hpm4ed
      nodePort: 31658
      port: 8082
      protocol: TCP
      targetPort: 8082
    - name: jhhfxg
      nodePort: 31997
      port: 8083
      protocol: TCP
      targetPort: 8083
  selector:
    k8s.kuboard.cn/layer: ''
    k8s.kuboard.cn/name: nexus3
  sessionAffinity: None
  type: NodePort

创建工作负载

效果图

运行

http://10.0.190.173:32113/nexus

账号和密码

admin/admin123


二、创建私有docker仓库

点击右上角进行登录,通过初始用户名和密码进行登录(admin/admin123):


点击设置界面,选择Repositories,点击Create repository,如下图所示:


选择仓库类型,这里Docker有三种类型,分别是group、hosted、proxy。这里只演示hosted类型,所以选择docker(hosted),如下图:

注:Docker镜像仓库类型含义解释如下:

  hosted : 本地存储,即同docker官方仓库一样提供本地私服功能

  proxy : 提供代理其他仓库的类型,如docker中央仓库

  group : 组类型,实质作用是组合多个仓库为一个地址

指定docker仓库的名称、指定一个端口用来通过http的方式进行访问仓库、勾选是否支持docker API V1,然后create repository;

因为我们测试的时候不是使用加密的HTTPS进行访问,所以这里需要增加一个docker的启动参数,给他指定私库的地址,如下:

编辑/etc/docker/daemon.json 增加如下内容,当然也可通过启动参数增加

{

"registry-mirrors": ["http://registry.shassel.com:31658"]

"insecure-registries":["registry.shassel.com:31658"]

}

重启docker进程: systemctl restart docker

编辑host文件将ip映射到域名

10.0.190.170 registry.shassel.com

登录docker仓库

docker login registry.shassel.com:31658

输入账号admin密码admin123即可登录成功

[root@jeecg-master-2 nexus-data]# docker login registry.shassel.com:31658
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
[root@jeecg-master-2 nexus-data]# 


三、上传镜像

maven打包springboot项目

将打包好的jar包放到服务器指定目录,编写好dockerfile文件

例如:

FROM anapsix/alpine-java:8_server-jre_unlimited

MAINTAINER jeecgos@163.com

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

RUN mkdir -p /jeecg-cloud-gateway

WORKDIR /jeecg-cloud-gateway

EXPOSE 9999

ADD ./target/jeecg-cloud-gateway-2.4.2.jar ./

CMD sleep 10;java -Dfile.encoding=utf-8 -Djava.security.egd=file:/dev/./urandom -jar jeecg-cloud-gateway-2.4.2.jar

构建镜像

docker build -t gateway:v1 .

打标记


docker tag gateway:v1 registry.shassel.com:31658/gateway:v2.5.5

推送镜像

docker push registry.shassel.com:31658/gateway:v2.5.5

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表