GitLab Runner Operatorをインストールする
Red Hat OpenShiftにインストールする
- プラン: Free、Premium、Ultimate
- 提供形態: GitLab.com、GitLab Self-Managed、GitLab Dedicated
OpenShiftのウェブコンソールでOperatorHubのstableチャネルからGitLab Runner Operatorを使用して、Red Hat OpenShift v4以降にGitLab Runnerをインストールします。インストールが完了すると、新しくデプロイされたGitLab Runnerインスタンスを使用して、GitLab CI/CDジョブを実行できます。各CI/CDジョブは、個別のポッドで実行されます。
前提条件
- 管理者権限を持つOpenShift 4.xクラスター
- GitLab Runner登録トークン
OpenShift Operatorをインストールする
まず、OpenShift Operatorをインストールする必要があります。
OpenShift UIを開き、管理者権限を持つユーザーとしてサインインします。
左側のペインで、Operators、OperatorHubの順に選択します。
メインペインのAll Itemsの下で、キーワード
GitLab Runnerを検索します。インストールするには、GitLab Runner Operatorを選択します。
GitLab Runner Operatorの概要ページで、Installを選択します。
Install Operatorページで、以下を実行します:
- Update Channelで、stableを選択します。
- Installed Namespaceで、目的のネームスペースを選択し、インストールを選択します。
Installed Operatorsページで、GitLab Operatorの準備ができると、ステータスがSucceededに変わります。
Kubernetesにインストールする
- プラン: Free、Premium、Ultimate
- 提供形態: GitLab.com、GitLab Self-Managed、GitLab Dedicated
OperatorHub.ioのstableチャネルからGitLab Runner Operatorを使用して、Kubernetes v1.21以降にGitLab Runnerをインストールします。インストールが完了すると、新しくデプロイされたGitLab Runnerインスタンスを使用して、GitLab CI/CDジョブを実行できます。各CI/CDジョブは、個別のポッドで実行されます。
前提条件
- Kubernetes v1.21以降
- Cert manager v1.7.1
Kubernetes Operatorをインストールする
OperatorHub.ioの手順に従ってください。
- 前提条件をインストールします。
- 右上にあるインストールを選択し、指示に従って
olmとOperatorをインストールします。
GitLab Runnerをインストールする
Runner認証トークンを取得します。次のいずれかの方法があります。
GitLab Runnerトークンを使用して、シークレットファイルを作成します:
cat > gitlab-runner-secret.yml << EOF apiVersion: v1 kind: Secret metadata: name: gitlab-runner-secret type: Opaque # Only one of the following fields can be set. The Operator fails to register the runner if both are provided. # NOTE: runner-registration-token is deprecated and will be removed in GitLab 18.0. You should use runner-token instead. stringData: runner-token: REPLACE_ME # your project runner token # runner-registration-token: "" # your project runner secret EOF以下を実行して、クラスターに
secretを作成します:kubectl apply -f gitlab-runner-secret.ymlカスタムリソース定義(CRD)ファイルを作成し、次の設定を含めます。
cat > gitlab-runner.yml << EOF apiVersion: apps.gitlab.com/v1beta2 kind: Runner metadata: name: gitlab-runner spec: gitlabUrl: https://gitlab.example.com buildImage: alpine token: gitlab-runner-secret EOF次に、コマンドを実行して
CRDファイルを適用します:kubectl apply -f gitlab-runner.yml以下を実行して、GitLab Runnerがインストールされていることを確認します:
kubectl get runner NAME AGE gitlab-runner 5mRunnerポッドも表示されるはずです:
kubectl get pods NAME READY STATUS RESTARTS AGE gitlab-runner-bf9894bdb-wplxn 1/1 Running 0 5m
OpenShift用の他のバージョンのGitLab Runner Operatorをインストールする
Red Hat OperatorHubで使用可能なGitLab Runner Operatorのバージョンを使用しない場合は、別のバージョンをインストールできます。
公式に利用可能なOperatorのバージョンを確認するには、gitlab-runner-operatorリポジトリのタグを表示します。Operatorが実行しているGitLab Runnerのバージョンを確認するには、目的のコミットまたはタグのAPP_VERSIONファイルの内容(たとえば、https://gitlab.com/gitlab-org/gl-openshift/gitlab-runner-operator/-/blob/1-17-stable/APP_VERSION)を表示します。
特定のバージョンをインストールするには、このcatalogsource.yamlファイルを作成し、<VERSION>をタグまたは特定のコミットに置き換えます:
特定のコミットのイメージを使用する場合、タグの形式はv0.0.1-<COMMIT>です。例: registry.gitlab.com/gitlab-org/gl-openshift/gitlab-runner-operator/gitlab-runner-operator-catalog-source:v0.0.1-f5a798af。
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: gitlab-runner-catalog
namespace: openshift-marketplace
spec:
sourceType: grpc
image: registry.gitlab.com/gitlab-org/gl-openshift/gitlab-runner-operator/gitlab-runner-operator-catalog-source:<VERSION>
displayName: GitLab Runner Operators
publisher: GitLab Community以下を使用してCatalogSourceを作成します:
oc apply -f catalogsource.yaml1分以内に、新しいRunnerがOpenShiftクラスターのOperatorHubセクションに表示されるはずです。
オフライン環境のKubernetesクラスターにGitLab Runner Operatorをインストールする
前提条件:
- インストールプロセスに必要なイメージにアクセスできます。
インストール中にコンテナイメージをプルするために、GitLab Runner Operatorには、外部ネットワーク上のパブリックインターネットへの接続が必要です。オフライン環境にKubernetesクラスターがインストールされている場合は、ローカルイメージレジストリまたはパッケージレジストリを使用して、インストール中にイメージまたはパッケージをプルします。
ローカルリポジトリは、次のイメージを提供する必要があります:
| 画像 | デフォルト値 |
|---|---|
| GitLab Runner Operatorイメージ | registry.gitlab.com/gitlab-org/gl-openshift/gitlab-runner-operator/gitlab-runner-operator:vGITLAB_RUNNER_OPERATOR_VERSION |
| GitLab RunnerとGitLab Runner Helperのイメージ | これらのイメージは、GitLab Runner UBIイメージレジストリからダウンロードされ、Runnerカスタムリソースのインストール時に使用されます。使用するバージョンは、要件によって異なります。 |
| RBAC Proxyイメージ | registry.gitlab.com/gitlab-org/gl-openshift/gitlab-runner-operator/openshift4/ose-kube-rbac-proxy:v4.13.0 |
ダウンロードしたソフトウェアパッケージとコンテナイメージをホストするために、切断されたネットワーク環境でローカルリポジトリまたはレジストリをセットアップします。使用できるモデルは次のとおりです:
- コンテナイメージ用のDockerレジストリ。
- Kubernetesバイナリと依存関係のためのローカルパッケージレジストリ。
GitLab Runner Operator v1.23.2以降の場合は、
operator.k8s.yamlファイルの最新バージョンをダウンロードします:curl -O "https://gitlab.com/gitlab-org/gl-openshift/gitlab-runner- operator/-/releases/vGITLAB_RUNNER_OPERATOR_VERSION/downloads/operator.k8s.yaml"operator.k8s.yamlファイルで、次のURLを更新します:GitLab Runner Operator imageRBAC Proxy image
更新されたバージョンの
operator.k8s.yamlファイルをインストールします:kubectl apply -f PATH_TO_UPDATED_OPERATOR_K8S_YAML GITLAB_RUNNER_OPERATOR_VERSION = 1.23.2+
Operatorをアンインストール
Red Hat OpenShiftでアンインストールする
Runner
CRDを削除します:kubectl delete -f gitlab-runner.ymlsecretを削除します:kubectl delete -f gitlab-runner-secret.ymlWebコンソールを使用してクラスターからOperatorを削除するについては、Red Hatドキュメントの手順に従ってください。
Kubernetesでアンインストールする
Runner
CRDを削除します:kubectl delete -f gitlab-runner.ymlsecretを削除します:kubectl delete -f gitlab-runner-secret.ymlOperatorサブスクリプションを削除します:
kubectl delete subscription my-gitlab-runner-operator -n operatorsインストールされている
CSVのバージョンを確認します:kubectl get clusterserviceversion -n operators NAME DISPLAY VERSION REPLACES PHASE gitlab-runner-operator.v1.7.0 GitLab Runner 1.7.0 SucceededCSVを削除します:kubectl delete clusterserviceversion gitlab-runner-operator.v1.7.0 -n operators
設定
OpenShiftでGitLab Runnerを設定するには、OpenShiftでのGitLab Runnerの設定ページを参照してください。
モニタリング
GitLab Runner Operatorデプロイメントのモニタリングとメトリクス収集を有効にするには、GitLab Runnerのモニタリングを参照してください。


