Installing Keycloak, an OIDC Provider, on OVHcloud Managed Kubernetes
Learn how to secure your OVHcloud Managed Kubernetes Cluster with OpenID Connect (OIDC) and RBAC.
To begin, what is OIDC?

OIDC stands for OpenID Connect. It is an open standard and decentralized authentication protocol.
This protocol allows for verifying the user identity when a user is trying to access a protected HTTPS endpoint.
Several OpenID Connect providers exist like Dex, Keycloak, or a SaaS provider. In this article, we will use Keycloak for our use case.
What is Keycloak?

Keycloak is an open-source identity and access management solution aimed at modern applications and services.
It makes it easy to secure applications and services with little to no code.
More information can be found here: Official Keycloak documentation
Why are we talking about OIDC and Keycloak?
That’s because, in this tutorial, we want to:
- easily secure applications and services deployed in a Kubernetes cluster
- be able to configure a working Keycloak deployment on top of a Managed Kubernetes Service provided by OVHcloud
- configure the
OpenIdConnectflags available for thekube-apiservercomponent of a Managed Kubernetes Service through the OVHcloud Control Panel - be able to use the
kubectlcommand line with the Keycloak OpenID Connect provider configured
In this tutorial, we are going to:
- install Keycloak on a freshly created OVHcloud Managed Kubernetes Service cluster.
- configure a Keycloak instance in our Kubernetes cluster as an OIDC provider.
You can use the Reset cluster function in the Public Cloud section of the OVHcloud Control Panel to reinitialize your cluster before following this tutorial.
Requirements
This tutorial assumes that you already have a working OVHcloud Managed Kubernetes cluster and some basic knowledge of how to operate it. If you want to know more on these topics, please consult the deploying a Hello World application documentation.
This tutorial has been written to be fully compliant with v1.22 of Kubernetes.
You may need to adapt it to be able to deploy a functional Keycloak instance in Kubernetes releases after v1.22.
Dependencies
A cert-manager to enable HTTPS connection through Keycloak
- More information can be found here: Official cert-manager documentation
- Helm chart description: cert-manager Helm chart
- Helm chart used for the deployment:
jetstack/cert-manager
How to add the cert-manager Helm repository:
How to install the cert-manager operator from its Helm chart:
This command will install the cert-manager with the values we defined. Create a new cert-manager namespace, and install the new CRD (Custom Resource Definitions):
Check that the cert-manager has been deployed correctly with the kubectl get all -n cert-manager command:
You should have new Deployments, Services, ReplicaSets, and Pods running in your cluster.
Now we will create an ACME ClusterIssuer used by the cert-manager operator to request certificates from ACME servers including from Let’s Encrypt.
During this lab, we will use the Let’s Encrypt production environment to generate all our testing certificates.
WARNING: Using the Let’s Encrypt Staging environment is not recommended and is not compliant with this tutorial.
Create a ClusterIssuer in a file named issuer.yaml with the following content:
Do not forget to replace [YOUR_EMAIL] with a real value - it will be used for ACME challenges.
Apply the YAML manifest:
You should have a new ClusterIssuer deployed in your cluster:
NOTE: You can use the neat kubectl plugin to remove useless information in Kubernetes manifest files.
An Ingress Nginx to publicly expose Keycloak
- More information can be found here: Official ingress-nginx documentation
- Helm chart description: ingress-nginx Helm chart
- Helm Chart used for the deployment:
ingress-nginx/ingress-nginx
How to add ingress-nginx Helm repository:
How to install the ingress-nginx controller:
This command will install ingress-nginx and create a new ingress-nginx namespace:
You should have new resources in the ingress-nginx namespace:
If you need to customize your ingress-nginx configuration, please refer to the following documentation: ingress-nginx values
Installing this ingress-nginx controller will order a Load Balancer provided by OVHcloud (this load balancer will be billed monthly).
For more information, please refer to the following documentation: Using the OVHcloud Managed Kubernetes Load Balancer
To check if the LoadBalancer is up and running, execute the following CLI in a console:
You should obtain a result similar to this:
Once your Load Balancer is up and running, get its IP address to configure your domain name zone:
You should obtain a result similar to this:
Please configure your domain before reading the rest of this tutorial.
In our case, we have an example.com domain name. The nslookup command output of our domain entry shows the following information:
Instructions
How to configure and deploy the Codecentric Keycloak provider
- More information can be found here: Official Keycloak documentation
- Helm chart description: codecentric Keycloak Helm chart
- Helm chart used for the deployment:
codecentric/keycloak
A PersistentVolume will be created to host all PostgreSQL data.
This PersistentVolume will be provided through the Cinder storage class which is the default storage class used by Managed Kubernetes Service at OVHcloud (this volume will be billed).
For more information, please refer to the following documentation: Setting Up a Persistent Volume on OVHcloud Managed Kubernetes
Keycloak installation
Add the codeCentric repository:
Create a file called keycloak-values.yaml with the following content:
Replace all values with the comment CHANGEME with strong usernames and passwords.
Then, install the codecentric/keycloak Helm chart:
You should obtain the following result:
Check if the Keycloak StatefulSet is in a Ready state:
In our example, after waiting a few minutes, our StatefulSets are all in a Ready state:
When they are ready, create a file nginx-ingress-definition.yaml with the following content:
Replace example.com with your domain name.
Then apply the YAML file to configure the Ingress route required to expose Keycloak on the internet:
Keycloak configuration
If you are reading this chapter, it indicates that your Keycloak is now up and running.
Let’s go and open the Keycloak Web console: https://keycloak.your-domain-name.tld/.
In our example, the URL to our installed Keycloak is https://keycloak.example.com/. If you change it with your custom URL, you should see the Keycloak UI:

Now, click Administration Console and log in with the username and password configured in the keycloak-values.yaml file you filled and modified in the Keycloak installation section of this guide.

Create a REALM
A realm in Keycloak is the equivalent of a tenant or a namespace. It enables the creation of isolated groups of applications and users.
By default, there is a single realm in Keycloak called Master. It is dedicated to managing Keycloak and should not be used for your own applications.
Let’s create a dedicated realm for our tutorial:
- Display the drop-down menu in the top-left corner where it is indicated
Master. Then click on theAdd realmblue button. - Fill in the form with this name:
ovh-lab-k8s-oidc-authentication. Then click the blueCreatebutton.

Create a CLIENT
A client in Keycloak is an entity that can request a Keycloak server to authenticate a user.
-
From the previously created realm, click on the left-hand
Clientsmenu under theConfigurecategory:
-
Click
Createin the top-right corner of the table. -
Fill in the form with the following parameters:
In our example, the new client information is:

-
Click the
Savebutton. -
In the newly-created client, find the
Access Typefield and set its value toconfidentialto require a secret to initiate the login protocol. Then click the blueSavebutton to save the change.
-
Then click on the
Credentialstab. Find theValid Redirect URIsfield and set the following value:* -
Find the
Admin URLand theWeb Originsfields and set their values to your defined domain name if it is not already done.InfoIn our example:
https://keycloak.example.com/.
__\/!\ Be careful to use the HTTPS schema only /!\__ -
Save your changes.
Create a USER
-
From the previously created realm, click on the left-hand
Usersmenu under theManagecategory. -
Click
Add userin the top-right corner of the table. -
Fill in the form. Only the
Usernamefield is required, which is all we need for this tutorial.In our example, we have created the following user:
- Click the
Savebutton.
The first user connection requires an initial password, so let’s create it:
- Click on the
Credentialstab. - Fill in the
Set Passwordform. - Disable the
Temporaryflag to prevent having to update the password upon your first login. - Click the
Set Passwordbutton and confirm your choice.
Configure the Keycloak instance in your Kubernetes cluster as an OIDC provider
Now that you have a working Keycloak instance, your Provider URL is https://keycloak.example.com/auth/realms/ovh-lab-k8s-oidc-authentication. Since you created a user, you can read the Configuring the OIDC Provider on an OVHcloud Managed Kubernetes Cluster guide to configure the OIDC provider on your Kubernetes cluster via the OVHcloud Control Panel, the OVHcloud API, or via Terraform.
Explanations:
- In the
Provider URLfield, you should copy/paste the URL to access the previously defined realm: https://${your-configured-root-url}/auth/realms/${your-configured-realm-name}
In our example, we used the ovh-lab-k8s-oidc-authentication realm issuer URL: https://keycloak.example.com/auth/realms/ovh-lab-k8s-oidc-authentication.
- In
Client ID, you should copy/paste the name of the Keycloak client previously defined.
In our example, we defined the client named: k8s-oidc-auth.
Our Kubernetes cluster is now configured with our Keycloak instances - both are linked.
OIDC integration and configuration
If it is not already done, you must install the kubectl plugin manager named Krew.
Then, install the oidc-login plugin to extend the capacity of the kubectl command line and easily configure your environment to use your Keycloak server.
Once oidc-login is installed, go back to the Keycloak web interface to get your client secret.
You can find this information here:
- Click on the
Clientsmenu in the left-hand column - Click on your previously created client (
k8s-oidc-authin my example) - Go to the
Credentialstab and get yoursecretvalue


Then, customize the following command line with your information, and execute it to be able to:
- Log into your Keycloak provider through your browser
- Generate a token from it
- Configure your Kubectl context to access the Kubernetes APIs with the freshly generated token
See the example below:
Your favorite browser will display an authentication page to your Keycloak server.
Log in with the credentials defined during the user creation step of this tutorial.
Once the authentication has succeeded, you can close your browser tab or go back to your console where a message is displayed.
The oidc-login plugin has given you some instructions to follow to finalize the configuration of your Kubectl environment.
In step 3 of the oidc-login output, you must create a ClusterRoleBinding:
You can ignore step 4 because we already configured the kube-apiserver through the OVHcloud Control Panel.
Then, for step 5, configure your kubeconfig:
Verify your cluster access (step 6 of the oidc-login output) with the following command:
For example:
If you can see the nodes of your Managed Kubernetes Service, congratulations, your Keycloak instance is up and running!
Upgrade the Keycloak deployment if needed
Enter the following command:
Rollout restarts the Keycloak Stateful Sets if needed
Various troubleshooting
If the cert-manager namespace is stuck in the deleting state, see the following documentation: namespace-stuck-in-terminating-state
Cleanup
To clean up all existing resources related to the Keycloak Helm chart, you can execute the following commands:
To clean up all existing resources related to the ingress-nginx Helm chart, execute the following commands:
To clean up all existing resources related to the cert-manager Helm chart, execute the following commands:
Useful resources
- Keycloak documentation
- ArtifactHUB keycloak
- Cert-manager Securing Ingress Resources
- Keycloak on Kubernetes
- Kubernetes API Access Control documentation
Go further
Browse all the Managed Kubernetes Service (MKS) guides.
Browse the rest of the OVHcloud US documentation for guides on our other products and services.
Learn more about Managed Kubernetes on the OVHcloud US website.