harbor是由vmware开源的企业级docker repository,提供私有仓库,安全认证,权限管理,漏洞扫描及仓库复制等多种功能,因为之前搭建的harbor在线上环境存在各种各样的问题(之前搭建的方式目前发现已被官方宣布弃用https://github.com/vmware/harbor/blob/master/docs/kubernetes_deployment.md,如ui显示不正常,权限认证不正常),于是近期抽空用官方推荐的helm方式对harbor进行重新部署,并替换掉线上harbor
注意
: 初始化需要使用下面命令使用canary镜像,否则无法正常安装,会报错helm部署文件的格式不正确,目前这是一个已知issue:https://github.com/vmware/harbor/issues/4484
helm init --canary-image
helm init --canary-image --upgrade
git clone https://github.com/vmware/harbor
cd harbor/contrib/helm/harbor
https://minhaskamal.github.io/DownGit/#/home
helm dependency update
helm install . --debug --name hub --set externalDomain=harbor.my.domain
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-default-ingress
namespace: default
annotations:
kubernetes.io/ingress.class: "traefik"
spec:
rules:
- host: harbor.my.domain
http:
paths:
- path: /
backend:
serviceName: my-release-harbor-ui
servicePort: 80
注意: 我这里把所有自定义配置放到后面的附录中,供大家参考,同时可以点击https://github.com/Anteoy/harbor-helm/commit/226b296d130b4f956f8463eecf2aa473bc1e844c,查看我上传到github的自定义配置,从github阅读更清晰。
templates/adminserver/adminserver-cm.yaml
@@ -1,6 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
+ namespace: class100-ops
name: "{{ template "harbor.fullname" . }}-adminserver"
labels:
{{ include "harbor.labels" . | indent 4 }}
1 templates/adminserver/adminserver-secrets.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.fullname" . }}-adminserver"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
component: adminserver
5 templates/adminserver/adminserver-ss.yaml
@@ -2,6 +2,7 @@ apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
name: "{{ template "harbor.fullname" . }}-adminserver"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
component: adminserver
@@ -42,13 +43,15 @@ spec:
volumeMounts:
- name: adminserver-config
mountPath: /etc/adminserver/config
+ subPath: harbor-v1/adminserver/
- name: adminserver-key
mountPath: /etc/adminserver/key
subPath: key
volumes:
{{- if not .Values.persistence.enabled }}
- name: adminserver-config
- emptyDir: {}
+ persistentVolumeClaim:
+ claimName: harbor-pvc
{{- end }}
- name: adminserver-key
secret:
1 templates/adminserver/adminserver-svc.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: "{{ template "harbor.fullname" . }}-adminserver"
+ namespace: class100-ops
spec:
ports:
- port: 80
1 templates/clair/clair-cm.yaml
@@ -3,6 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "harbor.fullname" . }}-clair
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
component: clair
1 templates/clair/clair-dpl.yaml
@@ -3,6 +3,7 @@ apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "harbor.fullname" . }}-clair
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
component: clair
1 templates/clair/clair-svc.yaml
@@ -6,6 +6,7 @@ apiVersion: v1
kind: Service
metadata:
name: clair
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
spec:
1 templates/ingress/ingress.yaml
@@ -2,6 +2,7 @@ apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: "{{ template "harbor.fullname" . }}-ingress"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
annotations:
1 templates/ingress/secret.yaml
@@ -5,6 +5,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.fullname" . }}-ingress"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
type: kubernetes.io/tls
1 templates/jobservice/jobservice-cm.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ template "harbor.fullname" . }}-jobservice"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
data:
1 templates/jobservice/jobservice-dpl.yaml
@@ -2,6 +2,7 @@ apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: "{{ template "harbor.fullname" . }}-jobservice"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
component: jobservice
1 templates/jobservice/jobservice-secrets.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.fullname" . }}-jobservice"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
type: Opaque
1 templates/jobservice/jobservice-svc.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: "{{ template "harbor.fullname" . }}-jobservice"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
spec:
1 templates/mysql/mysql-secret.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.fullname" . }}-mysql"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
type: Opaque
7 templates/mysql/mysql-ss.yaml
@@ -2,6 +2,7 @@ apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
name: "{{ template "harbor.fullname" . }}-mysql"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
component: mysql
@@ -33,10 +34,12 @@ spec:
volumeMounts:
- name: mysql-data
mountPath: /var/lib/mysql
+ subPath: harbor-v1/mysql-data/
{{- if not .Values.persistence.enabled }}
volumes:
- - name: "mysql-data"
- emptyDir: {}
+ - name: mysql-data
+ persistentVolumeClaim:
+ claimName: harbor-pvc
{{- end -}}
{{- if .Values.persistence.enabled }}
volumeClaimTemplates:
1 templates/mysql/mysql-svc.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: "{{ template "harbor.fullname" . }}-mysql"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
spec:
1 templates/registry/registry-cm.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ template "harbor.fullname" . }}-registry"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
data:
1 templates/registry/registry-secret.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.fullname" . }}-registry"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
type: Opaque
5 templates/registry/registry-ss.yaml
@@ -2,6 +2,7 @@ apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
name: "{{ template "harbor.fullname" . }}-registry"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
component: registry
@@ -37,6 +38,7 @@ spec:
volumeMounts:
- name: registry-data
mountPath: /var/lib/registry
+ subPath: harbor-v1/registry-data/
- name: registry-root-certificate
mountPath: /etc/registry/root.crt
subPath: root.crt
@@ -47,7 +49,8 @@ spec:
{{- if not .Values.registry.objectStorage }}
{{- if not .Values.persistence.enabled }}
- name: registry-data
- emptyDir: {}
+ persistentVolumeClaim:
+ claimName: harbor-pvc
{{- end }}
{{- end }}
- name: registry-root-certificate
1 templates/registry/registry-svc.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: "{{ template "harbor.fullname" . }}-registry"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
spec:
1 templates/ui/ui-cm.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ template "harbor.fullname" . }}-ui"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
data:
3 templates/ui/ui-dpl.yaml
@@ -2,6 +2,7 @@ apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: "{{ template "harbor.fullname" . }}-ui"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
component: ui
@@ -54,8 +55,10 @@ spec:
subPath: private_key.pem
- name: ca-download
mountPath: /etc/ui/ca
+ subPath: harbor-v1/ui-ca/
- name: psc
mountPath: /etc/ui/token
+ subPath: harbor-v1/ui-psc/
volumes:
- name: ui-config
configMap:
1 templates/ui/ui-secrets.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.fullname" . }}-ui"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
type: Opaque
1 templates/ui/ui-svc.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: "{{ template "harbor.fullname" . }}-ui"
+ namespace: class100-ops
labels:
{{ include "harbor.labels" . | indent 4 }}
spec:
3 values.yaml
@@ -287,4 +287,5 @@ postgresql:
postgresPassword: not-a-secure-password
postgresDatabase: clair
persistence:
- enabled: false
+ enabled: true
+ existingClaim: harbor-pvc