Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Host Security Service/ User Guide/ Container Protection/ Container Firewalls/ Configuring a Network Defense Policy (for a Cluster Using the Container Tunnel Network Model)

Configuring a Network Defense Policy (for a Cluster Using the Container Tunnel Network Model)

Updated on 2025-01-07 GMT+08:00

You can configure network defense policies to limit the access traffic to the pods in a cluster using the container tunnel network model. If no network policies are configured, all the inbound and outbound traffic of the pods in a namespace are allowed by default.

This section describes how to configure a network policy for a cluster using the container tunnel network model.

Constraints

  • Only clusters that use the tunnel network model support network policies. Network policies are classified into the following types:
    • Inbound rules, which are supported by all cluster versions.
    • Outbound rules, which are supported only by clusters in version 1.23 and later.
  • Network isolation is not supported for IPv6 addresses.

Creating a Network Defense Policy

You can create a network defense policy in various ways.

  1. Log in to the management console.
  2. In the upper left corner of the page, select a region, click , and choose Security & Compliance > HSS.
  3. In the navigation pane on the left, choose Container Protection > Container Firewalls.
  4. (Optional) If you have enabled the enterprise project, select the enterprise project where the target server resides from the drop-down list.
  5. Click Synchronize above the cluster list to synchronize the policies created on clusters.

    The synchronization takes about 1 to 2 minutes. Wait for a while and click in the upper right corner of the list to refresh and view the latest data.

    Figure 1 Synchronizing CCE Cluster policies

  6. Click Manage Policy in the Operation column of a cluster using the container tunnel network model.
  7. Click Create from YAML above the policy list.
  8. On the YAML creation page, enter content or click Import.

    An example of a network policy created from YAML is as follows:

    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: test-network-policy
      namespace: default
    spec:
      podSelector:                  # The rule takes effect for pods with the role=db label.
        matchLabels:
          role: db
      policyTypes:
        - Ingress
        - Egress
      ingress:                      # Ingress rule
        - from:
            - namespaceSelector: # Only namespaces with project=myproject can be accessed.
                matchLabels:
                  project: myproject
            - podSelector:              # Only the traffic from the pods with the role=frontend label is allowed.
                matchLabels:
                  role: frontend
          ports                       # Only TCP can be used to access port 6379.
            - protocol: TCP
              port: 6379
      egress:                         # Egress rule
        - to:
            - ipBlock:                #Only the 10.0.0.0/24 network segment of the destination object can be accessed.
                cidr: 10.0.0.0/24
          ports:                      # Only TCP can be used to access port 6379 of the destination object.
            - protocol: TCP
              port: 6379
    

  9. Click OK.
  1. Log in to the management console.
  2. In the upper left corner of the page, select a region, click , and choose Security & Compliance > HSS.
  3. In the navigation pane on the left, choose Container Protection > Container Firewalls.
  4. (Optional) If you have enabled the enterprise project, select the enterprise project where the target server resides from the drop-down list.
  5. Click Synchronize above the cluster list to synchronize the policies created on clusters.

    The synchronization takes about 1 to 2 minutes. Wait for a while and click in the upper right corner of the list to refresh and view the latest data.

    Figure 2 Synchronizing CCE Cluster policies

  6. Click Manage Policy in the Operation column of a cluster using the container tunnel network model.
  7. Click Create Network Policy above the network policy list.

    • Policy Name: Enter a network policy name.
    • Namespace: Select a namespace for the network policy.
    • Selector: Enter a key and a value to set the pod to be associated, and click Add. You can also click Reference Workload Label to reference the label of an existing workload. If this parameter is not specified, all pods in the namespace are associated by default.
    • Inbound rule: Click Add Rule in the Inbound Rules area. For more information, see Table 1.
      Table 1 Adding an inbound rule

      Parameter

      Description

      Protocol & Port

      Enter the inbound protocol type and port number of the pods to be associated. Currently, TCP and UDP are supported. If this parameter is not specified, all access traffic is allowed.

      Source Namespace

      Select a namespace whose objects can be accessed. If this parameter is not specified, access to the objects that belong to the same namespace as the current policy is allowed.

      Source Pod Label

      Select a label. Pods with this label can be accessed. If this parameter is not specified, all pods in the namespace can be accessed.

    • Outbound rule: Click Add Rule in the Outbound Rules area. For more information, see Table 2.
      Table 2 Adding an outbound rule

      Parameter

      Description

      Protocol & Port

      Enter the port and protocol of destination objects. If this parameter is not specified, access is not limited.

      Destination CIDR Block

      Configure CIDR blocks. This parameter allows requests to be routed to a specified CIDR block (and not to the exception CIDR blocks).

      Separate the destination and exception CIDR blocks by vertical bars (|), and separate multiple exception CIDR blocks by commas (,).

      For example, 172.17.0.0/16|172.17.1.0/24,172.17.2.0/24 indicates that 172.17.0.0/16 is accessible, but not for 172.17.1.0/24 or 172.17.2.0/24.

      Destination Namespace

      Namespace where the destination object is located. If not specified, the object belongs to the same namespace as the current policy.

      Destination Pod Label

      Select a label. Pods with this label can be accessed. If this parameter is not specified, all pods in the namespace can be accessed.

  1. Click OK.
  1. Log in to the management console.
  2. In the upper left corner of the page, select a region, click , and choose Security & Compliance > HSS.
  3. In the navigation pane on the left, choose Container Protection > Container Firewalls.
  4. (Optional) If you have enabled the enterprise project, select the enterprise project where the target server resides from the drop-down list.
  5. Click Synchronize above the cluster list to synchronize the policies created on clusters.

    The synchronization takes about 1 to 2 minutes. Wait for a while and click in the upper right corner of the list to refresh and view the latest data.

    Figure 1 Synchronizing CCE Cluster policies

  6. Click Manage Policy in the Operation column of a cluster using the container tunnel network model.
  7. Click Create from YAML above the policy list.
  8. On the YAML creation page, enter content or click Import.

    An example of a network policy created from YAML is as follows:

    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
      name: test-network-policy
      namespace: default
    spec:
      podSelector:                  # The rule takes effect for pods with the role=db label.
        matchLabels:
          role: db
      policyTypes:
        - Ingress
        - Egress
      ingress:                      # Ingress rule
        - from:
            - namespaceSelector: # Only namespaces with project=myproject can be accessed.
                matchLabels:
                  project: myproject
            - podSelector:              # Only the traffic from the pods with the role=frontend label is allowed.
                matchLabels:
                  role: frontend
          ports                       # Only TCP can be used to access port 6379.
            - protocol: TCP
              port: 6379
      egress:                         # Egress rule
        - to:
            - ipBlock:                #Only the 10.0.0.0/24 network segment of the destination object can be accessed.
                cidr: 10.0.0.0/24
          ports:                      # Only TCP can be used to access port 6379 of the destination object.
            - protocol: TCP
              port: 6379
    

  9. Click OK.
  1. Log in to the management console.
  2. In the upper left corner of the page, select a region, click , and choose Security & Compliance > HSS.
  3. In the navigation pane on the left, choose Container Protection > Container Firewalls.
  4. (Optional) If you have enabled the enterprise project, select the enterprise project where the target server resides from the drop-down list.
  5. Click Synchronize above the cluster list to synchronize the policies created on clusters.

    The synchronization takes about 1 to 2 minutes. Wait for a while and click in the upper right corner of the list to refresh and view the latest data.

    Figure 2 Synchronizing CCE Cluster policies

  6. Click Manage Policy in the Operation column of a cluster using the container tunnel network model.
  7. Click Create Network Policy above the network policy list.

    • Policy Name: Enter a network policy name.
    • Namespace: Select a namespace for the network policy.
    • Selector: Enter a key and a value to set the pod to be associated, and click Add. You can also click Reference Workload Label to reference the label of an existing workload. If this parameter is not specified, all pods in the namespace are associated by default.
    • Inbound rule: Click Add Rule in the Inbound Rules area. For more information, see Table 1.
      Table 1 Adding an inbound rule

      Parameter

      Description

      Protocol & Port

      Enter the inbound protocol type and port number of the pods to be associated. Currently, TCP and UDP are supported. If this parameter is not specified, all access traffic is allowed.

      Source Namespace

      Select a namespace whose objects can be accessed. If this parameter is not specified, access to the objects that belong to the same namespace as the current policy is allowed.

      Source Pod Label

      Select a label. Pods with this label can be accessed. If this parameter is not specified, all pods in the namespace can be accessed.

    • Outbound rule: Click Add Rule in the Outbound Rules area. For more information, see Table 2.
      Table 2 Adding an outbound rule

      Parameter

      Description

      Protocol & Port

      Enter the port and protocol of destination objects. If this parameter is not specified, access is not limited.

      Destination CIDR Block

      Configure CIDR blocks. This parameter allows requests to be routed to a specified CIDR block (and not to the exception CIDR blocks).

      Separate the destination and exception CIDR blocks by vertical bars (|), and separate multiple exception CIDR blocks by commas (,).

      For example, 172.17.0.0/16|172.17.1.0/24,172.17.2.0/24 indicates that 172.17.0.0/16 is accessible, but not for 172.17.1.0/24 or 172.17.2.0/24.

      Destination Namespace

      Namespace where the destination object is located. If not specified, the object belongs to the same namespace as the current policy.

      Destination Pod Label

      Select a label. Pods with this label can be accessed. If this parameter is not specified, all pods in the namespace can be accessed.

  1. Click OK.

Related Operations

Modifying or deleting a network policy

  1. Log in to the HSS console.
  2. In the navigation pane on the left, choose Container Protection > Container Firewalls.
  3. (Optional) If you have enabled the enterprise project, select the enterprise project where the target server resides from the drop-down list.
  4. Click Manage Policy in the Operation column of a cluster using the container tunnel network model.
  5. Click Synchronize above the network policy list.

    The synchronization takes about 1 to 2 minutes. Wait for a while and click in the upper right corner of the list to refresh and view the latest data.

  6. Manage policies as needed.

    • Modifying a policy
      • In the Operation column of a policy, click Edit YAML. On the YAML page, modify the YAML content and click OK.
      • In the Operation column of a policy, click Update. Modify the network policy information and click OK.
    • Deleting a policy
      • In the Operation column of a policy, click Delete. In the confirmation dialog box, click OK.
      • Select one or multiple policies and click Delete above the policy list. In the displayed dialog box, click OK.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback