1
<#import "/templates/guide.adoc" as tmpl>
2
<#import "/templates/kc.adoc" as kc>
3
<#import "/templates/options.adoc" as opts>
4
<#import "/templates/links.adoc" as links>
7
title="{project_name} Realm Import"
9
summary="How to perform an automated {project_name} Realm Import using the operator">
11
== Importing a {project_name} Realm
13
Using the {project_name} Operator, you can perform a realm import for the Keycloak Deployment.
17
* If a Realm with the same name already exists in {project_name}, it will not be overwritten.
19
* The Realm Import CR only supports creation of new realms and does not update or delete those. Changes to the realm performed directly on {project_name} are not synced back in the CR.
22
=== Creating a Realm Import Custom Resource
24
The following is an example of a Realm Import Custom Resource (CR):
28
apiVersion: k8s.keycloak.org/v2alpha1
29
kind: KeycloakRealmImport
33
keycloakCRName: <name of the keycloak CR>
38
This CR should be created in the same namespace as the Keycloak Deployment CR, defined in the field `keycloakCRName`.
39
The `realm` field accepts a full https://www.keycloak.org/docs-api/{version}/rest-api/index.html#RealmRepresentation[RealmRepresentation].
41
The recommended way to obtain a `RealmRepresentation` is by leveraging the export functionality <@links.server id="importExport"/>.
43
. Export the Realm to a single file.
44
. Convert the JSON file to YAML.
45
. Copy and paste the obtained YAML file as body for the `realm` key, making sure the indentation is correct.
47
=== Applying the Realm Import CR
49
Use `kubectl` to create the CR in the correct cluster namespace:
51
Create YAML file `example-realm-import.yaml`:
55
apiVersion: k8s.keycloak.org/v2alpha1
56
kind: KeycloakRealmImport
60
keycloakCRName: <name of the keycloak CR>
64
displayName: ExampleRealm
72
kubectl apply -f example-realm-import.yaml
75
To check the status of the running import, enter the following command:
79
kubectl get keycloakrealmimports/my-realm-kc -o go-template='{{range .status.conditions}}CONDITION: {{.type}}{{"\n"}} STATUS: {{.status}}{{"\n"}} MESSAGE: {{.message}}{{"\n"}}{{end}}'
82
When the import has successfully completed, the output will look like the following example: