mirror of
https://github.com/rancher/rancher-docs.git
synced 2026-09-29 14:38:50 +00:00
Merge pull request #998 from btat/projects-api
API: Project Workflow Examples
This commit is contained in:
@@ -0,0 +1,109 @@
|
|||||||
|
---
|
||||||
|
title: Projects
|
||||||
|
---
|
||||||
|
|
||||||
|
## Creating a Project
|
||||||
|
|
||||||
|
Project resources may only be created on the management cluster. See below for [creating namespaces under projects in a managed cluster](#creating-a-namespace-in-a-project).
|
||||||
|
|
||||||
|
### Creating a Basic Project
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl create -f - <<EOF
|
||||||
|
apiVersion: management.cattle.io/v3
|
||||||
|
kind: Project
|
||||||
|
metadata:
|
||||||
|
generateName: p-
|
||||||
|
namespace: c-m-abcde
|
||||||
|
spec:
|
||||||
|
clusterName: c-m-abcde
|
||||||
|
displayName: myproject
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `metadata.generateName` to ensure a unique project ID, but note that `kubectl apply` does not work with `metadata.generateName`, so `kubectl create` must be used instead.
|
||||||
|
|
||||||
|
Set `metadata.namespace` and `spec.clusterName` to the ID for the cluster the project belongs to.
|
||||||
|
|
||||||
|
### Creating a Project With a Resource Quota
|
||||||
|
|
||||||
|
Refer to [Kubernetes Resource Quota](https://kubernetes.io/docs/concepts/policy/resource-quotas/).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl create -f - <<EOF
|
||||||
|
apiVersion: management.cattle.io/v3
|
||||||
|
kind: Project
|
||||||
|
metadata:
|
||||||
|
generateName: p-
|
||||||
|
namespace: c-m-abcde
|
||||||
|
spec:
|
||||||
|
clusterName: c-m-abcde
|
||||||
|
displayName: myproject
|
||||||
|
resourceQuota:
|
||||||
|
limit:
|
||||||
|
limitsCpu: 1000m
|
||||||
|
namespaceDefaultResourceQuota:
|
||||||
|
limit:
|
||||||
|
limitsCpu: 50m
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creating a Project With Container Limit Ranges
|
||||||
|
|
||||||
|
Refer to [Kubernetes Limit Ranges](https://kubernetes.io/docs/concepts/policy/limit-range/).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl create -f - <<EOF
|
||||||
|
apiVersion: management.cattle.io/v3
|
||||||
|
kind: Project
|
||||||
|
metadata:
|
||||||
|
generateName: p-
|
||||||
|
namespace: c-m-abcde
|
||||||
|
spec:
|
||||||
|
clusterName: c-m-abcde
|
||||||
|
displayName: myproject
|
||||||
|
containerDefaultResourceLimit:
|
||||||
|
limitsCpu: 100m
|
||||||
|
limitsMemory: 100Mi
|
||||||
|
requestsCpu: 50m
|
||||||
|
requestsMemory: 50Mi
|
||||||
|
```
|
||||||
|
|
||||||
|
## Creating a Namespace in a Project
|
||||||
|
|
||||||
|
The Project resource resides in the management cluster, even if the Project is for a managed cluster. The namespaces under the project reside in the managed cluster.
|
||||||
|
|
||||||
|
On the management cluster, look up the project ID for the cluster you are administrating since it generated using `metadata.generateName`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl --namespace c-m-abcde get projects
|
||||||
|
```
|
||||||
|
|
||||||
|
On the managed cluster, create a namespace with a project annotation:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl apply -f - <<EOF
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: mynamespace
|
||||||
|
annotations:
|
||||||
|
field.cattle.io/projectId: c-m-abcde:p-vwxyz
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
Note the format, `<cluster ID>:<project ID>`.
|
||||||
|
|
||||||
|
## Deleting a Project
|
||||||
|
|
||||||
|
Look up the project to delete in the cluster namespace:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl --namespace c-m-abcde get projects
|
||||||
|
```
|
||||||
|
|
||||||
|
Delete the project under the cluster namespace:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl --namespace c-m-abcde delete project p-vwxyz
|
||||||
|
```
|
||||||
@@ -1311,17 +1311,15 @@
|
|||||||
"items": [
|
"items": [
|
||||||
"api/quickstart",
|
"api/quickstart",
|
||||||
{
|
{
|
||||||
|
"type": "category",
|
||||||
}
|
"label": "Example Workflows",
|
||||||
]
|
"items": [
|
||||||
},
|
"api/workflows/projects"
|
||||||
"contribute-to-rancher",
|
]
|
||||||
{
|
},
|
||||||
"type": "category",
|
|
||||||
"label": "API",
|
|
||||||
"items": [
|
|
||||||
"api/api-reference"
|
"api/api-reference"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"contribute-to-rancher"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user