Kubernetes部署(一):架構(gòu)及功能說明
Kubernetes部署(二):系統(tǒng)環(huán)境初始化
Kubernetes部署(三):CA證書制作
Kubernetes部署(四):ETCD集群部署
Kubernetes部署(五):Haproxy、Keppalived部署
Kubernetes部署(六):Master節(jié)點(diǎn)部署
Kubernetes部署(七):Node節(jié)點(diǎn)部署
Kubernetes部署(八):Flannel網(wǎng)絡(luò)部署
Kubernetes部署(九):CoreDNS、Dashboard、Ingress部署
Kubernetes部署(十):儲(chǔ)存之glusterfs和heketi部署
Kubernetes部署(十一):管理之Helm和Rancher部署
Kubernetes部署(十二):helm部署harbor企業(yè)級(jí)鏡像倉庫
創(chuàng)新互聯(lián)從2013年創(chuàng)立,先為加查等服務(wù)建站,加查等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為加查企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
harbor官方github:https://github.com/goharbor
Harbor是一個(gè)用于存儲(chǔ)和分發(fā)Docker鏡像的企業(yè)級(jí)Registry服務(wù)器。Harbor通過添加用戶通常需要的功能(如安全性,身份和管理)來擴(kuò)展開源Docker Distribution。使registry更接近構(gòu)建和運(yùn)行環(huán)境可以提高圖像傳輸效率。Harbor支持在registry之間復(fù)制映像,還提供高級(jí)安全功能,如用戶管理,訪問控制和活動(dòng)審計(jì)。
將h.cnlinux.club
和n.cnlinux.club
的A記錄解析到我的負(fù)載均衡IP 10.31.90.200
,用于創(chuàng)建ingress。
[root@node-01 harbor]# wget https://github.com/goharbor/harbor-helm/archive/1.0.0.tar.gz -O harbor-helm-v1.0.0.tar.gz
harbor-helm-v1.0.0.tar.gz
文件中的values.yaml
文件,并放到和harbor-helm-v1.0.0.tar.gz同一級(jí)的目錄中。修改values.yaml,我的配置修改了如下幾個(gè)字段:
需要說明的是如果k8s集群中存在storageclass就可以直接用storageclass,在幾個(gè)persistence.persistentVolumeClaim.XXX.storageClass中指定storageclass名就可以了,會(huì)自動(dòng)創(chuàng)建多個(gè)pvc,但是我這里為了防止創(chuàng)建多個(gè)pvc增加管理難度,我在部署前創(chuàng)建了一個(gè)pvc,harbor下所有的服務(wù)都使用這一個(gè)pvc,具體每個(gè)字段的作用請(qǐng)查看官方文檔https://github.com/goharbor/harbor-helm。
expose.ingress.hosts.core
xpose.ingress.hosts.notary
externalURL
persistence.persistentVolumeClaim.registry.existingClaim
persistence.persistentVolumeClaim.registry.subPath
persistence.persistentVolumeClaim.chartmuseum.existingClaim
persistence.persistentVolumeClaim.chartmuseum.subPath
persistence.persistentVolumeClaim.jobservice.existingClaim
persistence.persistentVolumeClaim.jobservice.subPath
persistence.persistentVolumeClaim.database.existingClaim
persistence.persistentVolumeClaim.database.subPath
persistence.persistentVolumeClaim.redis.existingClaim
persistence.persistentVolumeClaim.redis.subPath
expose:
type: ingress
tls:
enabled: true
secretName: ""
notarySecretName: ""
commonName: ""
ingress:
hosts:
core: h.cnlinux.club
notary: n.cnlinux.club
annotations:
ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
ingress.kubernetes.io/proxy-body-size: "0"
nginx.ingress.kubernetes.io/proxy-body-size: "0"
clusterIP:
name: harbor
ports:
httpPort: 80
httpsPort: 443
notaryPort: 4443
nodePort:
name: harbor
ports:
http:
port: 80
nodePort: 30002
https:
port: 443
nodePort: 30003
notary:
port: 4443
nodePort: 30004
externalURL: https://h.cnlinux.club
persistence:
enabled: true
resourcePolicy: "keep"
persistentVolumeClaim:
registry:
existingClaim: "pvc-harbor"
storageClass: ""
subPath: "registry"
accessMode: ReadWriteOnce
size: 5Gi
chartmuseum:
existingClaim: "pvc-harbor"
storageClass: ""
subPath: "chartmuseum"
accessMode: ReadWriteOnce
size: 5Gi
jobservice:
existingClaim: "pvc-harbor"
storageClass: ""
subPath: "jobservice"
accessMode: ReadWriteOnce
size: 1Gi
database:
existingClaim: "pvc-harbor"
storageClass: ""
subPath: "database"
accessMode: ReadWriteOnce
size: 1Gi
redis:
existingClaim: "pvc-harbor"
storageClass: ""
subPath: "redis"
accessMode: ReadWriteOnce
size: 1Gi
imageChartStorage:
type: filesystem
filesystem:
rootdirectory: /storage
imagePullPolicy: IfNotPresent
logLevel: debug
harborAdminPassword: "Harbor12345"
secretKey: "not-a-secure-key"
nginx:
image:
repository: goharbor/nginx-photon
tag: v1.7.0
replicas: 1
nodeSelector: {}
tolerations: []
affinity: {}
podAnnotations: {}
portal:
image:
repository: goharbor/harbor-portal
tag: v1.7.0
replicas: 1
nodeSelector: {}
tolerations: []
affinity: {}
podAnnotations: {}
core:
image:
repository: goharbor/harbor-core
tag: v1.7.0
replicas: 1
nodeSelector: {}
tolerations: []
affinity: {}
podAnnotations: {}
adminserver:
image:
repository: goharbor/harbor-adminserver
tag: v1.7.0
replicas: 1
nodeSelector: {}
tolerations: []
affinity: {}
podAnnotations: {}
jobservice:
image:
repository: goharbor/harbor-jobservice
tag: v1.7.0
replicas: 1
maxJobWorkers: 10
jobLogger: file
nodeSelector: {}
tolerations: []
affinity: {}
podAnnotations: {}
registry:
registry:
image:
repository: goharbor/registry-photon
tag: v2.6.2-v1.7.0
controller:
image:
repository: goharbor/harbor-registryctl
tag: v1.7.0
replicas: 1
nodeSelector: {}
tolerations: []
affinity: {}
podAnnotations: {}
chartmuseum:
enabled: true
image:
repository: goharbor/chartmuseum-photon
tag: v0.7.1-v1.7.0
replicas: 1
nodeSelector: {}
tolerations: []
affinity: {}
podAnnotations: {}
clair:
enabled: true
image:
repository: goharbor/clair-photon
tag: v2.0.7-v1.7.0
replicas: 1
httpProxy:
httpsProxy:
updatersInterval: 12
nodeSelector: {}
tolerations: []
affinity: {}
podAnnotations: {}
notary:
enabled: true
server:
image:
repository: goharbor/notary-server-photon
tag: v0.6.1-v1.7.0
replicas: 1
signer:
image:
repository: goharbor/notary-signer-photon
tag: v0.6.1-v1.7.0
replicas: 1
nodeSelector: {}
tolerations: []
affinity: {}
podAnnotations: {}
database:
type: internal
internal:
image:
repository: goharbor/harbor-db
tag: v1.7.0
password: "changeit"
nodeSelector: {}
tolerations: []
affinity: {}
podAnnotations: {}
redis:
type: internal
internal:
image:
repository: goharbor/redis-photon
tag: v1.7.0
nodeSelector: {}
tolerations: []
affinity: {}
podAnnotations: {}
因?yàn)閔arbor需要使用到MySQL,為防止mysql在調(diào)度過程中造成數(shù)據(jù)丟失,我們需要將mysql的數(shù)據(jù)存儲(chǔ)在gluster的存儲(chǔ)卷里。
[root@node-01 harbor]# vim pvc-harbor.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-harbor
spec:
storageClassName: gluster-heketi
accessModes:
- ReadWriteMany
resources:
requests:
storage: 50Gi
[root@node-01 harbor]# kubectl apply -f pvc-harbor.yaml
[root@node-01 harbor]# helm install --name harbor harbor-helm-v1.0.0.tar.gz -f values.yaml
如果安裝不成功可以用
helm del --purge harbor
刪除重新安裝。
在一段時(shí)間后可以看到harbor所有相關(guān)的pod都已經(jīng)運(yùn)行起來了,我們就可以訪問了,默認(rèn)用戶密碼是admin/Harbor12345,可以通過修改values.yaml來更改默認(rèn)的用戶名和密碼。
[root@node-01 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
harbor-harbor-adminserver-7fffc7bf4d-vj845 1/1 Running 1 15d
harbor-harbor-chartmuseum-bdf64f899-brnww 1/1 Running 0 15d
harbor-harbor-clair-8457c45dd8-9rgq8 1/1 Running 1 15d
harbor-harbor-core-7fc454c6d8-b6kvs 1/1 Running 1 15d
harbor-harbor-database-0 1/1 Running 0 15d
harbor-harbor-jobservice-7895949d6b-zbwkf 1/1 Running 1 15d
harbor-harbor-notary-server-57dd94bf56-txdkl 1/1 Running 0 15d
harbor-harbor-notary-signer-5d64c5bf8d-kppts 1/1 Running 0 15d
harbor-harbor-portal-648c56499f-g28rz 1/1 Running 0 15d
harbor-harbor-redis-0 1/1 Running 0 15d
harbor-harbor-registry-5cd9c49489-r92ph 2/2 Running 0 15d
接下來我們創(chuàng)建test的私有項(xiàng)目用來測(cè)試。
for n in `seq -w 01 06`;do ssh node-$n "mkdir -p /etc/docker/certs.d/h.cnlinux.club";done
#將下載下來的harbor CA證書拷貝到每個(gè)node節(jié)點(diǎn)的etc/docker/certs.d/h.cnlinux.club目錄下
for n in `seq -w 01 06`;do scp ca.crt node-$n:/etc/docker/certs.d/h.cnlinux.club/;done
.docker/config.json
里。[root@node-06 ~]# docker login h.cnlinux.club
Username: admin
Password:
Login Succeeded
[root@node-06 ~]# cat .docker/config.json
{
"auths": {
"h.cnlinux.club": {
"auth": "YWRtaW46SGFyYm9yMTIzNDU="
}
}
}
[root@node-06 ~]# docker pull nginx:latest
[root@node-06 ~]# docker tag nginx:latest h.cnlinux.club/test/nginx:latest
[root@node-06 ~]# docker push h.cnlinux.club/test/nginx:latest
問題:如果我的k8s集群很多的node節(jié)點(diǎn)是不是每個(gè)node節(jié)點(diǎn)都要上去登錄才能pull harbor倉庫的鏡像?這樣是不是就非常麻煩了?
kubernetes.io/dockerconfigjson
就是用來解決這種問題的。[root@node-06 ~]# cat .docker/config.json |base64
ewoJImF1dGhzIjogewoJCSJoLmNubGludXguY2x1YiI6IHsKCQkJImF1dGgiOiAiWVdSdGFXNDZTR0Z5WW05eU1USXpORFU9IgoJCX0KCX0sCgkiSHR0cEhlYWRlcnMiOiB7CgkJIlVzZXItQWdlbnQiOiAiRG9ja2VyLUNsaWVudC8xOC4wNi4xLWNlIChsaW51eCkiCgl9Cn0=
apiVersion: v1
kind: Secret
metadata:
name: harbor-registry-secret
namespace: default
data:
.dockerconfigjson: ewoJImF1dGhzIjogewoJCSJoLmNubGludXguY2x1YiI6IHsKCQkJImF1dGgiOiAiWVdSdGFXNDZTR0Z5WW05eU1USXpORFU9IgoJCX0KCX0sCgkiSHR0cEhlYWRlcnMiOiB7CgkJIlVzZXItQWdlbnQiOiAiRG9ja2VyLUNsaWVudC8xOC4wNi4xLWNlIChsaW51eCkiCgl9Cn0=
type: kubernetes.io/dockerconfigjson
[root@node-01 ~]# kubectl create -f harbor-registry-secret.yaml
secret/harbor-registry-secret created
10.31.90.200
。apiVersion: apps/v1
kind: Deployment
metadata:
name: deploy-nginx
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: h.cnlinux.club/test/nginx:latest
ports:
- containerPort: 80
imagePullSecrets:
- name: harbor-registry-secret
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
selector:
app: nginx
ports:
- name: nginx
protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx
annotations:
# nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: nginx.cnlinux.club
http:
paths:
- path:
backend:
serviceName: nginx
servicePort: 80
[root@node-01 ~]# kubectl get pod -o wide|grep nginx
deploy-nginx-647f9649f5-88mkt 1/1 Running 0 2m41s 10.34.0.5 node-06 <none> <none>
deploy-nginx-647f9649f5-9z842 1/1 Running 0 2m41s 10.40.0.5 node-04 <none> <none>
deploy-nginx-647f9649f5-w44ck 1/1 Running 0 2m41s 10.46.0.6 node-05 <none> <none>
最后我們?cè)L問http://nginx.cnlinux.club
,至此所有的都已完成。
后續(xù)會(huì)陸續(xù)更新所有的k8s相關(guān)文檔,如果你覺得我寫的不錯(cuò),希望大家多多關(guān)注點(diǎn)贊,如有問題可以在下面給我留言,非常感謝!
分享文章:Kubernetes部署(十二):helm部署harbor企業(yè)級(jí)鏡像倉庫
標(biāo)題路徑:http://chinadenli.net/article32/poojpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、、手機(jī)網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站排名、域名注冊(cè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)