All Products
Search
Document Center

Container Service for Kubernetes:Manage multi-cluster services from the command line to enable cross-cluster access for Kubernetes services

Last Updated:Mar 26, 2026

Multi-cluster Services (MCS) lets pods in one ACK cluster access Services running in another cluster without creating a load balancer. You export a Service from the provider cluster using a ServiceExport resource, and the Fleet instance automatically synchronizes endpoint information to the consumer cluster. You then create a ServiceImport in the consumer cluster to make the exported Service accessible.

Prerequisites

Before you begin, ensure that you have:

How it works

Multi-cluster Services architecture
  1. The administrator deploys namespaces, Deployments, and Services in the provider cluster (ACK Cluster 1) and the consumer cluster (ACK Cluster 2), and creates MCS resources including a ServiceExport and a ServiceImport.

  2. The Fleet instance listens on the ServiceExport and ServiceImport in the associated ACK clusters, and synchronizes MCS endpoint information.

  3. Pods in ACK Cluster 2 can reach Service 1 in ACK Cluster 1.

Step 1: Set up the provider cluster

Skip this step if the Service and its resources already exist in ACK Cluster 1.

  1. Create a namespace in ACK Cluster 1:

    kubectl create ns provider-ns
  2. Create a file named app-meta.yaml with the following content:

    apiVersion: v1
    kind: Service
    metadata:
      name: service1
      namespace: provider-ns
    spec:
      ports:
      - name: http
        port: 80
        protocol: TCP
        targetPort: 8080
      selector:
        app: web-demo
      sessionAffinity: None
      type: ClusterIP
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: web-demo
      name: web-demo
      namespace: provider-ns
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: web-demo
      template:
        metadata:
          labels:
            app: web-demo
        spec:
          containers:
          - image: acr-multiple-clusters-registry.cn-hangzhou.cr.aliyuncs.com/ack-multiple-clusters/web-demo:0.4.0
            name: web-demo
            env:
            - name: ENV_NAME
              value: cluster1-beijing
  3. Apply the manifest to ACK Cluster 1:

    kubectl apply -f app-meta.yaml
  4. Create a file named service-export.yaml with the following content:

    apiVersion: multicluster.x-k8s.io/v1alpha1
    kind: ServiceExport
    metadata:
      name: service1         # Must match the name of the Service to export.
      namespace: provider-ns # Must match the namespace of the Service to export.
  5. Apply the ServiceExport in ACK Cluster 1:

    kubectl apply -f service-export.yaml

Step 2: Set up the consumer cluster

  1. Create the same namespace in ACK Cluster 2:

    kubectl create ns provider-ns
  2. Create a file named service-import.yaml with the following content:

    apiVersion: multicluster.x-k8s.io/v1alpha1
    kind: ServiceImport
    metadata:
      name: service1         # Must match the name of the exported Service.
      namespace: provider-ns # Must match the namespace of the exported Service.
    spec:
      ports:
      - name: http
        port: 80
        protocol: TCP
      type: ClusterSetIP

    The spec parameters are described in the following table:

    Parameter Description
    metadata.name The Service name. Must match the exported Service name.
    metadata.namespace The namespace. Must match the exported Service namespace.
    spec.ports.name The port name. Must match the exported Service.
    spec.ports.protocol The protocol. Must match the exported Service.
    spec.ports.appProtocol The application protocol. Must match the exported Service.
    spec.ports.port The port number. Must match the exported Service.
    spec.ips The virtual IP address. Set by the Fleet instance—leave this blank.
    spec.type Valid values: ClusterSetIP and Headless. Use Headless when the source Service has ClusterIP: None. Use ClusterSetIP in all other cases.
    spec.sessionAffinity Session affinity. Valid values: ClientIP and None. Must match the exported Service.
    spec.sessionAffinityConfig Session affinity configuration. Must match the exported Service.
  3. Apply the ServiceImport in ACK Cluster 2:

    kubectl apply -f service-import.yaml

Step 3: Access the Service across clusters

After the ServiceImport is created, the Fleet instance automatically creates a multi-cluster Service with the amcs- prefix in ACK Cluster 2. You can access Service 1 in ACK Cluster 1 using either the Service name or a domain name.

Method 1: Use the Service name

  1. Query Services in ACK Cluster 2 to confirm the amcs-service1 Service was created:

    kubectl get service -n provider-ns

    Expected output:

    NAME            TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
    amcs-service1   ClusterIP   172.xx.xx.xx   <none>        80/TCP    26m
  2. From a pod in ACK Cluster 2, run:

    curl amcs-service1.provider-ns

Method 2: Use a domain name

  1. Install or update CoreDNS in ACK Cluster 2. The version of CoreDNS must be 1.9.3 or later. For more information, see CoreDNS and Manage components.

  2. Open the CoreDNS ConfigMap for editing in ACK Cluster 2:

    kubectl edit configmap coredns -n kube-system
  3. In the Corefile field, add multicluster clusterset.local to enable domain name resolution for multi-cluster Services:

    apiVersion: v1
    data:
      Corefile: |
        .:53 {
            errors
            health {
               lameduck 15s
            }
            ready
            multicluster clusterset.local    # Add this line.
            kubernetes cluster.local in-addr.arpa ip6.arpa {
              pods verified
              ttl 30
              fallthrough in-addr.arpa ip6.arpa
            }
            ...
        }
    kind: ConfigMap
    metadata:
      name: coredns
      namespace: kube-system
  4. From a pod in ACK Cluster 2, run:

    curl service1.provider-ns.svc.clusterset.local
  5. (Optional) To use a shorter URL, add clusterset.local to the dnsConfig.searches field of the client pod:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: client-pod
      namespace: consumer-ns
    spec:
      ...
      template:
        ...
        spec:
          dnsPolicy: "ClusterFirst"
          dnsConfig:
            searches:
              - svc.clusterset.local
              - clusterset.local
              - consumer-ns.svc.cluster.local
              - svc.cluster.local
              - cluster.local
          containers:
          - name: client-pod
            ...

    After applying this configuration, you can use the shorter form:

    curl service1.provider-ns

What's next

You can also configure MCS in the ACK One console. See Use MCS in the ACK One console.

References