Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Kubernetes users limited to namespaces

I have a hard time trying to set up my (test) Kubernetes cluster so that it have a few users and a few namespaces, and a user can only see specific namespaces. Is there a way to do that? If yes, what is needed to

  1. Create a user
  2. Limit a user to a specific namespace or namespaces
  3. Use Kubernetes (via kubectl) as a specific user
like image 830
user308993 Avatar asked Feb 27 '16 00:02

user308993


People also ask

How do I restrict namespaces in Kubernetes?

To achieve this, you have to create Roles (or a ClusterRole) and RoleBindings in those namespaces that you want to grant access to the users. Here is how you can grant access to all resources for the dev-team user in the dev and qa namespace but deny access to any resources in any other namespace.

How many namespaces are there in Kubernetes limit?

There is no limit on number of namespaces. You can create as many as you want. It doesn't actually consume cluster resources like cpu, memory etc.

How do I manage users in Kubernetes?

Kubernetes doesn't manage users. Normal users are assumed to be managed by an outside, independent service like LDAP or Active Directory. In a standard installation of Kubernetes (i.e., using kubeadm), authentication is done via standard transport level security (TLS) certificates.

What is--namespace in Kubernetes?

kube-node-lease This namespace for the lease objects associated with each node which improves the performance of the node heartbeats as the cluster scales. To set the namespace for a current request, use the --namespace flag. You can permanently save the namespace for all subsequent kubectl commands in that context.

How do I list the current namespaces in a Kubernetes cluster?

You can list the current namespaces in a cluster using: Kubernetes starts with four initial namespaces: kube-public This namespace is created automatically and is readable by all users (including those not authenticated).

How to prepare your Kubernetes cluster to become multi-tenant ready?

Before digging into how to use namespaces to prepare your Kubernetes cluster to become multi-tenant-ready, you need to know what namespaces are. A namespace is a Kubernetes object that partitions a Kubernetes cluster into multiple virtual clusters. This is done with the aid of Kubernetes names and IDs.

When should I use namespaces?

Namespaces are intended for use in environments with many users spread across multiple teams, or projects. For clusters with a few to tens of users, you should not need to create or think about namespaces at all. Start using namespaces when you need the features they provide.


1 Answers

You could setup ABAC (http://kubernetes.io/docs/admin/authorization/) and limit users to namespaces:

In the policy file you would have something like this if your user was bob and you wanted to limit him to the namespace projectCaribou:

{
  "apiVersion": "abac.authorization.kubernetes.io/v1beta1",
  "kind": "Policy",
  "spec": {
    "namespace": "projectCaribou",
    "readonly": true,
    "resource": "pods",
    "user": "bob"
  }
}
like image 113
Steve Sloka Avatar answered Sep 22 '22 19:09

Steve Sloka