Install Keycloak in Kubernetes

Published
Length
3 min read

Luis Felipe Dias

All posts

To install keycloak in kubernetes, you create a dedicated namespace, deploy a database, and run the identity pods. Next, you attach network services and secrets so the identity app can start and serve traffic. Most engineering teams run this setup using shared cluster roles so they can fix startup problems fast. Still, broad permissions let engineers read secrets or run raw commands inside the identity pod itself. How to install keycloak in kubernetes A clean deployment starts with a dedicate

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

To install keycloak in kubernetes, you create a dedicated namespace, deploy a database, and run the identity pods. Next, you attach network services and secrets so the identity app can start and serve traffic. Most engineering teams run this setup using shared cluster roles so they can fix startup problems fast. Still, broad permissions let engineers read secrets or run raw commands inside the identity pod itself.

How to install keycloak in kubernetes

A clean deployment starts with a dedicated namespace for the identity app and its backing database. Isolating the workload in one namespace keeps its storage, network rules, and secrets separate from other apps. You define secret objects in that namespace to hold the admin login and the database credentials. Then you deploy the database workload and wait for the storage volume to report a ready state.

Once the database runs, you deploy the identity app pods and point them at the database service. The pods read the secret objects at startup to set up the initial admin account and database link. Next, you expose the pods through an internal service and an ingress controller with TLS certificates. The identity server needs clean TLS routing so client apps and browsers trust the login tokens it issues.

To manage these objects, Kubernetes RBAC uses Roles and RoleBindings inside that single namespace. A Role holds a set of rules that grant permissions within one namespace only. In Kubernetes, RBAC permissions are purely additive, which means there are no deny rules at all. A RoleBinding connects a user or group to that Role inside the specific identity namespace. If an admin uses a ClusterRoleBinding instead, that binding grants permissions across the entire cluster.

Where native Kubernetes roles fall short

Native roles work well when you only need to decide who can deploy or update a pod. You can limit a team to a single namespace so they cannot touch other workloads in the cluster. You can also control subresources, which Kubernetes writes with a slash in the rule definition. For example, a rule can grant access to pod logs or allow exec sessions into a running container.

The gap appears after an engineer starts an interactive shell inside the identity pod or database pod. Kubernetes RBAC checks whether the user can start the exec subresource when the session begins. Once the shell opens, Kubernetes does not inspect the individual commands or database queries running inside that session. An engineer with shell access can dump environment variables, read mounted keys, or alter identity tables directly.

Keycloak + Just-in-Time Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Standard cluster logs record that an exec call happened, not what the user typed inside the pod. Also, if database results return sensitive fields like emails or phone numbers, native RBAC does not mask them. Giving engineers direct pod shell access to debug login issues exposes every secret stored in that namespace.

Check Kubernetes API requests and responses on the wire

Kubernetes RBAC decides who may call the API server. RBAC does not check response payloads or split listing Secret names from reading Secret values when a role grants get access. With hoop.dev, you run an open-source HTTP proxy, a sidecar for your Kubernetes API. The kubectl client changes only the server address it talks to while RBAC stays in place.

On each call, hoop.dev guardrails read the method, normalized path, and headers to refuse bad deletes or full Secret reads with a 403 error. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs. Every request and verdict is logged without storing bearer tokens. View the project on GitHub.

Frequently asked questions

Should I use a Role or a ClusterRole for the identity namespace?

Use a Role and a RoleBinding so permissions stay inside the single identity namespace. A ClusterRoleBinding grants access across the whole cluster, which is too broad for one app team.

Can Kubernetes RBAC block specific commands inside a pod shell?

No, Kubernetes RBAC only controls who can open the exec subresource on a pod. It does not inspect or block individual shell commands once the interactive session starts.

How does Kubernetes handle deny rules for sensitive identity secrets?

Kubernetes RBAC permissions are purely additive and do not support deny rules. To block secret access, you must omit secret read verbs from every Role bound to that user.

Short role checks help teams work fast. Simple rules make each review clear. Good logs keep every team safe. Scoped keys stop bad changes early.

The query runs. The emails stay hidden.