How can a project member create a namespace via command line (kubectl)
Article Number: 000021426
Environment
Rancher Version: v2.7.x and above
Situation
In a project setting, a collaborating member can seamlessly establish a namespace via the user interface for workload deployment. For proponents of GitOps and users predominantly utilizing command-line interfaces (CLIs), this approach proves beneficial for deploying a project's namespace efficiently.
Resolution
To efficiently configure user access and namespace deployment within a project environment, the following steps should be undertaken:
- Create a user profile with ANY user permissions (User-Base, Administrator, Restricted Administrator, Standard User) and assign the role of ‘Project Member’ within the Project through the Rancher user interface
- Login to the Rancher user interface as the new user.
- Initiate the generation of a
KUBECONFIG
file via the user interface linked to the respective user's profile. - Develop a namespace manifest incorporating the specific annotation: "field.cattle.io/projectId: c-m-zk2csxxp:p-bsr6h", where "c-m-zk2csxxp" represents the ClusterID for the targeted cluster and "p-bsr6h" signifies the projectID.
Example:
apiVersion: v1
kind: Namespace
metadata:
name: demo
annotations:
field.cattle.io/projectId: c-m-cbkjbt2m:p-872c7
- Configure the system environment variable, KUBECONFIG, to point to the newly generated kubeconfig file from Command Line Interface of your choice.
- Execute the kubectl create command to instantiate the namespace creation process.
- Validate the operation's success by verifying the newly created namespace within the designated project through the Rancher user interface.