Service Mesh (ASM) integrates with Karmada (Kubernetes Armada) to deploy and run cloud-native applications across multiple Kubernetes clusters without requiring application changes. Karmada provides plug-and-play automation for multi-cluster application management in cloud-native scenarios, with key features like centralized multi-cloud management, high availability, fault recovery, and traffic scheduling. This topic demonstrates how to use ASM and Karmada for multi-cluster application management.
Background information
Karmada uses Kubernetes-native APIs to define federated resource templates, allowing for easy integration with existing Kubernetes tools. Karmada also provides a standalone PropagationPolicy API to define multi-cluster scheduling requirements.
-
It supports a 1:N policy mapping mechanism, so you do not need to specify scheduling constraints every time you create a federated application.
-
When using default policies, you can interact directly with the Kubernetes API.
Cluster modes
Karmada can manage member clusters in two modes: push and pull. The main difference between the push and pull modes is how member clusters are accessed when manifests are deployed.
Push mode
The Karmada control plane directly accesses the kube-apiserver of a member cluster to get the cluster status and deploy manifests.
Pull mode
The Karmada control plane does not directly access member clusters. Instead, it delegates requests to an agent component named karmada-agent.
Each karmada-agent serves a single cluster and has the following responsibilities:
-
Registers the cluster with Karmada (creates a
Clusterobject). -
Maintains and reports the cluster status to Karmada (updates the status of the
Clusterobject). -
Watches for manifests from the Karmada execution space (a namespace in the format
karmada-es-<cluster name>) and applies them to the cluster it serves.
Key components
The Karmada control plane includes the following components:
-
Karmada API Server
-
Karmada Controller Manager
-
Karmada Scheduler
etcd stores the Karmada API objects. The API Server provides the REST endpoint for all other components. The Karmada Controller Manager acts on the API objects that you create through the API server.
Prerequisites
-
You have two ACK clusters (named
member1andmember2in this example) in the same virtual private cloud (VPC). For more information, see Create an ACK managed cluster.Note-
This topic uses two clusters in the same VPC as an example. If your clusters are in different VPCs, you must configure network connectivity between the VPCs.
-
We recommend using an enterprise security group when creating the clusters.
-
-
You have created an ASM instance (named
mesh1in this example) and configured a sidecar injection policy for thedefaultnamespace. For more information, see Create an ASM instance and Configure a sidecar injection policy. -
You have deployed a Karmada primary cluster instance (named
karmada-masterin this example) and added the two ACK clusters (member1andmember2) as member clusters. For more information, see Karmada Installation. -
You have added the two clusters to the ASM instance (
mesh1) and created a serverless ingress gateway. For more information, see Add clusters to an ASM instance and create a serverless ingress gateway.
Step 1: Deploy applications with Karmada
This topic uses the Bookinfo sample application, similar to the process described in Use an ASM serverless gateway for multi-cluster ingress. However, instead of manually deploying different reviews versions to separate clusters, this topic shows how to achieve the same result by creating a Karmada PropagationPolicy in the karmada-master cluster.
-
Create a file named
bookinfo-karmada.yamlwith the following content. -
Run the following command to deploy the Bookinfo application in the Karmada primary cluster:
kubectl --kubeconfig /etc/karmada/karmada-apiserver.config apply -f bookinfo-karmada.yamlNoteBy default, the kubeconfig file for the Karmada primary cluster is saved to
/etc/karmada/karmada-apiserver.config. If you chose a different installation path, replace the path after--kubeconfigwith the correct path. -
Create a file named
propagation.yamlwith the following content.apiVersion: policy.karmada.io/v1alpha1 kind: PropagationPolicy metadata: name: service-propagation spec: resourceSelectors: - apiVersion: v1 kind: Service name: productpage - apiVersion: v1 kind: Service name: details - apiVersion: v1 kind: Service name: reviews - apiVersion: v1 kind: Service name: ratings placement: clusterAffinity: clusterNames: - member1 - member2 --- apiVersion: policy.karmada.io/v1alpha1 kind: PropagationPolicy metadata: name: produtpage-propagation spec: resourceSelectors: - apiVersion: apps/v1 kind: Deployment name: productpage-v1 - apiVersion: v1 kind: ServiceAccount name: bookinfo-productpage placement: clusterAffinity: clusterNames: - member1 --- apiVersion: policy.karmada.io/v1alpha1 kind: PropagationPolicy metadata: name: details-propagation spec: resourceSelectors: - apiVersion: apps/v1 kind: Deployment name: details-v1 - apiVersion: v1 kind: ServiceAccount name: bookinfo-details placement: clusterAffinity: clusterNames: - member2 --- apiVersion: policy.karmada.io/v1alpha1 kind: PropagationPolicy metadata: name: reviews-propagation spec: resourceSelectors: - apiVersion: apps/v1 kind: Deployment name: reviews-v1 - apiVersion: apps/v1 kind: Deployment name: reviews-v2 - apiVersion: apps/v1 kind: Deployment name: reviews-v3 - apiVersion: v1 kind: ServiceAccount name: bookinfo-reviews placement: clusterAffinity: clusterNames: - member1 - member2 --- apiVersion: policy.karmada.io/v1alpha1 kind: PropagationPolicy metadata: name: ratings-propagation spec: resourceSelectors: - apiVersion: apps/v1 kind: Deployment name: ratings-v1 - apiVersion: v1 kind: ServiceAccount name: bookinfo-ratings placement: clusterAffinity: exclude: - member1The
.spec.placement.clusterAffinityfield in a PropagationPolicy defines scheduling constraints for a specific cluster. Without these constraints, any cluster can be a scheduling candidate.You can configure the following four fields:
Parameter
Description
labelSelector
A filter to select member clusters by their labels. If this field is not empty, only clusters that match the filter are selected.
fieldSelector
A filter to select member clusters by their fields. If this field is not empty, only clusters that match the filter are selected.
clusterNames
A list of cluster names to explicitly include in the selection.
exclude
A list of cluster names to explicitly exclude from the selection.
This example uses only the
clusterNamesandexcludefields. For more information about the.spec.placement.clusterAffinityfield, see Resource Propagating in the Karmada documentation. -
Run the following command to deploy the PropagationPolicy:
kubectl --kubeconfig /etc/karmada/karmada-apiserver.config apply -f propagation.yaml -
Use the kubeconfig files for the
member1andmember2clusters to view the Deployments in each cluster.-
member1
kubectl --kubeconfig member1 get deploymentExpected output:
NAME READY UP-TO-DATE AVAILABLE AGE productpage-v1 1/1 1 1 12m reviews-v1 1/1 1 1 12m reviews-v2 1/1 1 1 12m reviews-v3 1/1 1 1 12m -
member2
kubectl --kubeconfig member2 get deploymentExpected output:
NAME READY UP-TO-DATE AVAILABLE AGE details-v1 1/1 1 1 16m ratings-v1 1/1 1 1 16m reviews-v1 1/1 1 1 16m reviews-v2 1/1 1 1 16m reviews-v3 1/1 1 1 16m
-
Step 2: Add virtual service and gateway
-
In the
defaultnamespace, create a virtual service namedbookinfowith the following content. For more information, see Manage virtual services.apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: bookinfo spec: hosts: - "*" gateways: - bookinfo-gateway http: - match: - uri: exact: /productpage - uri: prefix: /static - uri: exact: /login - uri: exact: /logout - uri: prefix: /api/v1/products route: - destination: host: productpage port: number: 9080 -
In the
defaultnamespace, create a gateway namedbookinfo-gatewaywith the following content. For more information, see Manage gateways.apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: bookinfo-gateway spec: selector: istio: ingressgateway # use istio default controller servers: - port: number: 80 name: http protocol: HTTP hosts: - "*"
Step 3: Verify access
-
Obtain the IP address of the ingress gateway. For more information, see Obtain the IP address of an ingress gateway.
-
In your browser, enter
http://{IP_address_of_the_serverless_ingress_gateway}/productpageand refresh the page multiple times. The page cycles through the three versions of thereviewsservice, with traffic distributed roughly evenly. Althoughreviews-v3is in a different cluster than some of the other services, it works as expected.The
reviews-v3page shows red stars in the "Book Reviews" section and displaysReviews served by: reviews-v3-xxxat the bottom, indicating the current service version.The
reviews-v2page shows black stars in the "Book Reviews" section and displaysReviews served by: reviews-v2-xxxat the bottom.The
reviews-v1page shows only review text with no star ratings and displays the service instance, such asreviews-v1-586d96b89c-6v5p8, at the bottom.