kubernetes的容器镜像仓库有几种,cncf官网上有这几种容器镜像仓库的项目,虽然这里面没有nexus
但是我们可以从nexus提供丰富的仓库列表里面看到,docker镜像赫然在列。而且还提供helm chart的存储,基本上nexus在通用性上是无敌了。
首先我们来创建nexus,这里我们直接使用hostpath进行存储,再添加节点亲和性进行存储目录的固定。
svc端口则与我们后面要建立docker仓库的端口相对应。
apiVersion: apps/v1
kind: Deployment
metadata:
name: nexus
namespace: default
labels:
app: nexus
spec:
replicas: 1
selector:
matchLabels:
app: nexus
template:
metadata:
labels:
app: nexus
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: ip
operator: In
values:
- 172.16.12.100
containers:
- name: nexus
image: registry.cn-shenzhen.aliyuncs.com/liweilun/nexus:latest
# image: sonatype/nexus3
imagePullPolicy: IfNotPresent
# imagePullPolicy: Always
volumeMounts:
- mountPath: /nexus-data
name: nexusdata
volumes:
- name: nexusdata
hostPath:
path: /opt/nexus
type: Directory
dnsPolicy: ClusterFirst
restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: nexus
labels:
app: nexus
spec:
# type: NodePort
ports:
- name: nexus
port: 8081
targetPort: 8081
- name: dockergroup
port: 2000
targetPort: 2000
- name: dockerproxy
port: 2001
targetPort: 2001
- name: dockerhost
port: 2002
targetPort: 2002
# nodePort: 32000
- name: dockerhost2
port: 2003
targetPort: 2003
# nodePort: 32000
selector:
app: nexus
首先我们创建一个dockerhost仓库。我们利用ingress进行ssl卸载,然后禁止匿名用户pull,禁用docker v1 api,然后允许deploy
然后我们再来创建一个dockerproxy仓库。dockerproxy仓库主要利用阿里云等加速地址,缓存docker镜像,避免再次拉取。remote storage填写加速地址,docker index选择 use docker hub,foreign layer caching就是是否运行缓存docker镜像,填入*星号就是缓存所有地址的dockerhub镜像
最后再介绍下docker仓库有两种定时任务,一种是删除未完成上传的blob,另一种是删除未使用的mainfests和images。后一种主要针对频繁更新同一个tag的docker镜像
定时任务可以设置手动、一次、每小时、每天、每周、每月或者cron定时执行