4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GitLab Runner with Kubernetes の構築

Last updated at Posted at 2019-04-15

GitLab Runner with Kubernetes の構築

(2019/04時点)

環境

  • GitLab
    • OS: CentOS 6.9
    • GitLab: v11.9.8
  • Kubernetes
    • OS: CentOS 7.4
    • Kubernetes: v1.12
    • Docker: docker-ce-18.06.1.ce

手順

###1. Kubernetes クラスタの登録
a. プロジェクト > Operations > Kubernetesに移動し、[Add Kubernetes cluster] をクリック
b. [Add existing cluster] に各パラメータを入力

  • API URL: https://<kubernetes url>
  • CA Certificate 取得
sh
# kubectl get secrets
NAME                  TYPE                                  DATA   AGE
default-token-xxxxx   kubernetes.io/service-account-token   3      76d
# kubectl get secret <default-token-xxxxx> -o jsonpath="{['data']['ca\.crt']}" | base64 --decode
  • Token 取得
gitlab-admin.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: gitlab-admin
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: gitlab-admin
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: gitlab-admin
    namespace: kube-system
sh
# kubectl apply -f gitlab-admin.yaml
# kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep gitlab-admin | awk '{print $1}')

c. 「Add Kubernetes cluster」をクリック

2. Helm Tiller のインストール

  • Applications > Helm Tiller の [Install] をクリック

3. GitLab Runner のインストール

  • Applications > GitLab Runner の [Install] をクリック

    ※ GitLab Runner のインストールが失敗する。
    Install-RunnerのPodのログを見てみるとTillerに接続ができていないように見受けられる。

    ※ Tillerは、TLSオプション付きでデプロイされているが、[helm init] および [helm version] ではTLSオプションが付いていないことが原因だと思われる。

    ※ また、下記ログを見てみるとTillerの証明書と [helm install] で使用する証明書が異なると見受けられる。

    ※ 手順4の方法で、上記エラーを回避する
sh
# kubectl get logs install-runner -n gitlab-managed-apps
Retrying (30)...
+ helm repo add runner https://charts.gitlab.io
"runner" has been added to your repositories
+ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "runner" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈ 
+ helm install runner/gitlab-runner --name runner --tls --tls-ca-cert /data/helm/runner/config/ca.pem --tls-cert /data/helm/runner/config/cert.pem --tls-key /data/helm/runner/config/key.pem --version 0.1.43 --set 'rbac.create=true,rbac.enabled=true' --namespace gitlab-managed-apps -f /data/helm/runner/config/values.yaml
Error: remote error: tls: bad certificate

4. Tiller接続エラーの回避

下記ソースコードを書き換えることにより、TillerをTLSオプションなしでデプロイする。

init_command.rb
        def init_command_flags
          # tls_flags + optional_service_account_flag
          optional_service_account_flag
        end
install_command.rb
        def install_command
          command = ['helm', 'upgrade', name, chart] +
            install_flag +
            reset_values_flag +
            # optional_tls_flags +
            optional_version_flag +
            rbac_create_flag +
            namespace_flag +
            value_flag

          command.shelljoin
        end
  • [install-runner] Podの確認
sh
# kubectl get pods --namespace=gitlab-managed-apps
NAME                                    READY   STATUS    RESTARTS   AGE
runner-gitlab-runner-6f56c75784-xxxxx   1/1     Running   0          2d19h
tiller-deploy-5c76f66549-xxxxx          1/1     Running   0          2d19h
4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?