This topic describes how to smoothly migrate a self-built Kubernetes cluster to Alibaba Cloud Container Service for Kubernetes without affecting your business.

Procedure

  1. Create and configure a Container Service for Kubernetes cluster.

    Create a Container Service for Kubernetes cluster and allocate the required resources to the cluster. This simplifies the application migration. For more information, see Create a Kubernetes cluster.

    The following configurations are required for creating and configuring the Container Service for Kubernetes cluster:

    • Cluster template: Use one of the following templates to create the Container Service for Kubernetes cluster:
      • Dedicated Kubernetes cluster

        You must create and manage the master and worker nodes of the Kubernetes cluster. You have full control over the Kubernetes cluster. You are charged for the resources used by the master and worker nodes.

      • Managed Kubernetes cluster

        You only need to create and manage worker nodes. Container Service for Kubernetes creates and manages the master nodes for you. You are charged only for the resources used by the worker nodes.

    • Operating system: Select the operating system as required.
    • VPC: Configure the Virtual Private Cloud (VPC) and VSwitch.
    • SNAT: Configure source network address translation (SNAT) for the VPC.
    • Public access: Expose the API server with an elastic IP address (EIP).
    • CloudMonitor agent: Install the CloudMonitor agent on the Elastic Compute Service (ECS) instances of the Kubernetes cluster.
    • Log Service: Install and configure the Log Service agent in the Kubernetes cluster.
  2. Migrate data.
    • Migrate the database.
      1. Create an ApsaraDB for RDS database.
      2. Configure a whitelist to allow only specified IP addresses to access the ApsaraDB for RDS database.
      3. Configure the Alibaba Cloud DNS PrivateZone service.

        Use PrivateZone to resolve the domain name of the database to the IP address of the ApsaraDB for RDS database. In this way, you do not need to modify the database configuration on applications.

      4. Migrate the data in the MySQL database of the self-built Kubernetes cluster.

        Use Data Transmission Service (DTS) to migrate the data in the MySQL database to the ApsaraDB for RDS database in full, incremental, or two-way synchronization mode. For more information, see Migrate data from a user-created MySQL database to an ApsaraDB RDS for MySQL database.

    • Migrate storage data.
      1. Activate Object Storage Service (OSS).
      2. Create an OSS bucket.
      3. Migrate the storage data of the self-built Kubernetes cluster.

        Use the migration tool ossimport to migrate the data from a local server or a third-party cloud storage service such as Amazon S3, Microsoft Azure, or Tencent Cloud Object Storage to OSS. For more information, see Architectures and configurations.

    • Migrate images.
      1. Create a container image repository in Alibaba Cloud Container Registry.
      2. Set the credential for accessing Container Registry.
      3. Migrate the images of the self-built Kubernetes cluster.

        Use the image-syncer tool to migrate container images to Container Registry. For more information, see Use image-syncer to migrate container images.

  3. Migrate applications.

    Use the Velero tool to migrate applications and their configurations. For more information, see Migrate applications.

    1. Prepare the environment for migrating applications.
      1. Install the Velero client.
      2. Create an OSS bucket.
      3. Create a Resource Access Management (RAM) user and generate an AccessKey.
      4. Deploy the Velero server.
    2. Back up applications in the self-built Kubernetes cluster.
      • Back up applications without persistent volumes (PVs).
      • Back up applications with PVs.
    3. Restore applications in the Container Service for Kubernetes cluster.
      1. Create a StorageClass.
      2. Restore applications.
    4. Update the application configurations.
      • Update image URLs.
      • Optimize the method for exposing the applications.
      • Modify the configurations for attaching storage disks.
    5. Debug and start the applications.
  4. Perform regression testing.
    Perform regression testing on the Container Service for Kubernetes cluster without affecting the online business.
    1. Configure a testing domain.
    2. Test the features of the applications.
    3. Check the collected application logs.
    4. Check the monitoring data of the applications.
  5. Switch traffic.
    Modify the Domain Name System (DNS) configuration to switch traffic to the Container Service for Kubernetes cluster.
    1. Use the DNS service: Modify the DNS configuration to switch the traffic.
    2. Update clients: Modify the code or configuration on clients to switch the traffic.
  6. Bring the self-built Kubernetes cluster offline.
    Verify that the Container Service for Kubernetes cluster can be normally accessed. Then, bring the self-built Kubernetes cluster offline.
    1. Check whether the Container Service for Kubernetes cluster can receive and send traffic as expected.
    2. Bring the self-built Kubernetes cluster offline.
    3. Clear the backup files stored in the OSS bucket created when you migrate applications.