Get project names via kubectl

How to get project names via kubectl?

I’m not sure how to do it via kubectl, but it is possible to get projects list with rancher cli with a short script (few commands).
I think I have something that I wrote if it is useful for you let me know and I will find it.

No as they are just annotations of the namespace with the project ID.

I did write a script to handle creating projects and assigning namespace to a project. It also does helpful things like generating a kubeconfig file as I mainly use this script as part of my pipelines.

I have managed to find a way to get list of project names via following curl command. You need jq tool to be able to query the json formatted output from curl command.

curl -k -u ${token} https://"${rancher_fqdn}"/v1/management.cattle.io.projects | jq '.data[].spec.displayName'

1 Like

kubectl version:
(in case you have only one cluster)
kubectl get project -o json -n local | jq -r '.items[] | .spec.displayName + " " + .metadata.name'

If you manage multiple clusters with Rancher,
I thing you should do something like:
kubectl get project -A
and then replace -n local with -n <desired-cluster-name>

Just in case you’re interested - WebUI URL to list all projects:
https://<rancher_fqdn>/dashboard/c/local/explorer/management.cattle.io.project

And, yes, you can create Projects with id = name using normal yamls

apiVersion: management.cattle.io/v3
kind: Project
metadata:
  # generateName: p-
  name: the-proj-name
  namespace: local
spec:
  clusterName: local
  displayName: the-proj-name
  enableProjectMonitoring: false
  namespaceDefaultResourceQuota:
    limit: {}
  resourceQuota:
    limit: {}
    usedLimit: {}