在Kubernetes中导出/导入Keycloak数据的最佳实践

muz*_*row 6 kubernetes keycloak kubernetes-helm

我正在试图找出keycloak版本3.3.0.CR1中的导入/导出最佳实践.正如我在keycloak官方页面导入/导出中看到的那样,他们描述了策略.这里是他们导出到单个文件json的示例.goint到/ keycloak/bin文件夹并运行这个:

./standalone.sh -Dkeycloak.migration.action=export -Dkeycloak.migration.provider=singleFile -Dkeycloak.migration.file=keycloak-export.json
Run Code Online (Sandbox Code Playgroud)

我登录了k8s pod.运行此命令后,我收到错误:

12:23:32,045 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
    ("core-service" => "management"),
    ("management-interface" => "http-interface")
]) - failure description: {
    "WFLYCTL0080: Failed services" => {"org.wildfly.management.http.extensible" => "java.net.BindException: Address already in use /127.0.0.1:9990"},
    "WFLYCTL0288: One or more services were unable to start due to one or more indirect dependencies not being available." => {
        "Services that were unable to start:" => ["org.wildfly.management.http.extensible.shutdown"],
        "Services that may be the cause:" => ["jboss.remoting.remotingConnectorInfoService.http-remoting-connector"]
    }
}
Run Code Online (Sandbox Code Playgroud)

正如我所见,因为Keycloak服务器运行在同一个端口所在的地方,我运行了备份脚本.这里helm/keycloak values.yml:

Service:
  Name: keycloak
  Port: 8080
  Type: ClusterIP

Deployment:
  Image: jboss/keycloak
  ImageTag: 2.5.1.Final
  ImagePullPolicy: IfNotPresent
  ContainerPort: 8080
  KeycloakUser: Admin
  KeycloakPassword: Admin
Run Code Online (Sandbox Code Playgroud)

那么在我们运行这个脚本之前应该停止服务器?我无法阻止pod内部的keycloak进程,因为进入将关闭pod并将创建新的进程.对于导出/导入(备份/恢复)数据的任何其他方式的任何建议?或者我错过了什么?

PS我甚至尝试过UI导入/导出.出口工作很好,我看到了所有数据.但是进口只有一半.他带给我所有"客户",但不是我的"领域"和"用户联合会".可能吗?

Nik*_*nko 11

基本上,您只需要在与主实例不同的端口上启动导出Keycloak实例.我刚刚使用过这样的东西:

bin/standalone.sh -Dkeycloak.migration.action=export -Dkeycloak.migration.provider=singleFile -Dkeycloak.migration.file=keycloak-export.json -Djboss.http.port=8888 -Djboss.https.port=9999 -Djboss.management.http.port=7777

重要的部分是所有的端口.如果您收到更多错误消息,您可能需要添加更多属性(grep port standalone/configuration/standalone.xml是您的朋友找到属性名称),但最后,所有错误消息都会停止,您会看到此消息:

09:15:26,550 INFO [org.keycloak.exportimport.singlefile.SingleFileExportProvider] (ServerService Thread Pool -- 52) Exporting model into file /opt/jboss/keycloak/keycloak-export.json [...] 09:15:29,565 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: Keycloak 3.2.0.Final (WildFly Core 2.0.10.Final) started in 12156ms - Started 444 of 818 services (558 services are lazy, passive or on-demand)

现在,您可以使用Ctrl- 停止服务器C,退出容器并复制导出文件kubectl cp.

  • 您还可以使用-Djboss.socket.binding.port-offset来偏移所有端口 (5认同)