GitLab DevOps:Kubernetes 整合的 Applications 裝不起來怎麼辦?

我們的平民化旅遊黑卡秘書服務 LiMaGo,系統已經開發了兩年,有一定的複雜度,一直以來在維護上其實都有一定困難。此外,不知道是好消息還是壞消息,由於我們開始拓展日本等其他國家的業務,也加強了行銷通路,所以業務數字持續增加,導致各種功能和後勤機制也持續在擴張。還有,許多隱藏尚未公開的新計畫,整個系統複雜度不斷的再增加,慢慢的一切都開始混亂。

所以,為了重整系統,以及重建開發團隊的各種資源和管理流程,開始試圖引入了 Kubernetes 和 GitLab,並試著將 DevOps 流程給搭建起來。畢竟,自己的另外一家公司,是微服務和容器化的解決方案供應商,自己手上的東西要是沒有導入,也太講不過去。還好轉換的問題不太大,LiMaGo 的系統從第一天設計,就是採用微服務架構(Micro-service Architecture),甚至當時還設計了一套框架「Engined」,可以在 Node.js 上更容易開發微服務架構,只要專心在容器化和 DevOps 的工作上即可。

於是動手把 Kubernetes 架好,也安裝好 GitLab CE。下一步,就是把 Kubernetes 的設定加入 GitLab,讓 GitLab 可以把 GitLab Runner 和 DevOps 相關機制跟手上的 Kubernetes 整合起來。

糟糕!Applictions 裝不起來!

原本一切很順利,但在 GitLab 設定頁裡面的最後一個步驟「在 Kubernetes 上安裝 Applications」遭遇到莫名失敗,一開始是 Ingress 裝不起來,後來發現 Prometheus 也裝不起來,如下圖:

透過 kubectl 直接去 Kubernetes 裡面挖 logs ,得到了錯誤訊息:

$ kubectl logs install-prometheus -n gitlab-managed-apps -f
+ helm init --upgrade
Creating /root/.helm
Creating /root/.helm/repository
Creating /root/.helm/repository/cache
Creating /root/.helm/repository/local
Creating /root/.helm/plugins
Creating /root/.helm/starters
Creating /root/.helm/cache/archive
Creating /root/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /root/.helm.

Tiller (the Helm server-side component) has been upgraded to the current version.
+ seq 1 30
+ helm version --tls --tls-ca-cert /data/helm/prometheus/config/ca.pem --tls-cert /data/helm/prometheus/config/cert.pem --tls-key /data/helm/prometheus/config/key.pem
Client: &version.Version{SemVer:"v2.14.3", GitCommit:"0e7f3b6637f7af8fcfddb3d2941fcc7cbebb0085", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.14.3", GitCommit:"0e7f3b6637f7af8fcfddb3d2941fcc7cbebb0085", GitTreeState:"clean"}
+ break
+ helm upgrade prometheus stable/prometheus --install --reset-values --tls --tls-ca-cert /data/helm/prometheus/config/ca.pem --tls-cert /data/helm/prometheus/config/cert.pem --tls-key /data/helm/prometheus/config/key.pem --version 6.7.3 --set 'rbac.create=true,rbac.enabled=true' --namespace gitlab-managed-apps -f /data/helm/prometheus/config/values.yaml
E0902 10:50:18.229952      28 portforward.go:372] error copying from remote stream to local connection: readfrom tcp4 127.0.0.1:42953->127.0.0.1:44820: write tcp4 127.0.0.1:42953->127.0.0.1:44820: write: broken pipe
Error: UPGRADE FAILED: "prometheus" has no deployed releases
UPGRADE FAILED
Error: "prometheus" has no deployed releases

雖然乍看起來是連線的問題,但我確定網路應該沒什麼問題,而且我手動操作 helm 都是正常的。而且在 GitLab 頁面上,不管我怎麼重試,問題依舊。

Workaround: 直接連線到 Tiller 解決

上網試圖找了一些解決方法,卻都找不太到(大概是我關鍵字下的不對),最後決定試圖去直接操作 gitlab-managed-apps 底下的 Tiller 看看。於是找到了一則 GitLab 的 Issue,討論怎麼連線到 GitLab 所自動安裝出來的 Tiller:

https://gitlab.com/gitlab-org/gitlab-ce/issues/56591#workaround-for-now

文中所說的連線方法如下:

export TILLER_NAMESPACE="gitlab-managed-apps"

# 取得 gitlab-managed-apps namespace 底下的 Tiller 憑證和金鑰
kubectl get secrets/tiller-secret -n "$TILLER_NAMESPACE" -o "jsonpath={.data['ca\.crt']}" | base64 --decode > tiller-ca.crt
kubectl get secrets/tiller-secret -n "$TILLER_NAMESPACE" -o "jsonpath={.data['tls\.crt']}" | base64 --decode > tiller.crt
kubectl get secrets/tiller-secret -n "$TILLER_NAMESPACE" -o "jsonpath={.data['tls\.key']}" | base64 --decode > tiller.key

# 連線到 Tiller 並取得已安裝的套件清單
helm list --tiller-connection-timeout 30 --tls --tls-ca-cert tiller-ca.crt --tls-cert tiller.crt --tls-key tiller.key --all --tiller-namespace gitlab-managed-apps

幸運的是,用憑證和金鑰可以順利連線並取出 helm 的資訊,然後看到 ingress 和 prometheus 都出了問題:

$ helm list --tiller-connection-timeout 30 --tls --tls-ca-cert tiller-ca.crt --tls-cert tiller.crt --tls-key tiller.key --all --tiller-namespace gitlab-managed-apps
NAME        REVISION    UPDATED                     STATUS      CHART               APP VERSION NAMESPACE
ingress     1           Mon Sep  2 16:51:47 2019    FAILED      nginx-ingress-1.1.2 0.21.0      gitlab-managed-apps
prometheus  1           Mon Sep  2 17:42:41 2019    FAILED      prometheus-6.7.3    2.2.1       gitlab-managed-apps
runner      1           Mon Sep  2 17:33:55 2019    DEPLOYED    gitlab-runner-0.7.0 12.1.0      gitlab-managed-apps

就在我打算手動砍掉失敗的項目,然後重新安裝時,突然發現其實有人在討論類似的問題,雖然碰到的問題跟我不一樣:

https://gitlab.com/gitlab-org/gitlab-ce/issues/65326#note_198244170

下面剛好有篇原發問者自己的回文,和我的思路一樣,說他砍掉後重新安裝就解決了問題:

helm delete --purge prometheus --tls --tls-ca-cert tiller-ca.crt --tls-cert tiller.crt --tls-key tiller.key --tiller-namespace gitlab-managed-apps

很好!我也搞定了!

留言

  1. That is a very good tip particularly to those new to
    the blogosphere. Brief but very accurate information… Thanks for sharing
    this one. A must read post! 경마사이트

    回覆刪除

張貼留言

這個網誌中的熱門文章

有趣的邏輯問題:是誰在說謊

Web 技術中的 Session 是什麼?

淺談 USB 通訊架構之定義(二)

淺談 USB 通訊架構之定義(一)

Reverse SSH Tunnel 反向打洞實錄