Questo contenuto non è disponibile nella lingua selezionata.
Chapter 2. Projects
2.1. Working with projects Copia collegamentoCollegamento copiato negli appunti!
A project allows a community of users to organize and manage their content in isolation from other communities.
Projects starting with
openshift-
kube-
openshift-
kube-
oc new-project
oc adm new-project
You cannot assign an SCC to pods created in one of the default namespaces:
default
kube-system
kube-public
openshift-node
openshift-infra
openshift
2.1.1. Creating a project using the web console Copia collegamentoCollegamento copiato negli appunti!
If allowed by your cluster administrator, you can create a new project.
Projects starting with
openshift-
kube-
openshift-
You cannot assign an SCC to pods created in one of the default namespaces:
default
kube-system
kube-public
openshift-node
openshift-infra
openshift
Procedure
-
Navigate to Home
Projects. - Click Create Project.
- Enter your project details.
- Click Create.
2.1.2. Creating a project using the Developer perspective in the web console Copia collegamentoCollegamento copiato negli appunti!
You can use the Developer perspective in the OpenShift Container Platform web console to create a project in your cluster.
Projects starting with
openshift-
kube-
openshift-
kube-
oc adm new-project
You cannot assign an SCC to pods created in one of the default namespaces:
default
kube-system
kube-public
openshift-node
openshift-infra
openshift
Prerequisites
- Ensure that you have the appropriate roles and permissions to create projects, applications, and other workloads in OpenShift Container Platform.
Procedure
You can create a project using the Developer perspective, as follows:
Click the Project drop-down menu to see a list of all available projects. Select Create Project.
Figure 2.1. Create project
-
In the Create Project dialog box, enter a unique name, such as , in the Name field.
myproject - Optional: Add the Display Name and Description details for the project.
- Click Create.
- Use the left navigation panel to navigate to the Project view and see the dashboard for your project.
Optional:
- Use the Project drop-down menu at the top of the screen and select all projects to list all of the projects in your cluster.
- Use the Details tab to see the project details.
- If you have adequate permissions for a project, you can use the Project Access tab to provide or revoke administrator, edit, and view privileges for the project.
2.1.3. Creating a project using the CLI Copia collegamentoCollegamento copiato negli appunti!
If allowed by your cluster administrator, you can create a new project.
Projects starting with
openshift-
kube-
openshift-
kube-
oc new-project
oc adm new-project
You cannot assign an SCC to pods created in one of the default namespaces:
default
kube-system
kube-public
openshift-node
openshift-infra
openshift
Procedure
Run:
$ oc new-project <project_name> \ --description="<description>" --display-name="<display_name>"For example:
$ oc new-project hello-openshift \ --description="This is an example project" \ --display-name="Hello OpenShift"
The number of projects you are allowed to create might be limited by the system administrator. After your limit is reached, you might have to delete an existing project in order to create a new one.
2.1.4. Viewing a project using the web console Copia collegamentoCollegamento copiato negli appunti!
Procedure
-
Navigate to Home
Projects. Select a project to view.
On this page, click Workloads to see workloads in the project.
2.1.5. Viewing a project using the CLI Copia collegamentoCollegamento copiato negli appunti!
When viewing projects, you are restricted to seeing only the projects you have access to view based on the authorization policy.
Procedure
To view a list of projects, run:
$ oc get projectsYou can change from the current project to a different project for CLI operations. The specified project is then used in all subsequent operations that manipulate project-scoped content:
$ oc project <project_name>
2.1.6. Providing access permissions to your project using the Developer perspective Copia collegamentoCollegamento copiato negli appunti!
You can use the Project view in the Developer perspective to grant or revoke access permissions to your project.
Procedure
To add users to your project and provide Admin, Edit, or View access to them:
- In the Developer perspective, navigate to the Project view.
- In the Project page, select the Project Access tab.
Click Add Access to add a new row of permissions to the default ones.
Figure 2.2. Project permissions
- Enter the user name, click the Select a role drop-down list, and select an appropriate role.
- Click Save to add the new permissions.
You can also use:
- The Select a role drop-down list, to modify the access permissions of an existing user.
- The Remove Access icon, to completely remove the access permissions of an existing user to the project.
Advanced role-based access control is managed in the Roles and Roles Binding views in the Administrator perspective.
2.1.7. Customizing the available cluster roles using the Developer perspective Copia collegamentoCollegamento copiato negli appunti!
The users of a project are assigned to a cluster role based on their access control. You can access these cluster roles by navigating to the Project
To add or edit the cluster roles for a project, you can customize the YAML code of the cluster.
Procedure
To customize the different cluster roles of a project:
-
In the Search view, use the Resources drop-down list to search for .
Console From the available options, select the Console
operator.openshift.io/v1.Figure 2.3. Searching Console resource
- Select cluster under the Name list.
- Navigate to the YAML tab to view and edit the YAML code.
In the YAML code under
, add or edit the list ofspecand save your changes:availableClusterRolesspec: customization: projectAccess: availableClusterRoles: - admin - edit - view
2.1.8. Adding to a project Copia collegamentoCollegamento copiato negli appunti!
Procedure
- Select Developer from the context selector at the top of the web console navigation menu.
- Click +Add
- At the top of the page, select the name of the project that you want to add to.
- Click a method for adding to your project, and then follow the workflow.
You can also add components to the topology using quick search.
2.1.9. Checking project status using the web console Copia collegamentoCollegamento copiato negli appunti!
Procedure
-
Navigate to Home
Projects. - Select a project to see its status.
2.1.10. Checking project status using the CLI Copia collegamentoCollegamento copiato negli appunti!
Procedure
Run:
$ oc statusThis command provides a high-level overview of the current project, with its components and their relationships.
2.1.11. Deleting a project using the web console Copia collegamentoCollegamento copiato negli appunti!
You can delete a project by using the OpenShift Container Platform web console.
If you do not have permissions to delete the project, the Delete Project option is not available.
Procedure
-
Navigate to Home
Projects. - Locate the project that you want to delete from the list of projects.
-
On the far right side of the project listing, select Delete Project from the Options menu
.
- When the Delete Project pane opens, enter the name of the project that you want to delete in the field.
- Click Delete.
2.1.12. Deleting a project using the CLI Copia collegamentoCollegamento copiato negli appunti!
When you delete a project, the server updates the project status to Terminating from Active. Then, the server clears all content from a project that is in the Terminating state before finally removing the project. While a project is in Terminating status, you cannot add new content to the project. Projects can be deleted from the CLI or the web console.
Procedure
Run:
$ oc delete project <project_name>
2.2. Creating a project as another user Copia collegamentoCollegamento copiato negli appunti!
Impersonation allows you to create a project as a different user.
2.2.1. API impersonation Copia collegamentoCollegamento copiato negli appunti!
You can configure a request to the OpenShift Container Platform API to act as though it originated from another user. For more information, see User impersonation in the Kubernetes documentation.
2.2.2. Impersonating a user when you create a project Copia collegamentoCollegamento copiato negli appunti!
You can impersonate a different user when you create a project request. Because
system:authenticated:oauth
Procedure
To create a project request on behalf of a different user:
$ oc new-project <project> --as=<user> \ --as-group=system:authenticated --as-group=system:authenticated:oauth
2.3. Configuring project creation Copia collegamentoCollegamento copiato negli appunti!
In OpenShift Container Platform, projects are used to group and isolate related objects. When a request is made to create a new project using the web console or
oc new-project
As a cluster administrator, you can allow and configure how developers and service accounts can create, or self-provision, their own projects.
2.3.1. About project creation Copia collegamentoCollegamento copiato negli appunti!
The OpenShift Container Platform API server automatically provisions new projects based on the project template that is identified by the
projectRequestTemplate
admin
When a project request is submitted, the API substitutes the following parameters into the template:
| Parameter | Description |
|---|---|
|
| The name of the project. Required. |
|
| The display name of the project. May be empty. |
|
| The description of the project. May be empty. |
|
| The user name of the administrating user. |
|
| The user name of the requesting user. |
Access to the API is granted to developers with the
self-provisioner
self-provisioners
2.3.2. Modifying the template for new projects Copia collegamentoCollegamento copiato negli appunti!
As a cluster administrator, you can modify the default project template so that new projects are created using your custom requirements.
To create your own custom project template:
Procedure
-
Log in as a user with privileges.
cluster-admin Generate the default project template:
$ oc adm create-bootstrap-project-template -o yaml > template.yaml-
Use a text editor to modify the generated file by adding objects or modifying existing objects.
template.yaml The project template must be created in the
namespace. Load your modified template:openshift-config$ oc create -f template.yaml -n openshift-configEdit the project configuration resource using the web console or CLI.
Using the web console:
-
Navigate to the Administration
Cluster Settings page. - Click Configuration to view all configuration resources.
- Find the entry for Project and click Edit YAML.
-
Navigate to the Administration
Using the CLI:
Edit the
resource:project.config.openshift.io/cluster$ oc edit project.config.openshift.io/cluster
Update the
section to include thespecandprojectRequestTemplateparameters, and set the name of your uploaded project template. The default name isname.project-requestProject configuration resource with custom project template
apiVersion: config.openshift.io/v1 kind: Project metadata: ... spec: projectRequestTemplate: name: <template_name>- After you save your changes, create a new project to verify that your changes were successfully applied.
2.3.3. Disabling project self-provisioning Copia collegamentoCollegamento copiato negli appunti!
You can prevent an authenticated user group from self-provisioning new projects.
Procedure
-
Log in as a user with privileges.
cluster-admin View the
cluster role binding usage by running the following command:self-provisioners$ oc describe clusterrolebinding.rbac self-provisionersExample output
Name: self-provisioners Labels: <none> Annotations: rbac.authorization.kubernetes.io/autoupdate=true Role: Kind: ClusterRole Name: self-provisioner Subjects: Kind Name Namespace ---- ---- --------- Group system:authenticated:oauthReview the subjects in the
section.self-provisionersRemove the
cluster role from the groupself-provisioner.system:authenticated:oauthIf the
cluster role binding binds only theself-provisionersrole to theself-provisionergroup, run the following command:system:authenticated:oauth$ oc patch clusterrolebinding.rbac self-provisioners -p '{"subjects": null}'If the
cluster role binding binds theself-provisionersrole to more users, groups, or service accounts than theself-provisionergroup, run the following command:system:authenticated:oauth$ oc adm policy \ remove-cluster-role-from-group self-provisioner \ system:authenticated:oauth
Edit the
cluster role binding to prevent automatic updates to the role. Automatic updates reset the cluster roles to the default state.self-provisionersTo update the role binding using the CLI:
Run the following command:
$ oc edit clusterrolebinding.rbac self-provisionersIn the displayed role binding, set the
parameter value torbac.authorization.kubernetes.io/autoupdate, as shown in the following example:falseapiVersion: authorization.openshift.io/v1 kind: ClusterRoleBinding metadata: annotations: rbac.authorization.kubernetes.io/autoupdate: "false" ...
To update the role binding by using a single command:
$ oc patch clusterrolebinding.rbac self-provisioners -p '{ "metadata": { "annotations": { "rbac.authorization.kubernetes.io/autoupdate": "false" } } }'
Log in as an authenticated user and verify that it can no longer self-provision a project:
$ oc new-project testExample output
Error from server (Forbidden): You may not request a new project via this API.Consider customizing this project request message to provide more helpful instructions specific to your organization.
2.3.4. Customizing the project request message Copia collegamentoCollegamento copiato negli appunti!
When a developer or a service account that is unable to self-provision projects makes a project creation request using the web console or CLI, the following error message is returned by default:
You may not request a new project via this API.
Cluster administrators can customize this message. Consider updating it to provide further instructions on how to request a new project specific to your organization. For example:
-
To request a project, contact your system administrator at .
projectname@example.com -
To request a new project, fill out the project request form located at .
https://internal.example.com/openshift-project-request
To customize the project request message:
Procedure
Edit the project configuration resource using the web console or CLI.
Using the web console:
-
Navigate to the Administration
Cluster Settings page. - Click Configuration to view all configuration resources.
- Find the entry for Project and click Edit YAML.
-
Navigate to the Administration
Using the CLI:
-
Log in as a user with privileges.
cluster-admin Edit the
resource:project.config.openshift.io/cluster$ oc edit project.config.openshift.io/cluster
-
Log in as a user with
Update the
section to include thespecparameter and set the value to your custom message:projectRequestMessageProject configuration resource with custom project request message
apiVersion: config.openshift.io/v1 kind: Project metadata: ... spec: projectRequestMessage: <message_string>For example:
apiVersion: config.openshift.io/v1 kind: Project metadata: ... spec: projectRequestMessage: To request a project, contact your system administrator at projectname@example.com.- After you save your changes, attempt to create a new project as a developer or service account that is unable to self-provision projects to verify that your changes were successfully applied.