完成前期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
說明:
- 私有倉庫直接使用特定主機的特定端口映射,並利用指定主機的本地存儲。
- 有條件可以將倉庫獨立部署,如直接上Minikube。