Help Center/ Cloud Container Engine/ Best Practices/ Networking/ Accessing an External Network from a Pod/ Accessing Cloud Services from a Pod in a Different VPC
Updated on 2024-12-28 GMT+08:00

Accessing Cloud Services from a Pod in a Different VPC

Pods cannot communicate with each other across VPCs. To resolve this issue, you can use VPC peering to connect two VPCs so that pods in one VPC can access services in the other VPC. The method of setting up cross-VPC connectivity varies depending on the clusters' network types. For details, see Table 1. In this section, the VPC where the cluster is in is referred to as the cluster VPC, the VPC where the cloud service to be accessed is in is referred to as the destination VPC, and the subnet where the cloud service to be accessed is in is referred to as the destination subnet.

Table 1 Cross-VPC access for clusters of different network types

Network Model

Description

Difference

Tunnel network

Data packets are encapsulated through tunnels in the node network.

To access cloud services from a pod in a different VPC, ensure that the node subnet can communicate with the destination subnet.

After creating a VPC peering connection between the cluster VPC and the destination VPC, you only need to create a route for the node subnet and the destination subnet.

VPC network

Pod traffic is forwarded through VPC routing. The VPC CIDR block of the cluster cannot overlap with the container CIDR block.

When accessing services from a pod in a different VPC, ensure that the node subnet can communicate with the destination subnet and that the container CIDR block can also communicate with the destination subnet.

After creating a VPC peering connection between the cluster VPC and the destination VPC, you need to create a route for the destination subnet, cluster node subnet, and container CIDR block.

Cloud Native Network 2.0

In the Cloud Native 2.0 network model, container IP addresses are directly assigned from the VPC CIDR block.

To access cloud services from a pod in a different VPC, ensure that the container subnet can communicate with the destination subnet.

After creating a VPC peering connection between the cluster VPC and the destination VPC, you only need to create a route for the container subnet and the destination subnet.

Cloud services that communicate with CCE include ECS, ELB, RDS, DCS, Kafka, RabbitMQ, ModelArts, and DDS. To ensure successful communication, make sure your network is configured correctly and verify that the cloud service you want to access allows external access. For example, accessing DCS Redis requires being trustlisted. If you cannot configure the trustlist on the service console, create a service ticket in the target service.

This section uses ECS and RDS for MySQL as examples to describe how to implement cross-VPC communication between pods in clusters that use different network models. Table 2 shows the details about the cluster, ECS, and RDS for MySQL network information in the example.

Table 2 Network information

Cloud Service

Container Network Model

Network Information

CCE

Container tunnel network (CCE standard cluster)

  • Cluster VPC
    • Name: vpc-demo1
    • CIDR block: 192.168.0.0/18 (primary) and 172.1.0.0/24 (secondary)
      NOTE:

      After a VPC is created, if the primary CIDR block is not enough, you can add secondary CIDR blocks to the VPC. For details, see Adding a Secondary IPv4 CIDR Block to a VPC. After a secondary CIDR block is added to the VPC, you can create a subnet based on the secondary CIDR block. The subnet can be used in CCE.

    • Subnet: 192.168.0.0/24, 192.168.60.0/28, and 172.1.0.0/26
  • Node subnet: 192.168.0.0/24
  • Container CIDR block: 172.18.1.0/24

VPC network (CCE standard cluster)

  • Cluster VPC
    • Name: vpc-demo1
    • CIDR block: 192.168.0.0/18 (primary) and 172.1.0.0/24 (secondary)
    • Subnet: 192.168.0.0/24, 192.168.60.0/28, and 172.1.0.0/26
  • Node subnet: 192.168.0.0/24
  • Container CIDR block: 172.18.1.0/24

Cloud Native 2.0 network (CCE Turbo cluster)

  • Cluster VPC
    • Name: vpc-demo1
    • CIDR block: 192.168.0.0/18 (primary) and 172.1.0.0/24 (secondary)
    • Subnet: 192.168.0.0/24, 192.168.60.0/28, and 172.1.0.0/26
  • Node subnet: 192.168.0.0/24
  • Container subnet: 192.168.60.0/28

ECS

N/A

  • Destination VPC
    • Name: vpc-demo2
    • CIDR block: 10.1.0.0/16
    • Subnet: 10.1.1.0/24
  • Subnet where the ECS resides (destination subnet): 10.1.1.0/24
  • ECS IP address: 10.1.1.24

RDS for MySQL

N/A

  • Destination VPC
    • Name: vpc-373896-1
    • CIDR block: 172.16.0.0/16
    • Subnet: 172.16.0.0/24
  • Subnet where RDS for MySQL resides (destination subnet): 172.16.0.0/24
  • IP address of RDS for MySQL: 172.16.0.167

Prerequisites

Accessing Cloud Services from a Pod in a Different VPC

This part describes how to access an ECS or an RDS for MySQL DB instance from a pod in a different VPC.

The following describes how to access an ECS from pods that run in clusters that use the tunnel network model, VPC network model, and Cloud Native 2.0 network model, respectively. You can select a method based on your cluster types.

The following describes how to access an RDS for MySQL DB instance from pods that run in clusters that use the tunnel network model, VPC network model, and Cloud Native 2.0 network model, respectively. You can select a method based on your cluster types.

Troubleshooting a Pod Access Failure

If a pod cannot access the network, rectify the fault by referring to Table 15. If the fault persists, submit a service ticket to contact Huawei Cloud customer service.

The CIDR blocks used for pod access depend on the cluster network model. For details, see Table 1. The container CIDR blocks mentioned in the following section are specific to a cluster that uses the VPC network model.

Table 15 Troubleshooting methods

Check Item

Possible Fault

Solution

Security group rules of the accessed service

One of the following issues may be the cause of the failure:

  • The security group's inbound rules prevent access to the node CIDR block or container CIDR block.
  • The security group's inbound rules permit access to the node CIDR block and container CIDR block, but the protocol is incorrectly configured.
    NOTICE:

    Run the ping command and use ICMP to test network connectivity. Before doing so, enable the ICMP port in the security group rule.

VPC peering connection

The CIDR blocks of the local and peer VPCs are overlapping.

There are two possible causes for this issue. For details, see Overlapping CIDR Blocks of Local and Peer VPCs.

  • If the subnet where the node CIDR block resides does not overlap with the subnet where the accessed service resides, you can create a VPC peering connection that points to the subnet.
  • If the subnet where the node CIDR block resides overlaps with the subnet where the accessed service resides, you need to replan the network.

Route

One of the following issues may be the cause of the failure:

  • The custom route table used to add routes for the two VPCs is not associated with the destination subnet. (The cluster VPC route table must be associated with the node subnet, and the route table of the accessed service must be associated with the subnet where the accessed service is located.)
  • There is no route between the accessed service subnet and the container CIDR block.
  • For possible cause 1, locate the target route table, click Associate Subnet, and select the correct subnet.
  • For problem 2, add a route for the destination service subnet and the container CIDR block.

Trustlist

The trustlist for the accessed service does not have the node CIDR block and container CIDR block configured.

Add the container and node CIDR blocks to the trustlist. Find more information in the help document for the relevant service.

Domain name resolution

When accessing an external domain name, the pod uses its cluster's domain name resolution to resolve the destination address and accesses the address based on the pod's network policy. However, sometimes the domain name cannot be resolved, resulting in errors. The most common errors are listed below:

  • Name or service not known
  • Temporary failure in name resolution
  • Unable to resolve hostname
  • DNS resolution failed
  • Could not resolve MYHOST (nodename nor servname known), where MYHOST indicates the domain name that cannot be resolved

Locate the cause of the DNS exception. For details, see DNS Overview for troubleshooting.

Network policy (applicable only to tunnel networks)

If you have configured a network policy for both your tunnel network cluster and the namespace where the pod is located, the network policy may prevent the pod from accessing the destination address.

If so, modify the network policy. For details, see Configuring Network Policies to Restrict Pod Access.