Este conteúdo não está disponível no idioma selecionado.
Chapter 2. Network policies
A cluster hosts two types of projects:
- Projects associated with managed services. These projects support inbound and outbound connections.
- User projects. These projects support communication from managed services.
In OpenShift Dedicated, there are two approaches to enabling communications:
- Using network policies
-
Using the
join-projectoption of theoccommand
In OpenShift API Management, you can use network policies to enable communication and allow 3scale to communicate directly with the service endpoint, instead of the external URL.
You cannot use the join-projects option of the oc command with managed services projects.
2.1. Enabling communication between managed services and customer applications Copiar o linkLink copiado para a área de transferência!
You can create NetworkPolicy objects to define granular rules describing the Ingress network traffic that is allowed for projects in your cluster. By default, when you create projects in a cluster, communication between the projects is disabled.
This procedure describes how to enable communication for a project so that managed services, such as 3scale, can access customer applications.
Prerequisites
-
You have installed the OpenShift command-line interface (CLI), commonly known as
oc.
Procedure
-
Log in to the cluster using the
oclogin command. Use the following command to change the project:
oc project <project_name>
$ oc project <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow where
<project_name>is the name of a project that you want to accept communications from other projects.Create a
NetworkPolicyobject:-
Create a
allow-from-middleware-namespaces.yamlfile. Define a policy in the file you just created, such as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the following command to create the policy object:
oc create -f allow-from-middleware-namespaces.yaml -n <project>
$ oc create -f allow-from-middleware-namespaces.yaml -n <project> networkpolicy "allow-from-middleware-namespaces" createdCopy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Create a
2.2. Enabling communication between managed services and projects Copiar o linkLink copiado para a área de transferência!
By default, when you create projects in a cluster, communication between the projects is disabled. Use this procedure to enable communication in a project.
Prerequisites
-
You have installed the OpenShift command-line interface (CLI), commonly known as
oc.
Procedure
-
Log in to the cluster using the
oclogin command. Use the following command to change the project:
oc project <project_name>
$ oc project <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow where
<project_name>is the name of a project that you want to accept communications from other projects.Create a NetworkPolicy object:
-
Create a
NetworkPolicy.yamlfile. Define a policy in the file you just created, such as in the following example.
This policy enables incoming communication for all projects in the cluster:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis policy configuration enables this project to communicate with all projects in the cluster.
Run the following command to create the policy object:
oc create -f <policy-name>.yaml -n <project>
$ oc create -f <policy-name>.yaml -n <project>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Create a
2.3. Enabling communication between customer applications Copiar o linkLink copiado para a área de transferência!
You can enable communication between user applications.
Prerequisites
-
You have installed the OpenShift command-line interface (CLI), commonly known as
oc.
Procedure
-
Log in to the cluster using the
oclogin command. Use the following command to change the project:
oc project <project_name>
$ oc project <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow <project_name>is the name of a project that you want to accept communications from.Create a NetworkPolicy object:
-
Create a
allow-from-myproject-namespace.yamlfile. Define a policy in the file you just created, such as in the following example.
This policy enables incoming communication for a specific project (
myproject):Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Create a
Run the following commands to create the policy object:
oc create -f allow-from-myproject-namespace.yaml -n <project>
$ oc create -f allow-from-myproject-namespace.yaml -n <project> networkpolicy "allow-from-myproject-namespace" createdCopy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4. Disabling communication from a managed service to a project Copiar o linkLink copiado para a área de transferência!
By default, projects are created with a template that allows communication from a managed service. For example, 3scale can communicate with all of your projects.
You can disable the communication from a managed service to a project.
Prerequisites
-
You have installed the OpenShift command-line interface (CLI), commonly known as
oc - You have a project you want to isolate from the managed services.
Procedure
-
Log in to the cluster using the
oclogin command. Use the following command to change the project:
oc project <project_name>
$ oc project <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow where
<project_name>is the name of a project that you want to isolate from the managed services.Create a NetworkPolicy object:
-
Create a
deny-all.yamlfile. Define a policy in the file you just created, such as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the following command to create the policy object:
oc create -f <policy-name>.yaml -n <project>
$ oc create -f <policy-name>.yaml -n <project>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Create a