You can use a Distributed Cloud Container Platform for Kubernetes (ACK One) Fleet instance to deploy an application across multiple clusters that are associated with the Fleet instance. To use the preceding method, you need to create Kubernetes resources, such as Deployments, Services, and Ingresses, for the application. Then, you need to specify the clusters in which you want to deploy the application and create the application. You can view the deployment progress of the application in each cluster. This topic describes how to use an ACK One Fleet instance to deploy an application across multiple clusters.
Prerequisites
The Fleet management feature is enabled. For more information, see Enable Fleet management.
Multiple clusters are associated with the Fleet instance. For more information, see Associate clusters with a Fleet instance.
The kubeconfig file of the Fleet instance is obtained in the ACK One console and a kubectl client is connected to the Fleet instance.
The AMC command-line tool is installed. For more information, see Use AMC.
Creates an application.
Run the following command to create a namespace.
Replace
<your-namespace>
with the name of the namespace that you want to create.kubectl create namespace <your-namespace>
Create a file named app-meta.yaml and add the following content to the file. The file defines the Kubernetes resources that are required for deploying an application.
apiVersion: apps/v1 kind: Deployment metadata: labels: app: demo name: demo namespace: demo spec: replicas: 1 selector: matchLabels: app: demo template: metadata: labels: app: demo spec: containers: - image: registry.cn-hangzhou.aliyuncs.com/acs/rollouts-demo:red name: demo --- apiVersion: v1 kind: Secret metadata: name: demo namespace: demo labels: app: demo type: Opaque data: version: MQ== --- apiVersion: v1 kind: ConfigMap metadata: name: demo-1 namespace: demo labels: app: demo data: version: "1" --- apiVersion: v1 kind: Service metadata: name: demo namespace: demo labels: app: demo spec: selector: app: demo ports: - protocol: TCP port: 80 targetPort: 8080 --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: demo namespace: demo labels: app: demo spec: rules: - host: app.demo.example.com http: paths: - path: / pathType: Prefix backend: service: name: demo port: number: 80
Run the following command to deploy an application named
demo
on the Fleet instance:kubectl apply -f app-meta.yaml
Create a file named app.yaml and add the following content to the file. The file defines a KubeVela application named demo.
Run the following command to query the clusters that are associated with the Fleet instance:
kubectl get managedclusters
Expected output:
NAME HUB ACCEPTED MANAGED CLUSTER URLS JOINED AVAILABLE AGE managedcluster-c5**** true True True 12d managedcluster-c1**** true True True 12d
Replace
<clusterid1>
and<clusterid2>
with the IDs of the clusters in which you want to deploy the application.apiVersion: core.oam.dev/v1beta1 kind: Application metadata: name: demo namespace: demo annotations: app.oam.dev/publishVersion: version1 spec: components: - name: demo type: ref-objects properties: objects: - apiVersion: apps/v1 kind: Deployment name: demo - apiVersion: v1 kind: ConfigMap selector: app: demo - apiVersion: v1 kind: Secret name: demo - apiVersion: v1 kind: Service name: demo - apiVersion: networking.k8s.io/v1 kind: Ingress name: demo policies: - type: topology name: beijing-clusters properties: clusters: ["<clusterid1>", "<clusterid2>"] # Specify the IDs of the clusters in which you want to deploy the application. You can add or remove cluster IDs on demand.
Parameter
Description
annotations. app.oam.dev/publishVersion
The version of the application. If an application or the Kubernetes resources that are used by an application are updated, you must change the value of this parameter to trigger the Fleet instance to synchronize the updates to the clusters.
components. type: ref-objects
The
apiVersion
,kind
, andname
parameters are used to reference Kubernetes resources in the same namespace. The Fleet instance deploys these resources in the specified clusters.ACK One supports the following Kubernetes resources:
Deployment/apps/v1
,Secret/v1
,ConfigMap/v1
, andIngress/networking.k8s.io/v1
.If you require other resources, submit a ticket to contact the ACK One team.
policies. type: topology
Set the type of the policy to topology. A topology policy specifies the destinations to which Kubernetes resources are deployed.
policies. properties. clusters
You can specify destinations only by cluster ID. Each destination can contain one or more clusters that are associated with the Fleet instance.
Run the following command to deploy the application
demo
on the Fleet instance:kubectl apply -f app.yaml
Run the following command to query the deployment progress of the application:
kubectl get app demo -n demo
Expected output:
NAME COMPONENT TYPE PHASE HEALTHY STATUS AGE demo demo ref-objects running true 24m
Query the deployment progress of the Kubernetes resources in each destination cluster.
kubectl get app demo -n demo -o yaml ...... status: appliedResources: - apiVersion: apps/v1 cluster: <clusterid1> creator: workflow kind: Deployment name: demo namespace: demo - apiVersion: v1 cluster: <clusterid1> creator: workflow kind: ConfigMap name: demo-1 namespace: demo - apiVersion: v1 cluster: <clusterid1> creator: workflow kind: Secret name: demo namespace: demo - apiVersion: networking.k8s.io/v1 cluster: <clusterid1> creator: workflow kind: Ingress name: demo namespace: demo - apiVersion: apps/v1 cluster: <clusterid2> creator: workflow kind: Deployment name: demo namespace: demo - apiVersion: v1 cluster: <clusterid2> creator: workflow kind: ConfigMap name: demo-1 namespace: demo - apiVersion: v1 cluster: <clusterid2> creator: workflow kind: Secret name: demo namespace: demo - apiVersion: networking.k8s.io/v1 cluster: <clusterid2> creator: workflow kind: Ingress name: demo namespace: demo
Run the following command to query the status of Kubernetes resources in the specified destination cluster:
Replace
<clusterid1>
with the ID of the destination cluster.kubectl amc get deployment demo -n demo -m <clusterid1>
Expected output:
Run on ManagedCluster <clusterid1> NAME READY UP-TO-DATE AVAILABLE AGE demo 1/1 1 1 28m
kubectl amc get pod -n demo -m <clusterid1>
Expected output:
Run on ManagedCluster <clusterid1> NAME READY STATUS RESTARTS AGE demo-7c96b5bffd-**** 1/1 Running 0 30m
Update the Kubernetes resources that are used by an application
To update the Kubernetes resources that are used by an application, perform the following steps:
Run the
kubectl apply
command to modify the Kubernetes resources that are deployed in Step 2.You can modify the Kubernetes resources based on your business requirements. For example, you can modify the OS image in a Deployment, the port of a Service, or the
Secret in a ConfigMap
. The updates are automatically synchronized to the destination clusters.Run the
kubectl apply
command to modify the Kubernetes resources that are deployed for the application demo in Step 4. You must change the value ofannotations: app.oam.dev/publishVersion: version1
to trigger the Fleet instance to deploy the updated Kubernetes resources in the destination clusters.For example, you can change the value of
app.oam.dev/publishVersion
toversion2
.Repeat Step 6, Step 7, and Step 8 to query the status of the application and resources.
Delete an application
Run the following command to delete an application. After you delete an application, the Kubernetes resources that are deployed in the destination clusters for the application are also deleted.
kubectl delete app demo -n demo