Kubernetes集群实践(06)使用Nexus3部署私有仓库

完成前期Kubernetes环境部署后,再部署其它容器,如果还是docker load -i 导入真心很不方便了,急需引入私有仓库。而私有仓库也有几个选择,docker官方的registry很简单,但有个最大的问题就是没有UI,镜像的管理也只有通过RESTful API来操作,很不方便(虽然有他人开发的界面,但不太成熟,个人可以自己把握)。VMware的Harbor和SUSE Portus都不错,但Sonatype的Nexus3更加简单,而且还可以做Maven、yum的源。因此,此处我选取Nexus3作为我的私有仓库。
官方网站上已经有详细的安装文档,本人在此将自己的安装配置做了下笔记记录。

编写部署文件(含服务暴露)

nexus3-deployment.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: nexus
spec:
  selector:
    matchLabels:
      app: nexus
  template:
    metadata:
      labels:
        app: nexus
    spec:
      containers:
      - name: nexus
        image: sonatype/nexus3:3.21.1
        imagePullPolicy: IfNotPresent
        ports:
        - name: web # web ui for management
          containerPort: 8081 # port of web management
                hostPort: 8081 # use hostport directly for access
          protocol: TCP
        - name: docker-office # the name of internal docker registry
          containerPort: 8082 # port of docker registry
          hostPort: 8082 # use hostport directly for access
        resources:
          requests:
            cpu: 4000m # default reqirement
        volumeMounts:
        - name: nexus-data
          mountPath: /nexus-data
      volumes:
      - name: nexus-data
        hostPath:
          path: /home/nexus-data # use local path for selected host
      nodeSelector:
        "kubernetes.io/hostname": nf5270m4-repo
      tolerations:
      - key: "node-role.kubernetes.io/node"
        operator: "Exists"
        effect: "PreferNoSchedule"
---
apiVersion: v1
kind: Service
metadata:
  name: nexus
spec:
  selector:
    app: nexus
  ports:
  - name: webadmin
    port: 8081
    targetPort: 8081
  - name: nexus3docker
    port: 8082
    targetPort: 8082

说明:

  1. 私有仓库直接使用特定主机的特定端口映射,并利用指定主机的本地存储。
  2. 有条件可以将仓库独立部署,如直接上Minikube。

猜你喜欢

转载自blog.51cto.com/huanghai/2476865