跳到主内容

使用Helm尝试

本页面介绍如何使用Helm在Kubernetes上部署Casdoor。

先决条件

  • 运行中的Kubernetes集群(1.19+)
  • Helm v3.8+

安装

步骤1:安装Casdoor图表

安装Casdoor Helm图表

helm install casdoor oci://registry-1.docker.io/casbin/casdoor-helm-charts --version <version>

使用自定义值文件进行安装:

helm install casdoor oci://registry-1.docker.io/casbin/casdoor-helm-charts \
--version <0> \
-f my-values.yaml

步骤2:访问Casdoor

安装完成后,使用集群提供的服务URL访问Casdoor。

定制

覆盖values.yaml以自定义部署。 关键参数:

参数描述默认值
replicaCount运行 Casdoor 应用的副本数量。1
image.repositoryCasdoor Docker 图像的仓库。casbin
image.nameCasdoor Docker 图像的名称。casdoor
image.pullPolicyCasdoor Docker 图像的拉取策略。IfNotPresent
image.tagCasdoor Docker 图像的标签。""
configCasdoor 应用的配置设置。请参阅 values.yaml
database.driver要使用的数据库驱动程序(mysqlpostgrescockroachdbsqlite)。sqlite
database.user数据库用户名。""
database.password数据库密码。""
database.host数据库主机。""
database.port数据库端口。""
database.databaseNameCasdoor 使用的数据库名称。casdoor
database.sslMode数据库连接的 SSL 模式。disable
service.typeKubernetes服务类型(ClusterIPNodePortLoadBalancer)。ClusterIP
service.portCasdoor 服务的端口号。8000
ingress.enabled是否启用 Casdoor 的 Ingress。false
ingress.annotationsIngress 资源的注解。{}
ingress.hostsIngress 资源的主机名。[]
resourcesCasdoor 容器的资源请求和限制。`{}
autoscaling.enabled是否启用 Casdoor 的水平 Pod 自动扩展。false
autoscaling.minReplicasHPA 的最小副本数。1
autoscaling.maxReplicasHPA 的最大副本数。100
autoscaling.targetCPUUtilizationPercentageHPA 的目标 CPU 利用率百分比。80
nodeSelectorPod 分配的节点标签。{}
tolerationsPod 分配的容忍标签。[]
affinityPod 分配的亲和性设置。`{}
extraContainersEnabled是否启用额外的边车容器。false
extraContainers额外的边车容器。""
extraVolumeMountsCasdoor 容器的额外卷挂载。[]
extraVolumesCasdoor 容器的额外卷。[]
envFromSecret来自单个Secret密钥的环境变量。[]
envFromConfigmap来自单个ConfigMap密钥的环境变量。`[]'
envFrom来自整个 Secret 或 ConfigMap 的环境变量。[]

暴露 Casdoor

选项 1:Ingress(经典)

启用并配置 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

选项2:网关API(现代)

Kubernetes 网关 API 是 Ingress 的下一代替代方案,自 Kubernetes 1.31 起已正式进入 GA 阶段。 它由Istio、Envoy网关、Cilium、Kong、NGINX网关Fabric等支持。

提示

先决条件

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

您还需要在集群中运行一个兼容的网关控制器。

附加到现有网关

如果您集群中已有一个网关资源,请将HTTPRoute指向它:

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

创建一个新的网关(例如使用Istio)

让图表同时创建网关和HTTPRoute:

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重定向的网关

启用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

网关API参数

参数描述默认值
gatewayApi.enabled启用HTTPRoute创建false
gatewayApi.createGateway同时创建一个 Gateway 资源false
gatewayApi.annotationsHTTPRoute 的注解{}
gatewayApi.labelsHTTPRoute 的额外标签{}
gatewayApi.parentRefs父网关引用[]
gatewayApi.hostnames要匹配的主机名(Host标头)[]
gatewayApi.rules`路由规则(匹配、过滤器、后端引用)路径前缀 /
gatewayApi.gateway.name`网关名称(默认为图表全名)""
gatewayApi.gateway.gatewayClassName网关类名称(当createGateway=true时必填)""
gatewayApi.gateway.listeners网关监听器HTTP:80
gatewayApi.httpsRedirect.enabled启用HTTP→HTTPS重定向HTTPRoutefalse
gatewayApi.httpsRedirect.statusCode重定向响应码301
gatewayApi.httpsRedirect.hostnames重定向路由的主机名[]
gatewayApi.httpsRedirect.parentRefs覆盖重定向路由的 parentRefs[]

管理部署

升级:

helm upgrade casdoor oci://registry-1.docker.io/casbin/casdoor-helm-charts --version <0>

卸载:

helm uninstall casdoor

更多选项,请参阅 HelmKubernetes 文档。