GitLab Omnibus Helm Chartのアップグレード方法

GitLab Omnibus Helm Chartを構築して運用していると、アップグレード作業がきになります。
基本的にOmnibus Dockerコンテナと同様ですが、この記事で全体の流れと細かいコマンドについてまとめました。

![successfully-canadian-518136-unsplash.jpg](https://qiita-image-store.s3.amazonaws.com/0/260796/daf4eba1-9201-ae5c-147c-8294af43d4fb.jpeg)

Omnibus Helm Chartが既にkubernetesクラスタにデプロイされていることを前提とします。
よって、`kubectl`や`helm`のインストールと設定は省略します。

## kubectlを設定

対象クラスタに接続できるようしておきます。

```shell:
> kubectl get pods -n gitlab
NAME                                          READY     STATUS    RESTARTS   AGE
noraneco-gitlab-77c8d66f64-vg6vf              1/1       Running   0          5m
noraneco-gitlab-postgresql-7ff9865b45-5lmsb   1/1       Running   0          66d
noraneco-gitlab-redis-668fb8dc4f-nqxpx        1/1       Running   0          66d
noraneco-gitlab-runner-6b868d6f55-dwdg8       1/1       Running   6          16m
noraneco-gitlab-runner-6b868d6f55-wq24p       1/1       Running   6          16m
```

## Helmを設定

```shell:
> helm init
$HELM_HOME has been configured at /Users/jb/.helm.
Warning: Tiller is already installed in the cluster.
(Use --client-only to suppress this message, or --upgrade to upgrade Tiller to the current version.)
Happy Helming!
```

これでデプロイ済みのOmnibus Chartが見れるようになります。

```shell:
> helm list
NAME        REVISION    UPDATED                     STATUS      CHART                    NAMESPACE
noraneco    4           Fri Apr 13 15:11:55 2018    DEPLOYED    gitlab-omnibus-0.1.37    gitlab
```

GitLabのChartレポジトリを登録します。

```shell:
> helm repo add gitlab https://charts.gitlab.io
"gitlab" has been added to your repositories
```

## Chartをアップグレード

GitLab Omnibus Chartをアップグレードしたい対象バージョンを特定しておきます。以下のURLでイメージ名の一覧を参照してください。

> https://hub.docker.com/r/gitlab/gitlab-ee/tags/

いよいよ、アップグレードを実行します。

```shell:
> helm upgrade noraneco --set gitlab=ee,gitlabEEImage=gitlab/gitlab-ee:10.7.3-ee.0,baseDomain=mydomain.io,legoEmail=mymailaddress@gmail.com,provider=acs,redisDedicatedStorage=true,postgresDedicatedStorage=true gitlab/gitlab-omnibus
Release "noraneco" has been upgraded. Happy Helming!
LAST DEPLOYED: Sun May 13 13:50:38 2018
NAMESPACE: gitlab
STATUS: DEPLOYED

RESOURCES:
==> v1/ConfigMap
NAME                               DATA  AGE
noraneco-gitlab-runner             2     96d
noraneco-gitlab-config             9     96d
noraneco-gitlab-postgresql-initdb  1     96d
kube-lego                          2     96d
nginx                              7     96d
tcp-ports                          1     96d
==> v1beta1/DaemonSet
NAME   DESIRED  CURRENT  READY  UP-TO-DATE  AVAILABLE  NODE SELECTOR  AGE
nginx  1        1        1      1           1          <none>         96d
==> v1beta1/Deployment
NAME                        DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
noraneco-gitlab-runner      2        2        2           2          96d
noraneco-gitlab             1        1        1           0          96d
noraneco-gitlab-postgresql  1        1        1           1          96d
noraneco-gitlab-redis       1        1        1           1          96d
kube-lego                   1        1        1           1          96d
default-http-backend        1        1        1           1          96d
==> v1beta1/Ingress
NAME             HOSTS                                                                       ADDRESS     PORTS    AGE
noraneco-gitlab  gitlab.mydomain.io,registry.mydomain.io,mattermost.mydomain.io + 1 more...  10.240.0.5  80, 443  96d
==> v1/Pod(related)
NAME                                         READY  STATUS             RESTARTS  AGE
nginx-gdnmf                                  1/1    Running            0         96d
noraneco-gitlab-runner-6b868d6f55-dwdg8      1/1    Running            6         29d
noraneco-gitlab-runner-6b868d6f55-wq24p      1/1    Running            6         29d
noraneco-gitlab-6bbff796b6-z5k22             0/1    ContainerCreating  0         1s
noraneco-gitlab-77c8d66f64-vg6vf             1/1    Terminating        0         29d
noraneco-gitlab-postgresql-7ff9865b45-5lmsb  1/1    Running            0         96d
noraneco-gitlab-redis-668fb8dc4f-nqxpx       1/1    Running            0         96d
kube-lego-75cf85bd4b-6pqzx                   1/1    Running            14        96d
default-http-backend-59c9697d84-ws2qm        1/1    Running            0         96d
==> v1/Namespace
NAME           STATUS  AGE
kube-lego      Active  96d
nginx-ingress  Active  96d
==> v1/PersistentVolumeClaim
NAME                                STATUS  VOLUME                                    CAPACITY  ACCESS MODES  STORAGECLASS  AGE
noraneco-gitlab-config-storage      Bound   pvc-f0526378-0a32-11e8-ac66-0a58ac1f0a88  1Gi       RWO           default       96d
noraneco-gitlab-storage             Bound   pvc-f053cdce-0a32-11e8-ac66-0a58ac1f0a88  30Gi      RWO           default       96d
noraneco-gitlab-registry-storage    Bound   pvc-f052eb94-0a32-11e8-ac66-0a58ac1f0a88  30Gi      RWO           default       96d
noraneco-gitlab-postgresql-storage  Bound   pvc-a9b071fb-0a57-11e8-ac66-0a58ac1f0a88  30Gi      RWO           default       96d
noraneco-gitlab-redis-storage       Bound   pvc-a9b2d037-0a57-11e8-ac66-0a58ac1f0a88  5Gi       RWO           default       96d
==> v1/Service
NAME                        TYPE          CLUSTER-IP    EXTERNAL-IP   PORT(S)                                     AGE
noraneco-gitlab             ClusterIP     10.0.202.185  <none>        22/TCP,8065/TCP,8105/TCP,8005/TCP,9090/TCP  96d
noraneco-gitlab-postgresql  ClusterIP     10.0.222.76   <none>        5432/TCP                                    96d
noraneco-gitlab-redis       ClusterIP     10.0.133.214  <none>        6379/TCP                                    96d
default-http-backend        ClusterIP     10.0.110.19   <none>        80/TCP                                      96d
nginx                       LoadBalancer  10.0.162.57   13.89.187.36  80:32546/TCP,443:32401/TCP,22:32331/TCP     96d
==> v1/Secret
NAME                     TYPE    DATA  AGE
noraneco-gitlab-runner   Opaque  2     96d
noraneco-gitlab-secrets  Opaque  3     96d
NOTES:
  It may take several minutes for GitLab to reconfigure.
    You can watch the status by running `kubectl get deployment -w noraneco-gitlab --namespace gitlab
  You did not specify a baseIP so one will be assigned for you.
  It may take a few minutes for the LoadBalancer IP to be available.
  Watch the status with: 'kubectl get svc -w --namespace nginx-ingress nginx', then:
  export SERVICE_IP=$(kubectl get svc --namespace nginx-ingress nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
  Then make sure to configure DNS with something like:
    *.mydomain.io   300 IN A $SERVICE_IP
```

これで、イメージがダウンロードされコンテナが生成されます。GitLabのRailsコンテナが立ち上がるとマイグレーションが実行されます。

```
> kubectl get pods -n gitlab
NAME                                          READY     STATUS              RESTARTS   AGE
noraneco-gitlab-6bbff796b6-z5k22              0/1       ContainerCreating   0          27s
noraneco-gitlab-postgresql-7ff9865b45-5lmsb   1/1       Running             0          96d
noraneco-gitlab-redis-668fb8dc4f-nqxpx        1/1       Running             0          96d
noraneco-gitlab-runner-6b868d6f55-dwdg8       1/1       Running             6          29d
noraneco-gitlab-runner-6b868d6f55-wq24p       1/1       Running             6          29d
> kubectl get pods -n gitlab
NAME                                          READY     STATUS    RESTARTS   AGE
noraneco-gitlab-6bbff796b6-z5k22              0/1       Running   0          2m
noraneco-gitlab-postgresql-7ff9865b45-5lmsb   1/1       Running   0          96d
noraneco-gitlab-redis-668fb8dc4f-nqxpx        1/1       Running   0          96d
noraneco-gitlab-runner-6b868d6f55-dwdg8       1/1       Running   6          29d
noraneco-gitlab-runner-6b868d6f55-wq24p       1/1       Running   6          29d
```

起動やマイグレーションのログを確認した場合、`kubectl logs noraneco-gitlab-6bbff796b6-z5k22 -n gitlab -f`が役に立ちます。

数分で終わります、5分もかかりませんがダウンタイムが発生しますのでご注意ください。
また、アップグレードを実施する前にフルバックアップを取得するようにしておきましょう。