このコンテンツは選択した言語では利用できません。

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-project option of the oc command

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

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

  1. Log in to the cluster using the oc login command.
  2. Use the following command to change the project:

    $ oc project <project_name>
    Copy to Clipboard

    where <project_name> is the name of a project that you want to accept communications from other projects.

  3. Create a NetworkPolicy object:

    1. Create a allow-from-middleware-namespaces.yaml file.
    2. Define a policy in the file you just created, such as in the following example:

      apiVersion: networking.k8s.io/v1
      kind: NetworkPolicy
      metadata:
        name: allow-from-middleware-namespaces
      spec:
        podSelector:
        ingress:
          - from:
              - namespaceSelector:
                  matchLabels:
                    integreatly-middleware-service: 'true'
      Copy to Clipboard
    3. Run the following command to create the policy object:

      $ oc create -f allow-from-middleware-namespaces.yaml -n <project>
      
      networkpolicy "allow-from-middleware-namespaces" created
      Copy to Clipboard

2.2. Enabling communication between managed services and projects

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

  1. Log in to the cluster using the oc login command.
  2. Use the following command to change the project:

    $ oc project <project_name>
    Copy to Clipboard

    where <project_name> is the name of a project that you want to accept communications from other projects.

  3. Create a NetworkPolicy object:

    1. Create a NetworkPolicy.yaml file.
    2. 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:

      kind: NetworkPolicy
      apiVersion: networking.k8s.io/v1
      metadata:
        name: allow-all
      spec:
        podSelector:
        ingress:
        - {}
      Copy to Clipboard
      Note

      This policy configuration enables this project to communicate with all projects in the cluster.

    3. Run the following command to create the policy object:

      $ oc create -f <policy-name>.yaml -n <project>
      Copy to Clipboard

2.3. Enabling communication between customer applications

You can enable communication between user applications.

Prerequisites

  • You have installed the OpenShift command-line interface (CLI), commonly known as oc.

Procedure

  1. Log in to the cluster using the oc login command.
  2. Use the following command to change the project:

    $ oc project <project_name>
    Copy to Clipboard

    <project_name> is the name of a project that you want to accept communications from.

  3. Create a NetworkPolicy object:

    1. Create a allow-from-myproject-namespace.yaml file.
    2. 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):

      apiVersion: networking.k8s.io/v1
      kind: NetworkPolicy
      metadata:
        name: allow-from-myproject-namespace
      spec:
        podSelector:
        ingress:
          - from:
              - namespaceSelector:
                   matchLabels:
                     project: myproject
      Copy to Clipboard
  4. Run the following commands to create the policy object:

    $ oc create -f allow-from-myproject-namespace.yaml -n <project>
    networkpolicy "allow-from-myproject-namespace" created
    Copy to Clipboard

2.4. Disabling communication from a managed service to a project

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

  1. Log in to the cluster using the oc login command.
  2. Use the following command to change the project:

    $ oc project <project_name>
    Copy to Clipboard

    where <project_name> is the name of a project that you want to isolate from the managed services.

  3. Create a NetworkPolicy object:

    1. Create a deny-all.yaml file.
    2. Define a policy in the file you just created, such as in the following example:

      kind: NetworkPolicy
      apiVersion: networking.k8s.io/v1
      metadata:
        name: deny-all
      spec:
        podSelector: {}
        ingress:
          - from:
              - namespaceSelector:
                  matchLabels:
                    integreatly-middleware-service: 'true'
      Copy to Clipboard
    3. Run the following command to create the policy object:

      $ oc create -f <policy-name>.yaml -n <project>
      Copy to Clipboard
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat