Helm
致力於成爲k8s集羣的應用包管理工具,但願像linux 系統的RPM
DPKG
那樣成功;確實在k8s上部署複雜一點的應用很麻煩,須要管理不少yaml文件(configmap,controller,service,rbac,pv,pvc等等),而helm可以整齊管理這些文檔:版本控制,參數化安裝,方便的打包與分享等。 linux
爲了安全,在helm客戶端和tiller服務器間創建安全的SSL/TLS認證機制;tiller服務器和helm客戶端都是使用同一CA簽發的client cert
,而後互相識別對方身份。建議經過本項目提供的ansible role
安裝,符合官網上介紹的安全加固措施,在delpoy節點運行:
首先克隆ansible playbook:nginx
git clone https://github.com/donxan/ansible_helm.git
# 1.若是已安裝,須要從新安裝,使用 helm reset 清理 # 2.配置默認helm參數 vim /etc/ansible/roles/helm/vars/main.yml # 3.執行安裝 # ansible-playbook /etc/ansible/roles/helm/helm.yml
簡單介紹下/roles/helm/tasks/main.yml
中的步驟git
[root@master software]# wget -qO- https://storage.googleapis.com/kubernetes-helm/helm-v2.12.1-linux-amd64.tar.gz | tar -zx [root@master software]# ls harbor linux-amd64 traefik [root@master software]# mv linux-amd64/helm /etc/ansible/bin/
1-下載最新release的helm客戶端到/etc/ansible/bin目錄下,再由它自動推送到deploy的{{ bin_dir }}目錄下github
注意client,server的版本要一致,不然會報錯,使用helm安裝應用也會報錯 web
# helm version --tls Client: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"} Server: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"}
helm ls
helm version
helm install
等須要加--tls
參數helm search
helm fetch
helm home
等不須要加--tls
[root@master harbor-helm]# kubectl get po,svc -n kube-system -l app=helm NAME READY STATUS RESTARTS AGE pod/tiller-deploy-d658b9c47-fqrx7 1/1 Running 0 4s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/tiller-deploy ClusterIP 10.68.42.136 <none> 44134/TCP 4s
這裏使用了nfs pv,先到 NFS Server 上創建四個資料夾mkdir nfs{3..6}
,本次不須要配置pvc,後面會自動配置redis
for i in {3..6}; do cat <<EOF | kubectl apply -f - apiVersion: v1 kind: PersistentVolume metadata: name: pv00${i} spec: capacity: storage: 100Gi accessModes: - ReadWriteOnce #須要注意 persistentVolumeReclaimPolicy: Recycle nfs: path: /volume1/harbor/nfs${i} server: 192.168.2.4 EOF done
[root@master pv]# kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pv001 10Gi RWX Retain Bound default/myclaim 21h pv002 100Gi RWX Retain Bound default/nginx-svc-claim 20h pv003 100Gi RWO Recycle Available 12s pv004 100Gi RWO Recycle Available 12s pv005 100Gi RWO Recycle Available 12s pv006 100Gi RWO Recycle Available 11s
當Persistent Volume準備完成後,隆Harbor helm chart代碼:docker
git clone https://github.com/goharbor/harbor-helm cd harbor-helm git checkout 0.3.0 #目前最新的分支是0.3.0
更新依賴,使用 Helm 部署 Harborvalues.yaml
包含不少配置參數,根據須要修改。參考官方文檔json
helm dependency update elm install . --debug --name hub --set externalDomain=harbor.abcgogo.com --tls
使用kubectl
查看 Harbor 是否部署成功vim
[root@master harbor-helm]# kubectl get pod -o wide | grep harbor hub-harbor-adminserver-77dc5bb8c4-xchm7 1/1 Running 4 7h 172.20.4.95 192.168.2.12 <none> hub-harbor-chartmuseum-77895d6c6-wxh7q 1/1 Running 0 7h 172.20.2.101 192.168.2.11 <none> hub-harbor-clair-6575949b87-wrgs7 1/1 Running 4 7h 172.20.4.97 192.168.2.12 <none> hub-harbor-database-0 1/1 Running 0 6h 172.20.2.103 192.168.2.11 <none> hub-harbor-jobservice-7c5f74d9d-jrrxr 1/1 Running 2 7h 172.20.3.83 192.168.2.13 <none> hub-harbor-notary-server-75f64bfcd-7tlts 1/1 Running 0 7h 172.20.3.82 192.168.2.13 <none> hub-harbor-notary-signer-7fbf77648d-4485x 1/1 Running 0 7h 172.20.4.96 192.168.2.12 <none> hub-harbor-registry-674c7f487d-5xzqt 1/1 Running 0 7h 172.20.2.102 192.168.2.11 <none> hub-harbor-ui-759b87c94c-kg7gj 1/1 Running 1 6h 172.20.4.99 192.168.2.12 <none>
可使用kubectl get pod,svc,ingress -o wide | grep harbor<br/>
查看更多信息,因以前配置了traefik,因此這裏使用traefik ingree,這裏已經配置成功。
dns服務器上配置harbor.abcgogo.com的dns,也能夠修改本地hosts
接著可使用瀏覽器查看Harbor Web UI,默認登陸帳號密碼:admin/Harbor12345
api
確認Helm部署的Harbour沒問題後,能夠開始使用Harbor。如下將說明如何讓Docker Client如何存取私有的Registry以及一些基本操做。
首先,要讓Docker能存取私有的註冊表須要對Docker作一些小小的設定,而設定方式有如下兩種方式:
而兩種方法選擇其中一種設定便可。
由於咱們部署的Harbour是有自帶憑證(CA),因此須要再Docker Client加入憑證,這樣Docker Client纔有辦法存取到私有的註冊表。
首先,在Kubernetes Master使用如下指令取得憑證
pv006 100Gi RWO Recycle Bound default/redis-data-hub-redis-master-0 12h [root@master harbor-helm]# kubectl get secret/hub-harbor-ingress -o jsonpath="{.data.ca\.crt}" | base64 --decode -----BEGIN CERTIFICATE----- adfadsfaAwIBAgIRAJmXXxn40kWHcoOj6dfjtgIwDQYJKoZIhvcNAQELBQAw FDESMBAGA1UEAxMJaGFyYm9yLWNhMB4XDTE5MDExNTA4MzExMloXDTI5MDExMjA4 MzExMlowFDESMBAGA1UEAxMJaGFyYm9yLWNhMIIBIjANBgkqhkiG9w0BAQEFAAOC AQ8AMIIBCgKCAQEA34RNLkEvdHQDufGgZRJmL3Tki6IJyPnKQc0PdtIZvKYCSMut wyiOeS/VEk/GNtEMet1+Vf6EbclnH0kR6aHl4t11S/9C1kSwRwm48lTkeDKk79Q8 4p/z8GfFW25BTLLcDE9BjdE71Zl4vKX3Spf9iFUWmKiSDi682xXC66/CUjGlyts3 AZOXpGUdmgOGKWNGQ0EBWThVo1krytj/6qKLt7sB08+/KzUSMX+k9Dl5G6yN/7Lt rwmAPW3KqZY6ZqYvSb7Big/9xgCE2lO3C/rVOQIDAQABo0IwQDAOBgNVHQ8BAf8E BAMCAqQwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMA8GA1UdEwEB/wQF MAMBAf8wDQYJKoZIhvcNAQELBQADggEBAHoqJZDqAiMkcbO273n9GjWTXQgqBIkb mBltkXU1oWa6wDrF/ZrTU25RUftDZ1QPYGsXRGpz/9pODcGDVDPK+45QH2Fjtldj KOycOWIEdolFP6aDuqxiSaRrC6XjM9fyPSRSjS3kSHVQJ91c7PwD+9v1U6kwNkvh CsfwerqerwerwsdfMr8eLvjpKitaHQLHkgqOIDquxV8dNIMSzvfGJw77lzhJ3ere y+UgzIBpPLc8FpsuwjKmBnSDjOvj8OWGmJyTBM2KfDC1dk+ZXTsErpY= -----END CERTIFICATE-----
取得憑證後,在每一臺Docker Client加入如下憑證:
mkdir -p /etc/docker/certs.d/harbor.abcgogo.com/ cat <<EOF > /etc/docker/certs.d/harbor.abcgogo.com/ca.crt -----BEGIN CERTIFICATE----- MIIC9TCCAd2gAwIBAgIRAJmXXxn40kWHcoOj6dfjtgIwDQYJKoZIhvcNAQELBQAw FDESMBAGA1UEAxMJaGFyYm9yLWNhMB4XDTE5MDExNTA4MzExMloXDTI5MDExMjA4 MzExMlowFDESMBAGA1UEAxMJaGFyYm9yLWNhMIIBIjANBgkqhkiG9w0BAQEFAAOC AQ8AMIIBCgKCAQEA34RNLkEvdHQDufGgZRJmL3Tki6IJyPnKQc0PdtIZvKYCSMut wyiOeS/VEk/GNtEMet1+Vf6EbclnH0kR6aHl4t11S/9C1kSwRwm48lTkeDKk79Q8 4p/z8GfFW25BTLLcDE9BjdE71Zl4vKX3Spf9iFUWmKiSDi682xXC66/CUjGlyts3 AZOXpGUdmgOGKWNGQ0EBWThVo1krytj/6qKLt7sB08+/KzUSMX+k9Dl5G6yN/7Lt mBltkXU1oWa6wDrF/ZrTU25RUftDZ1QPYGsXRGpz/9pODcGDVDPK+45QH2Fjtldj KOycOWIEdolFP6aDuqxiSaRrC6XjM9fyPSRSjS3kSHVQJ91c7PwD+9v1U6kwNkvh CqEWg9ejsw0jNmxNwoJfQlz0Y+qz3fzhQxXnaZdDDXrvq9wKMr8eLvjpKitaHQLH DIcQ11JR7dU3qVmegv3YxEB5S1cxwvyGH12kgqOIDquxV8dNIMSzvfGJw77lzhJ3 y+UgzIBpPLc8FpsuwjKmBnSDjOvj8OWGmJyTBM2KfDC1dk+ZXTsErpY= -----END CERTIFICATE----- EOF
修改完成後,從新啓動docker.service:
systemctl daemon-reload systemctl restart docker.service
更快捷高效的方法,使用for循環同步ca:
for host in `seq 11 14`;do rsync -av /etc/docker/certs.d/harbor.abcgogo.com/ca.crt root@192.168.2.${host}:/etc/docker/certs.d/harbor.abcgogo.com/ ssh root@192.168.2.${host} "systemctl daemon-reload && systemctl restart docker.service" done
經過命令行登陸測試:
[root@master harbor-helm]# docker login harbor.abcgogo.com Username: admin Password: Login Succeeded
在kubernetes中使用harbor,爲了不輸入帳號密碼,須要建立secret
如下操做在master上執行:
1)建立secret
kubectl create secret docker-registry harbor-secret --docker-server=harbor.abcgogo.com --docker-username=admin --docker-password=Harbor123
建立完成後,能夠用如下命令查看:
# kubectl get secret
推送鏡像到harbor
[root@master harbor-helm]# docker tag tomcat harbor.abcgogo.com/aikerlinux/tomcat:latest [root@master harbor-helm]# docker push harbor.abcgogo.com/aikerlinux/tomcat:latest The push refers to a repository [harbor.abcgogo.com/aikerlinux/tomcat]
推送成功後,能夠經過web查看
從harbor獲取image
docker pull harbor.abcgogo.com/aikerlinux/tomcat:latest