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

Private Network Access

The following two methods are available for private network access:
  • Workload Access Through a Service: Use this method when workloads in a namespace need to access each other.
  • Workload Access Through a Private Network Load Balancer: Use this method when a workload need to access other cloud resources (such as ECSs) in the same VPC. You can also use this method when you want workloads in the same VPC but different namespaces to access each other. The workload can be accessed using Private domain name or Load balancer's IP address:Port over HTTP/HTTPS and TCP/UDP. If other resources are in a VPC different from the current workload, you can also create a VPC peering connection to enable communication between VPCs.

Pod is the smallest resource unit in the workload. Accessing a workload is to access the pods in the workload. Pods in a workload can be dynamically created and destroyed, for example, during capacity scaling or rolling upgrade. In this case, the pod addresses will change, which makes it inconvenient to access pods.

To solve this problem, CCI provides the CoreDNS add-on (used for internal domain name resolution). Pod changes are managed by workloads and are not visible to users.

A workload can be accessed using Service name:Workload access port, where the access port is mapped to the container port. As shown in the following figure, if the pod in the frontend needs to access a pod in the backend, it only needs to access nginx:8080.

Figure 1 Workload access through the Service

Setting Service-based Workload Access When Creating a Workload

To enable a workload to be accessed through Service name:Workload access port, configure the following parameters when creating the workload:

  • Service Name: Specify the Service, which will be used to manage pod access. For details, see Service.
  • CoreDNS: Enable this option if you want to use the CoreDNS add-on. The CoreDNS add-on resolves internal domain names of workloads. If you do not install this add-on, the workload cannot be accessed through Service name:Workload access port.
  • Workload Port Settings:
    • Protocol: Specify the protocol that will be used to access the workload. Select TCP or UDP.
    • Workload Access Port: Specify the port for accessing the workload.
    • Container Port: Specify the port on which the container listens. The workload access port will be mapped to the container port.

Setting Service-based Workload Access After a Workload Is Created

You can configure Service-based access settings after a workload is created. The settings have no impact on the workload status and take effect immediately.

  1. Log in to the CCI console. In the navigation pane on the left, choose Network Management > Services. On the page displayed, click Create Service.
  2. On the Create Service page, select ClusterIP for Access Type.
  3. Set intra-cluster access parameters.

    • Service Name: Specify the Service, which will be used to manage pod access.
    • Namespace: Specify the namespace that the workload belongs to.
    • Workload: Select a workload that you want to add the Service for.
    • Port Settings:
      • Protocol: Specify the protocol that will be used to access the workload. Select TCP or UDP.
      • Access Port: Specify the port for accessing the workload.
      • Container Port: Specify the port on which the container listens. The workload access port will be mapped to the container port.

  4. Click Submit. The ClusterIP Service will be added for the workload.

Creating a Service Using kubectl

For details, see Service.

Workload Access Through a Private Network Load Balancer

If you want a workload to be accessed by other cloud resources or CCI workloads in other namespaces, bind a private network shared load balancer when you create the workload. In this way, the workload can be accessed over the private IP address of the load balancer.

When you configure access settings, select a private network load balancer and follow the description in Public Network Access to configure other parameters.

Figure 2 Setting ELB-based workload access when creating a workload

Setting Ingress-based Workload Access

You can configure ingress-based access settings after a workload is created. The settings have no impact on the workload status and take effect immediately.

  1. Log in to the CCI console. In the navigation pane on the left, choose Network Management > Ingresses. On the page displayed, click Create Ingress.
  2. Set ingress parameters.

    • Ingress Name: Enter a custom ingress name.
    • Namespace: Select the namespace to which you want to add the ingress.
    • Load Balancer: Specify a load balancer, which will automatically distribute Internet access traffic to multiple nodes running the workload.
    • External Port: Specify a port number that is open to the ELB service address.
    • External Protocol: HTTP and HTTPS are available. If you select HTTPS, choose a key certificate. For details about the certificate format, see Certificate and Private Key Format.
      • The key certificate ingress-test-secret.yaml is required only if you have selected HTTPS. For details on how to create a key, see Secrets.
      • If there is already an HTTPS ingress for the chosen port on the load balancer, the certificate of the new HTTPS ingress must be the same as the certificate of the existing ingress. This means that a listener has only one certificate. If two certificates, each with a different ingress, are added to the same listener of the same load balancer, only the certificate that was added first will take effect for the load balancer.
    • Ingress Rule
      • Domain Name: (Optional) Specify the domain name that will be used for access. Ensure that the domain name can be mapped to the IP address of the selected load balancer.
      • Rule Matching: Currently, only Prefix match is supported.

        Prefix match: Specify the prefix to be matched. If the mapping URL is /healthz, the URL that meets the prefix can be accessed. For example, /healthz/v1 and /healthz/v2.

      • URL: Specify the access path to be registered.
      • Service Name: Select the Service whose ingress you want to add.
      • Service Port: Specify the port on which the container in the container image listens.

  3. Click Submit.

    After the ingress is created, it is displayed in the ingress list.

Updating a Service

After you add a Service, you can update the port configuration of the Service.

  1. Log in to the CCI console. In the navigation pane on the left, choose Network Management > Services. On the Services page, select the corresponding namespace. In the row that contains the Service, click Update.
  2. Update intra-cluster access parameters.

    • Namespace: Specify the namespace that the workload belongs to. The value is inherited from the workload creation page and cannot be changed.
    • Workload: Specify the workload that you want to add a Service for. The value is inherited from the workload creation page and cannot be changed.
    • Service Name: Specify the Service, which will be used to manage pod access. The value is inherited from the workload creation page and cannot be changed.
    • Port Settings:
      • Protocol: Select a protocol used by the Service.
      • Container Port: Specify the port on which the workload listens. The Nginx workload listens on port 80.
      • Access Port: Specify the port mapped to the container port at the cluster-internal IP address. The workload can be accessed at <cluster-internal IP address>:<access port>. The port number range is 1–65535.

  3. Click Submit. The Service will be updated for the workload.

Updating an Ingress

After adding an ingress, you can update its port, domain name, and route configuration.

  1. Log in to the CCI console. In the navigation pane on the left, choose Network Management > Ingresses and then select the corresponding namespace. In the row that contains the ingress to be updated, click Update.
  2. On the Update Ingress page, set the following parameters:

    • External Port: Specify a port number that is open to the ELB service address.
    • Ingress Rule: You can click Add Ingress Rule to add a rule.
      • Domain Name: (Optional) Specify the domain name that will be used for access. You need to have registered a domain name. Ensure that the domain name can be mapped to the IP address of the selected load balancer. If you have configured a domain name rule, the domain name must always be used for access.
      • Rule Matching: Currently, only Prefix match is supported.

        Prefix match: Specify the prefix to be matched. If the mapping URL is /healthz, the URL that meets the prefix can be accessed. For example, /healthz/v1 and /healthz/v2.

      • URL: Specify the access path to be registered, for example, /healthz.
      • Service Name: Select the Service whose ingress you want to update.
      • Service Port: Specify the port on which the container in the container image listens.

  3. Click Submit. The ingress will be updated for the workload.