This topic describes the methods that are used to access applications in a Container Service for Swarm cluster or Container Service for Kubernetes (ACK) cluster. The methods allow an application to access other applications within the same cluster or in other clusters.

Access applications within the same cluster

Container Service for Swarm cluster

To access a service within the same Container Service for Swarm cluster, you can use the links label to specify the name of the service as an environment variable.

For example, as described in YAML files used for creating applications, web services provided by a WordPress application are associated with a MySQL service. You can access the MySQL service by specifying its name mysql after the container is started.
links:            #---7
    - 'db:mysql'

ACK cluster

To access a service within the same ACK cluster, you can use the cluster IP or name of the service. We recommend that you use service names to access applications within the cluster.

When you create an application, you can specify the name of the service that you want to access as an environment variable.

For example, as described in YAML files used for creating applications, a WordPress application uses an environment variable to call a MySQL service.
spec:    
      containers:    
      - image: wordpress:4   
        name: wordpress
        env:    
        - name: WORDPRESS_DB_HOST
          value: wordpress-mysql    #---7 Specify the name of the MySQL service that you want to access. The name is mysql in this example.
        - name: WORDPRESS_DB_PASSWORD    

Access applications in other clusters

Access an application by using a domain name
Note
  • Ensure the network connectivity to the classic network or virtual private cloud (VPC).
  • The DNS server supports load balancing and can distribute traffic to different backend IP addresses.
  • Applications that are accessed through domain names can be migrated from Swarm to Kubernetes without service disruption.

Simple routing (use a domain name bound to the default SLB instance of a Container Service for Swarm cluster)

To migrate an application from a Container Service for Swarm cluster to an ACK cluster, you must first create an application in the ACK cluster. You must verify the functions of the application before you migrate the Swarm application to the ACK cluster.

Simple routing

Migration scheme

  • Perform the following operations to create an application in the ACK cluster:
    • In the ACK cluster, create an application of the same type as the application that you want to migrate from a Container Service for Swarm cluster.
    • Create a Loadbalancer service for the application in the ACK cluster.
    • The Loadbalancer service automatically creates a Server Load Balancer (SLB) instance. The IP address of the SLB instance is 2.2.2.2 in this example.
    • Modify DNS records to add the IP address 2.2.2.2 as a backend IP address for the domain name test.com.
  • Verify that the application in the ACK cluster is available

    The application is available when it is accessed through the IP address 2.2.2.2.

  • Switch traffic to the Kubernetes application

    Modify DNS records to remove the backend IP address 1.1.1.1 for the domain name test.com.

All traffic destined for the application in the Container Service for Swarm cluster is forwarded to the Kubernetes application through DNS.

Simple routing (use a domain name bound to a self-managed SLB instance of a Container Service for Swarm cluster)

You can bind a domain name to the default SLB instance or a self-managed SLB instance attached to a Container Service for Swarm cluster. The two methods differ in the following ways:
  • The SLB instances are different.
  • By default, Alibaba Cloud DNS is used. To use a custom domain name, you must manually resolve the domain name.

Migration scheme

The procedure is the same as the procedure to migrate an application from Swarm to Kubernetes by using the default SLB instance. You must create an application in the ACK cluster and verify the functions of the application before you switch all traffic to the Kubernetes application.

Migration scheme

Access through <HostIP>:<port>

If an application is accessed through <HostIP>:<port>, you cannot migrate the application from a Container Service for Swarm cluster to an ACK cluster without service disruption. We recommend that you migrate the application during off-peak hours.

Migration scheme
  1. Create an application in the ACK cluster and use a NodePort service to expose the application. For more information, see Configure port mapping.
  2. Record the NodePort and replace the <port> of the Container Service for Swarm cluster with the <NodePort> of the ACK cluster.
    Note To perform this step, you must stop and modify applications one after another.
  3. Attach worker nodes of the ACK cluster to the SLB instance that is attached to the Container Service for Swarm cluster.
  4. The SLB instance forwards a percentage of traffic to the Kubernetes application. After you verify the functions of this application, you can remove the nodes of the Container Service for Swarm cluster from the SLB instance. This switches all traffic to the Kubernetes application.

Access through an SLB instance

If an application is accessed through an SLB instance, you cannot migrate the application from a Container Service for Swarm cluster to an ACK cluster without service disruption. We recommend that you migrate the application during off-peak hours.

Migration scheme

You can use LoadBalancer services in the ACK cluster in the same way as you use SLB instances in the Container Service for Swarm cluster. For more information, see Configure Server Load Balancer.