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 リポジトリにあります。
-
チャートをインストールします。
<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 -
クラスター内の
casdoorサービスの URL で Casdoor を開きます。デフォルトの値では、サービスはポート 8000 のClusterIPタイプであるため、公開するまでクラスター内からのみ到達可能です。 -
初回訪問時、Casdoor は Welcome to Casdoor ページを開きます。
adminのパスワードを設定し、Set Password をクリックします。管理者コンソールへのサインインを参照してください。代わりに、初回起動前にパスワードを設定するには、Secret から読み取ってください:
kubectl create secret generic casdoor-admin --from-literal=initAdminPassword='<admin-password>'initAdminPassword:
existingSecret: casdoor-admininitAdminPassword.existingSecretKeyは Secret 内の別のキーを選択します。ローカルテストでは--set initAdminPassword.value=<admin-password>も有効ですが、パスワードが values ファイルと Helm リリースに含まれることになります。この設定は、Casdoor が新しいデータベースを作成する場合にのみ適用されます。
デプロイメントのカスタマイズ
values.yaml の値を、独自の values ファイルで上書きします。主な値は以下の通りです:
| パラメーター | 説明 | デフォルト |
|---|---|---|
replicaCount | Casdoorアプリケーションを実行するレプリカの数。 | 1 |
image.repository | Casdoor Dockerイメージのリポジトリ。 | casbin |
image.name | Casdoor Dockerイメージの名前。 | casdoor |
image.pullPolicy | Casdoor Dockerイメージのプルポリシー。 | IfNotPresent |
image.tag | Casdoor Dockerイメージのタグ。 | "" |
config | Casdoorアプリケーションの設定。 | See values.yaml |
initAdminPassword.value | 新しいデータベース用の built-in/admin のパスワード; existingSecret の方が安全です。 | "" |
initAdminPassword.existingSecret | 初期パスワードを保持する既存の Secret。 | "" |
initAdminPassword.existingSecretKey | existingSecret 内の初期パスワードのキー。 | initAdminPassword |
database.driver | Database driver to use (mysql, postgres, cockroachdb, sqlite). | sqlite |
database.user | データベースのユーザー名。 | "" |
database.password | データベースのパスワード。 | "" |
database.host | データベースのホスト。 | "" |
database.port | データベースのポート。 | "" |
database.databaseName | Casdoorが使用するデータベースの名前。 | casdoor |
database.sslMode | データベース接続のSSLモード。 | disable |
service.type | Type of Kubernetes service (ClusterIP, NodePort, LoadBalancer). | ClusterIP |
service.port | Casdoorサービスのポート番号。 | 8000 |
service.annotations | Annotations for the Kubernetes Service, for example the annotations of a cloud load balancer when service.type is LoadBalancer. | {} |
ingress.enabled | CasdoorのIngressを有効にするかどうか。 | false |
ingress.annotations | Ingressリソースのアノテーション。 | {} |
ingress.hosts | Ingressリソースのホスト名。 | [] |
resources | Casdoorコンテナのリソースリクエストとリミット。 | {} |
autoscaling.enabled | CasdoorのHorizontal Pod Autoscalerを有効にするかどうか。 | false |
autoscaling.minReplicas | Minimum number of replicas for HPA. | 1 |
autoscaling.maxReplicas | Maximum number of replicas for HPA. | 100 |
autoscaling.targetCPUUtilizationPercentage | Target CPU utilization percentage for HPA. | 80 |
nodeSelector | ポッド割り当てのためのノードラベル。 | {} |
tolerations | ポッド割り当てのためのトレランスラベル。 | [] |
affinity | ポッド割り当てのためのアフィニティ設定。 | {} |
extraContainersEnabled | 追加のサイドカーコンテナを有効にするかどうか。 | false |
extraContainers | 追加のサイドカーコンテナ。 | "" |
extraVolumeMounts | Casdoorコンテナの追加のボリュームマウント。 | [] |
extraVolumes | Casdoorコンテナの追加のボリューム。 | [] |
envFromSecret | Environment variables from individual Secret keys. | [] |
envFromConfigmap | Environment variables from individual ConfigMap keys. | [] |
envFrom | Environment 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.enabled | Enable HTTPRoute creation | false |
gatewayApi.createGateway | Also create a Gateway resource | false |
gatewayApi.annotations | Annotations for the HTTPRoute | {} |
gatewayApi.labels | Extra labels for the HTTPRoute | {} |
gatewayApi.parentRefs | Parent Gateway references | [] |
gatewayApi.hostnames | Hostnames to match (Host header) | [] |
gatewayApi.rules | Routing rules (matches, filters, backendRefs) | PathPrefix / |
gatewayApi.gateway.name | Gateway name (defaults to chart fullname) | "" |
gatewayApi.gateway.gatewayClassName | GatewayClass name (required when createGateway=true) | "" |
gatewayApi.gateway.listeners | Gateway listeners | HTTP:80 |
gatewayApi.httpsRedirect.enabled | Enable HTTP→HTTPS redirect HTTPRoute | false |
gatewayApi.httpsRedirect.statusCode | Redirect response code | 301 |
gatewayApi.httpsRedirect.hostnames | Hostnames for redirect route | [] |
gatewayApi.httpsRedirect.parentRefs | Override 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 を設定してください。
| Parameter | Description | Default |
|---|---|---|
initData.enabled | Apply initData.data (or initData.existingSecret) | false |
initData.merge | Update existing objects with the given fields only; when false, they are deleted and re-created on every apply | true |
initData.watchInterval | Seconds between the checks for changes, 0 applies the data only at startup | 30 |
initData.existingSecret | Existing Secret holding the data, instead of initData.data | "" |
initData.existingSecretKey | Key of the file in existingSecret, .yaml/.yml keys are read as YAML | init_data.yaml |
initData.data | The 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