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

NetworkAttachmentDefinition

Updated on 2024-01-04 GMT+08:00

Scenario

In a CCE Turbo cluster, you can configure subnets and security groups for containers by namespace using NetworkAttachmentDefinition, a CRD resource in the cluster. If you want to configure a specified container subnet and security group for a specified namespace, you can create a custom container NetworkAttachmentDefinition and associate the container network configuration with the corresponding namespace. In this way, service subnets can be planned or services can be securely isolated.

Constraints

  • Only the default-network supports container ENI prebinding. The creation speed of pods using the custom container network is slower than that of pods using the default-network. Therefore, this function is not suitable for ultra-fast pod scaling scenarios.
  • The default container network configuration default-network cannot be deleted.
  • To delete a NetworkAttachmentDefinition, delete pods (with the cni.yangtse.io/network-status annotation) created using the configuration in the corresponding namespace first. For details, see Deleting a Network Configuration.

Creating a NetworkAttachmentDefinition of the Namespace Type Using the CCE Console

  1. Log in to the CCE console.
  2. Click the cluster name to access the cluster console. Choose Settings in the navigation pane and click the Network tab.

    NOTE:

    If default-network exists in the cluster, it will take effect for all pods for which no custom network is configured. Default container subnet in the network configuration area on the Overview page is the container subnet in default-network.

  3. View Container Network Security Policy Configuration (Namespace Level). Click Adding a Container Network Security Policy. In the dialog box that is displayed, configure the container subnet and security group.

    • Name: Enter a name that contains a maximum of 253 characters. Do not use default-network, default, mgnt0, and mgnt1.
    • Namespace: Select the namespace to be associated. Namespaces associated with different container network configurations must be unique. If no namespace is available, click Create Namespace to create one.
    • Pod Subnet: Select a subnet. If no subnet is available, click Create Subnet to create a subnet. After the subnet is created, click the refresh button. A maximum of 20 subnets can be selected.
    • Associate Security Group: The default value is the container ENI security group. You can also click Create Security Group to create one. After the security group is created, click the refresh button. A maximum of five security groups can be selected.

  4. Click OK. After the creation is complete, you will be redirected to the network configuration list. You can see that the newly added subnet is in the list.

Creating a NetworkAttachmentDefinition of the Namespace Type Using Kubectl

This section describes how to create a NetworkAttachmentDefinition of the namespace type using kubectl.

  1. Use kubectl to connect to the cluster. For details, see Connecting to a Cluster Using kubectl.
  2. Modify the networkattachment-test.yaml file.

    vi networkattachment-test.yaml

    apiVersion: k8s.cni.cncf.io/v1
    kind: NetworkAttachmentDefinition
    metadata:
      annotations:
        yangtse.io/project-id: 05e38**
      name: example
      namespace: kube-system
    spec:
      config: 
      '{
        "type":"eni-neutron",
        "args":{
          "securityGroups":"41891**",
          "subnets":[
            {
              "subnetID":"27d95**"
            }
          ]
        },
        "selector":{
          "namespaceSelector":{
            "matchLabels":{
              "kubernetes.io/metadata.name":"default"
            }
          }
        }
      }'
    Table 1 Key parameters

    Parameter

    Mandatory

    Type

    Description

    apiVersion

    Yes

    String

    API version. The value is fixed at k8s.cni.cncf.io/v1.

    kind

    Yes

    String

    Type of the object to be created. The value is fixed at NetworkAttachmentDefinition.

    yangtse.io/project-id

    Yes

    String

    Project ID.

    name

    Yes

    String

    Configuration item name.

    namespace

    Yes

    String

    Namespace of the configuration resource. The value is fixed to kube-system.

    config

    Yes

    Table 2 object

    Configuration content, which is a string in JSON format.

    Table 2 config parameters

    Parameter

    Mandatory

    Type

    Description

    type

    Yes

    String

    The value is fixed at eni-neutron.

    args

    No

    Table 3

    object

    Configuration parameters.

    selector

    No

    Table 4 object

    Namespace on which the configuration takes effect.

    Table 3 args parameters

    Parameter

    Mandatory

    Type

    Description

    securityGroups

    No

    String

    Security group ID. If no security group is planned, ensure that the security group is the same as that in default-network.

    How to obtain:

    Log in to the VPC console. In the navigation pane, choose Access Control > Security Groups. Click the target security group name and copy the ID on the Summary tab page.

    subnets

    Yes

    Array of subnetID Objects

    List of container subnet IDs. At least one subnet ID must be entered. The format is as follows:

    [{"subnetID":"27d95**"},{"subnetID":"827bb**"},{"subnetID":"bdd6b**"}]

    Subnet ID not used by the cluster in the same VPC.

    How to obtain:

    Log in to the VPC console. In the navigation pane, choose Virtual Private Cloud > Subnets. Click the target subnet name and copy the Subnet ID on the Summary tab page.

    Table 4 selector parameters

    Parameter

    Mandatory

    Type

    Description

    namespaceSelector

    No

    matchLabels Object

    A Kubernetes standard selector. Enter the namespace label in the following format:

    "matchLabels":{
              "kubernetes.io/metadata.name":"default"
            }

    The namespaces of different configurations cannot overlap.

  3. Create a NetworkAttachmentDefinition.

    kubectl create -f networkattachment-test.yaml

    If information similar to the following is displayed, the NetworkAttachmentDefinition has been created.

    networkattachmentdefinition.k8s.cni.cncf.io/example created

Deleting a Network Configuration

You can delete the new network configuration or view its YAML file.

NOTE:

Before deleting a network configuration, delete the container corresponding to the configuration. Otherwise, the deletion fails.

  1. Run the following command to filter the pod that uses the configuration in the cluster (example is an example configuration name and you should replace it):
    kubectl get po -A -o=jsonpath="{.items[?(@.metadata.annotations.cni\.yangtse\.io/network-status=='[{\"name\":\"example\"}]')]['metadata.namespace', 'metadata.name']}"

    The command output contains the pod name and namespace associated with the configuration.

  2. Delete the owner of the pod. The owner may be a Deployment, StatefulSet, DaemonSet, or Job.

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