メインコンテンツにスキップ

Helm を使用して Kubernetes 上で Casdoor を実行する

このガイドでは、公式の Helm チャートを使用して Kubernetes クラスターに Casdoor をインストールし、クラスターの外部からアクセスできるように公開する方法と、リリースのアップグレードや削除について説明します。複数のインスタンスを実行する場合や、組織およびアプリケーションを Kubernetes リソースとして宣言する場合は、Kubernetes オペレーターを参照してください。


学習目標​

  • Casdoor Helm チャートをインストールできます。
  • データベース接続を含むチャートの値を上書きできます。
  • Ingress または Gateway API を使用して Casdoor を公開できます。
  • values ファイルで組織、アプリケーション、ユーザーを管理できます。
  • リリースをアップグレードおよびアンインストールできます。

必要なもの​

  • Kubernetes クラスター(バージョン 1.19 以降)
  • Helm 3.8 以降
  • Gateway API オプションの場合:クラスター内の Gateway API CRD と Gateway コントローラー

自分で運用したくない場合

Casdoor Cloud gives you a dedicated Casdoor instance that we host and keep upgraded for you, from $9/month with no per-user fees. New accounts get $4 in free credit to try it.

チャートのインストール​

このチャートは GitHub Container Registry に OCI アーティファクトとして公開されています。Artifact Hub に登録されており、そのソースは Casdoor リポジトリにあります。

  1. チャートをインストールします。<version> を Artifact Hub のチャートバージョンに置き換えてください。

    helm install casdoor oci://ghcr.io/casdoor/helm-charts/casdoor --version <version>

    値を上書きするには、独自の values ファイルを渡します:

    helm install casdoor oci://ghcr.io/casdoor/helm-charts/casdoor      --version <version>      -f my-values.yaml
  2. クラスター内の casdoor サービスの URL で Casdoor を開きます。デフォルトの値では、サービスはポート 8000 の ClusterIP タイプであるため、公開するまでクラスター内からのみ到達可能です。

  3. 初回訪問時、Casdoor は Welcome to Casdoor ページを開きます。admin のパスワードを設定し、Set Password をクリックします。管理者コンソールへのサインインを参照してください。

    代わりに、初回起動前にパスワードを設定するには、Secret から読み取ってください:

    kubectl create secret generic casdoor-admin --from-literal=initAdminPassword='<admin-password>'
    initAdminPassword:
    existingSecret: casdoor-admin

    initAdminPassword.existingSecretKey は Secret 内の別のキーを選択します。ローカルテストでは --set initAdminPassword.value=<admin-password> も有効ですが、パスワードが values ファイルと Helm リリースに含まれることになります。この設定は、Casdoor が新しいデータベースを作成する場合にのみ適用されます。

デプロイメントのカスタマイズ​

values.yaml の値を、独自の values ファイルで上書きします。主な値は以下の通りです:

パラメーター説明デフォルト
replicaCountCasdoorアプリケーションを実行するレプリカの数。1
image.repositoryCasdoor Dockerイメージのリポジトリ。casbin
image.nameCasdoor Dockerイメージの名前。casdoor
image.pullPolicyCasdoor Dockerイメージのプルポリシー。IfNotPresent
image.tagCasdoor Dockerイメージのタグ。""
configCasdoorアプリケーションの設定。See values.yaml
initAdminPassword.value新しいデータベース用の built-in/admin のパスワード; existingSecret の方が安全です。""
initAdminPassword.existingSecret初期パスワードを保持する既存の Secret。""
initAdminPassword.existingSecretKeyexistingSecret 内の初期パスワードのキー。initAdminPassword
database.driverDatabase driver to use (mysql, postgres, cockroachdb, sqlite).sqlite
database.userデータベースのユーザー名。""
database.passwordデータベースのパスワード。""
database.hostデータベースのホスト。""
database.portデータベースのポート。""
database.databaseNameCasdoorが使用するデータベースの名前。casdoor
database.sslModeデータベース接続のSSLモード。disable
service.typeType of Kubernetes service (ClusterIP, NodePort, LoadBalancer).ClusterIP
service.portCasdoorサービスのポート番号。8000
service.annotationsAnnotations for the Kubernetes Service, for example the annotations of a cloud load balancer when service.type is LoadBalancer.{}
ingress.enabledCasdoorのIngressを有効にするかどうか。false
ingress.annotationsIngressリソースのアノテーション。{}
ingress.hostsIngressリソースのホスト名。[]
resourcesCasdoorコンテナのリソースリクエストとリミット。{}
autoscaling.enabledCasdoorのHorizontal Pod Autoscalerを有効にするかどうか。false
autoscaling.minReplicasMinimum number of replicas for HPA.1
autoscaling.maxReplicasMaximum number of replicas for HPA.100
autoscaling.targetCPUUtilizationPercentageTarget CPU utilization percentage for HPA.80
nodeSelectorポッド割り当てのためのノードラベル。{}
tolerationsポッド割り当てのためのトレランスラベル。[]
affinityポッド割り当てのためのアフィニティ設定。{}
extraContainersEnabled追加のサイドカーコンテナを有効にするかどうか。false
extraContainers追加のサイドカーコンテナ。""
extraVolumeMountsCasdoorコンテナの追加のボリュームマウント。[]
extraVolumesCasdoorコンテナの追加のボリューム。[]
envFromSecretEnvironment variables from individual Secret keys.[]
envFromConfigmapEnvironment variables from individual ConfigMap keys.[]
envFromEnvironment variables from entire Secrets or ConfigMaps.[]

Casdoor の公開​

Ingress または Gateway API を選択します。

Ingress を使用して Casdoor を公開する​

values ファイルで Ingress を有効化します:

ingress:
enabled: true
className: nginx
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
hosts:
- host: casdoor.example.com
paths:
- path: /
pathType: Prefix
tls:
- secretName: casdoor-tls
hosts:
- casdoor.example.com

Gateway API を使用して Casdoor を公開する​

Kubernetes Gateway API は Ingress の後継です。Istio、Envoy Gateway、Cilium、Kong、NGINX Gateway Fabric などのコントローラーがこれをサポートしています。

このオプションを有効化する前に、Gateway API CRD をインストールし、互換性のある Gateway コントローラーがクラスター内で実行されていることを確認してください:

kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.2.0/standard-install.yaml

その後、以下のいずれかの構成を使用します。

既存の Gateway にアタッチする​

クラスターに既に Gateway がある場合、HTTPRoute をそれに向けます:

gatewayApi:
enabled: true
parentRefs:
- name: my-gateway
namespace: gateway-system
sectionName: https
hostnames:
- casdoor.example.com

Gateway の作成​

チャートが HTTPRoute とともに Gateway を作成するようにします。この例では Istio を使用します:

gatewayApi:
enabled: true
createGateway: true
hostnames:
- casdoor.example.com
gateway:
gatewayClassName: istio
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: Same

HTTP を HTTPS にリダイレクトする Gateway の作成​

Gateway で TLS を終端し、HTTP リクエストを HTTPS へリダイレクトします:

gatewayApi:
enabled: true
createGateway: true
hostnames:
- casdoor.example.com
gateway:
gatewayClassName: istio
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: Same
- name: https
protocol: HTTPS
port: 443
tls:
certificateRefs:
- name: casdoor-tls
kind: Secret
allowedRoutes:
namespaces:
from: Same
httpsRedirect:
enabled: true

Gateway API の値​

パラメータ説明Default
gatewayApi.enabledEnable HTTPRoute creationfalse
gatewayApi.createGatewayAlso create a Gateway resourcefalse
gatewayApi.annotationsAnnotations for the HTTPRoute{}
gatewayApi.labelsExtra labels for the HTTPRoute{}
gatewayApi.parentRefsParent Gateway references[]
gatewayApi.hostnamesHostnames to match (Host header)[]
gatewayApi.rulesRouting rules (matches, filters, backendRefs)PathPrefix /
gatewayApi.gateway.nameGateway name (defaults to chart fullname)""
gatewayApi.gateway.gatewayClassNameGatewayClass name (required when createGateway=true)""
gatewayApi.gateway.listenersGateway listenersHTTP:80
gatewayApi.httpsRedirect.enabledEnable HTTP→HTTPS redirect HTTPRoutefalse
gatewayApi.httpsRedirect.statusCodeRedirect response code301
gatewayApi.httpsRedirect.hostnamesHostnames for redirect route[]
gatewayApi.httpsRedirect.parentRefsOverride parentRefs for redirect route[]

values ファイルでの Casdoor オブジェクトの管理​

組織、アプリケーション、ユーザー、プロバイダー、ロール、権限を、デプロイメントの他の設定と同じ values ファイルに保持できます。Casdoor は起動時にこれらを適用し、30 秒ごとにチェックして変更を確認します。helm upgrade でこれらの値を変更すると、Pod を再起動せずに反映されます。

initData:
enabled: true
data:
organizations:
- owner: admin
name: acme
displayName: Acme
passwordType: bcrypt
applications:
- owner: admin
name: app-acme
organization: acme
displayName: Acme Portal
redirectUris:
- https://portal.acme.example.com/callback

既存のオブジェクトには、ここで記述したフィールドのみが適用されます。その他のフィールドは、管理者コンソールで設定された値のまま維持されます。

チャートはこのデータを Secret に保存します。values ファイルにデータを残さないようにするには、自分で Secret を作成し、initData.existingSecret を設定してください。

ParameterDescriptionDefault
initData.enabledApply initData.data (or initData.existingSecret)false
initData.mergeUpdate existing objects with the given fields only; when false, they are deleted and re-created on every applytrue
initData.watchIntervalSeconds between the checks for changes, 0 applies the data only at startup30
initData.existingSecretExisting Secret holding the data, instead of initData.data""
initData.existingSecretKeyKey of the file in existingSecret, .yaml/.yml keys are read as YAMLinit_data.yaml
initData.dataThe objects to apply, in the init data format{}

リリースのアップグレード​

helm upgrade casdoor oci://ghcr.io/casdoor/helm-charts/casdoor --version <version>
注

バージョン 4.15.0 までのチャートは oci://registry-1.docker.io/casbin/casdoor-helm-charts として公開されていました。この場所では現在もすべてのリリースを受け取っています。既存のリリースを新しい場所に移動するには、上記の helm upgrade コマンドを実行してください。リソース名は変わりません。

リリースのアンインストール​

helm uninstall casdoor

関連項目​