正式なドキュメントは英語版であり、この日本語訳はAI支援翻訳により作成された参考用のものです。日本語訳の一部の内容は人間によるレビューがまだ行われていないため、翻訳のタイミングにより英語版との間に差異が生じることがあります。最新かつ正確な情報については、英語版をご参照ください。

GitLab Runner Operatorをインストールする

Red Hat OpenShiftへのインストール

  • プラン: Free、Premium、Ultimate
  • 提供形態: GitLab.com、GitLab Self-Managed、GitLab Dedicated

OpenShiftのウェブコンソールで、OperatorHubの安定チャンネルから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をインストールする必要があります。

  1. 管理者権限を持つユーザーとしてOpenShift UIを開き、サインインします。

  2. 左側のペインで、Operators(Operators)、OperatorHub(OperatorHub) の順に選択します。

  3. メインペインのAll Items(All Items)の下で、キーワードGitLab Runnerを検索します。

    GitLab Operator

  4. インストールするには、GitLab Runner Operatorを選択します。

  5. GitLab Runner Operatorの概要ページで、インストールを選択します。

  6. Install Operatorページで、以下を行います:

    1. Update Channel(Update Channel) で、stable(stable)を選択します。
    2. Installed Namespace(Installed Namespace)で、目的のネームスペースを選択し、インストールを選択します。

    GitLab Operator Install Page

Installed Operatorsページで、GitLab Operatorの準備ができると、ステータスが完了に変わります。

GitLab Operator Install Status

Kubernetesにインストールする

  • プラン: Free、Premium、Ultimate
  • 提供形態: GitLab.com、GitLab Self-Managed、GitLab Dedicated

OperatorHub.ioの安定チャンネルから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の手順に従ってください。

  1. 前提条件をインストールします。
  2. 右上にあるインストールを選択し、指示に従ってolmとOperatorをインストールします。

GitLab Runnerをインストールする

  1. Runner認証トークンを取得します。次のいずれかの方法があります:

  2. 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
  3. 実行して、クラスターにsecretシークレットを作成します:

    kubectl apply -f gitlab-runner-secret.yml
  4. カスタムリソース定義(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
  5. コマンドを実行して、CRDファイルを適用します:

    kubectl apply -f gitlab-runner.yml
  6. GitLab Runnerがインストールされていることを確認するには、次を実行します:

    kubectl get runner
    NAME             AGE
    gitlab-runner    5m
  7. Runnerポッドも表示されるはずです:

    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.yaml

1分以内に、新しいRunnerがOpenShiftクラスターのOperatorHubセクションに表示されるはずです。

オフライン環境のKubernetesクラスターにGitLab Runner Operatorをインストールする

前提要件:

  • インストールプロセスに必要なイメージにアクセスできること。

インストール中にコンテナイメージをプルするには、GitLab Runner Operatorは、外部ネットワーキング上のパブリックインターネットへの接続を必要とします。オフライン環境にKubernetesクラスターがインストールされている場合は、ローカルイメージレジストリまたはパッケージリポジトリを使用して、インストール中にイメージまたはパッケージをプルできます。

ローカルリポジトリは、次のイメージを提供する必要があります:

画像デフォルト値
GitLab Runner Operator(GitLab Runner Operator)イメージregistry.gitlab.com/gitlab-org/gl-openshift/gitlab-runner-operator/gitlab-runner-operator:vGITLAB_RUNNER_OPERATOR_VERSION
GitLab Runner(GitLab Runner)イメージとGitLab Runner Helper(GitLab Runner Helper)イメージこれらのイメージはRunnerカスタムリソースのインストール時にGitLab Runner UBIイメージレジストリからダウンロードされ、使用されます。使用されるバージョンは要件によって異なります。
RBAC Proxy(RBAC Proxy)イメージregistry.gitlab.com/gitlab-org/gl-openshift/gitlab-runner-operator/openshift4/ose-kube-rbac-proxy:v4.13.0
  1. ダウンロードしたソフトウェアパッケージとコンテナイメージをホストするために、切断されたネットワーク環境にローカルリポジトリまたはレジストリを設定します。次を使用できます:

    • コンテナイメージ用のDockerレジストリ。
    • Kubernetesバイナリと依存関係用のローカルパッケージレジストリ。
  2. 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"
  3. operator.k8s.yamlファイルで、次のURLを更新します:

    • GitLab Runner Operator image
    • RBAC Proxy image
  4. 更新されたバージョンのoperator.k8s.yamlファイルをインストールします:

    kubectl apply -f PATH_TO_UPDATED_OPERATOR_K8S_YAML
    GITLAB_RUNNER_OPERATOR_VERSION = 1.23.2+

Operatorのアンインストール

Red Hat OpenShiftでのアンインストール

  1. Runner CRDの削除:

    kubectl delete -f gitlab-runner.yml
  2. secretを削除:

    kubectl delete -f gitlab-runner-secret.yml
  3. Red HatドキュメントのWebコンソールを使用したクラスターからのOperatorの削除の手順に従ってください。

Kubernetesからアンインストール

  1. Runner CRDの削除:

    kubectl delete -f gitlab-runner.yml
  2. secretを削除:

    kubectl delete -f gitlab-runner-secret.yml
  3. Operatorのサブスクリプションを削除します:

    kubectl delete subscription my-gitlab-runner-operator -n operators
  4. インストールされているCSVのバージョンを確認します:

    kubectl get clusterserviceversion -n operators
    NAME                            DISPLAY         VERSION   REPLACES   PHASE
    gitlab-runner-operator.v1.7.0   GitLab Runner   1.7.0                Succeeded
  5. CSVを削除します:

    kubectl delete clusterserviceversion gitlab-runner-operator.v1.7.0 -n operators

設定

OpenShiftでGitLab Runnerを設定するには、OpenShiftでのGitLab Runnerの設定ページを参照してください。

モニタリング

GitLab Runner Operatorデプロイのモニタリングとメトリクス収集を有効にするには、GitLab Runner Operatorを監視しますを参照してください。