All Products
Search
Document Center

Container Service for Kubernetes:Enable an existing ACK cluster to access the Internet

Last Updated:Dec 20, 2023

If an Elastic Compute Service (ECS) instance or a Container Service for Kubernetes (ACK) cluster does not have a public IP address, you can create an SNAT entry in the virtual private cloud (VPC) where the ECS instance or ACK cluster is deployed to enable Internet access. If SNAT is disabled when you create a cluster, you can enable SNAT in the ACK console after the cluster is created. This topic describes how to enable SNAT for ACK clusters in the ACK console. SNAT allows ACK clusters to access the Internet.

Background information

You cannot call API operations to enable SNAT for existing clusters. For more information about SNAT, see What is NAT Gateway?

Procedure

The following figure shows the steps to enable SNAT for an existing ACK cluster to access the Internet.

创建SNAT

  1. Create a NAT gateway.

    1. Log on to the NAT Gateway console.

    2. In the left-side navigation pane, choose NAT Gateway > Internet NAT Gateway.

    3. On the Internet NAT Gateway page, click Create NAT Gateway.

      For more information about the NAT gateway parameters, see Create and manage Internet NAT gateways.

      Note

      The NAT gateway must be created in the region and VPC where your cluster resides.

    After you create the NAT gateway, a route is automatically added to the route table of the VPC where the NAT gateway is created. The destination CIDR block of the route is 0.0.0.0/0 and the next hop is the NAT gateway. This ensures that traffic is routed to the NAT gateway.

    Important

    By default, the route is automatically created for the first NAT gateway in a VPC. You must manually configure routes for other NAT gateways if multiple NAT gateways are created in the VPC. For more information, see Add and delete routes.

  2. Create an elastic IP address (EIP).

    In the left-side navigation pane, choose Access to Internet > Elastic IP Addresses. On the Elastic IP Addresses page, click Create EIP.

    If you already have an EIP, skip this step.

  3. Associate the EIP with the NAT gateway.

    1. On the Internet NAT Gateway page, find the NAT gateway that you created and choose 1 > Bind Elastic IP Address.

    2. In the Bind Elastic IP Address dialog box, select a resource group from the Resource Group drop-down list and select the EIP that you created from the Select Existing EIP drop-down list.

    3. Click OK.

  4. Create an SNAT entry for the NAT gateway.

    1. On the Internet NAT Gateway page, find your NAT gateway and click Manage.

    2. On the SNAT Management tab, click Create SNAT Entry.

    3. On the Create SNAT Entry page, configure the parameters and click Confirm.

      For more information about the parameters, see Create an SNAT entry.

      Parameter

      Description

      SNAT Entry

      Select Specify vSwitch and select the vSwitches that are used by the cluster.

      • If the cluster uses the Terway network plug-in, select the node vSwitches and pod vSwitches.

      • If the cluster uses the Flannel network plug-in, select the node vSwitches.

      If the cluster uses the Flannel or Terway network plug-in, perform the following steps to view the IDs of the node vSwitches.

      1. Log on to the ACK console.

      2. In the left-side navigation pane of the ACK console, click Clusters.

      3. On the Clusters page, find the cluster that you want to manage. Then, click the name of the cluster or click Details in the Actions column.

      4. In the left-side navigation pane of the cluster details page, choose Nodes > Node Pools.

      5. Find the node pool that you want to manage and click Details in the Actions column.

        On the Overview tab, view the IDs of the node vSwitches in the Node Configurations section.Flannel网络

      If the cluster uses the Terway network plug-in, perform the following steps to view the IDs of the pod vSwitches.

      1. Log on to the ACK console and click Clusters in the left-side navigation pane.

      2. On the Clusters page, click the name of the cluster that you want to manage and choose Configurations > ConfigMaps in the left-side navigation pane.

      3. On the top of the ConfigMap page, select kube-system for Namespace. Then, find and click the eni-config ConfigMap.

        On the eni-config page, you can view the pod vSwitch IDs in the vswitches field.

        Pod虚拟交换机ID

      Select Public IP Address

      Select one or more EIPs that you want to use to access the Internet.

    After the SNAT entry is created and SNAT rules are configured, SNAT is enabled for the cluster. You can log on to the NAT Gateway console to view the details of the NAT gateway, such as the EIPs used by SNAT. The following figure shows a NAT gateway that is created for an ACK cluster that uses the Terway network plug-in. SNAT rules are configured to enable the cluster to access the Internet.NAT

    Click the name of the NAT gateway. On the SNAT Management tab of the gateway details page, you can check whether public IP addresses are associated with the vSwitches used by the cluster. The following figure shows the SNAT entries that are created for the cluster that uses the Terway network plug-in.snat

Result

Log on to a node of the cluster and access the Internet to verify that the node can access the Internet and no packet loss occurs during data transmission.

SNAT 2