arrow

Use Argo CD To Deploy Applications In An ACK Cluster

1. Experiment

1.1 Knowledge points

Container Service for Kubernetes (ACK) is used in this experiment. This experiment describes how to use Argo CD to perform canary releases and blue-green releases.

Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes.

Argo CD is implemented as a Kubernetes controller. The controller continuously monitors running applications, and compares the current live state with the desired state specified in the Git repository. A deployed application whose live state deviates from the desired state is considered OutOfSync. Argo CD reports and visualizes the differences, and provides facilities to automatically or manually synchronize the live state back to the desired state. All modifications made to the desired state in the Git repository can be automatically applied and reflected in the specified environments.

1.2 Experiment process

  • Create a cluster
  • Log on to the cluster
  • Install Argo CD
  • Install Argo Rollouts
  • Perform a canary release
  • Perform a blue-green release

1.3 Scene architecture diagram

image desc

1.4 Cloud resources required

  • ECS
  • CS

1.5 Prerequisites

  • If you’re using your own Alibaba Cloud account instead of the account provided by this lab during the experiment, please note that you’ll need to choose the same Ubuntu 16.04 operating system for your ECS, in order to run the experiment smoothly.
  • Before starting the experiment, please confirm that the previous experiment has been closed normally and has been exited.

2. Start the experiment environment

Click Start Lab in the upper right corner of the page to start the experiment.

image desc.

After the experiment environment is successfully started, the system has deployed resources needed during the experiment in the background. For example, the ECS instance, RDS instance, Server Load Balancer instance, and OSS bucket. An account consisting of the username and password for logging on to the Web console of Alibaba Cloud is also provided.

image desc

After the experiment environment is started and related resources are properly deployed, the experiment starts a countdown. You have an hour to perform experimental operations. After the countdown ends, the experiment stops, and related resources are released. During the experiment, pay attention to the remaining time and arrange your time wisely. Next, use the username and password provided by the system to log on to the Web console of Alibaba Cloud and view related resources:

image desc

Go to the logon page of Alibaba Cloud console.

image desc

Fill in the sub-user account and click on Next.

image desc

Fill in the sub-user password and click on Login.

image desc

After successfully log on to the console, you will see the page showing as the following page.

image desc

3. Create a cluster

Refer to the following figure and select Container Service to enter the container service console.

image desc

Refer to the figure below to create a cluster first.

image desc

Select the Standard Managed Kubernetes.

image desc

Refer to the figure below, set the cluster name, select the US (Silicon Valley) area, and check the VPC network and switch to which it belongs. Click Next.

image desc

Start the worker node configuration.

Refer to the figure below and select the instance type of the Worker node.

image desc

The number of worker nodes is set to 3.

image desc

Set password, and click Next.

image desc

Refer to the following figure to set. Click Next.

image desc

Click Create Cluster.

image desc

It takes about 10 minutes to create a cluster. Please wait patiently.

image desc

image desc

4. Log on to the cluster

Click Elastic Computer Service, as shown in the following picture.

image desc

Copy this ECS instance’s Internet IP address and remotely log in to this ECS (Ubuntu system) instance. For more information about remote logon, see How to Remotely Log in to Alibaba Cloud’s ECS Server.

If multiple ECS instances are available in the ECS console, the cluster just created is creating ECS instances. Select the ECS instance with a public IP address to log on.

image desc

The default account name and password of the ECS instance:

Account name: root

Password: nkYHG890..

Run the following command to download the latest version of the kubectl client:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

image desc

Run the following commands to grant the execution permission to the downloaded client and move the client to the /usr/bin directory:

chmod +x kubectl
mv kubectl /usr/bin/

image desc

Run the following command to create a directory named .kube:

mkdir -p .kube

image desc

Log on to the Alibaba Cloud Container Service console, and choose Clusters > Clusters from the left-side navigation pane. On the Clusters page, click the cluster name.

image desc

On the Basic Information page, click Copy to copy the certification information of the Kubernetes cluster.

image desc

Return to the CLI and run the vim .kube/config command to create a config file. Copy the certificate information of the Kubernetes cluster you just created to the file. Save the file and exit.

image desc

Run the following command to view the node information:

kubectl get node

image desc

The command execution result shows that these nodes have been connected to the Kubernetes cluster.

5. Install Argo CD

Run the following command to install Argo CD:

kubectl create namespace argocd

kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

image desc

Run the following command to change the argocd-server service type to LoadBalancer:

kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'

image desc

Run the following command to query the IP address of the Argo CD server:

kubectl get svc -n argocd

image desc

Enter the IP address of the Argo CD server into the address bar of your browser and press Enter.If the access error is reported because the Argo CD server is still starting, please wait for 2~3 minutes

image desc

Run the following command to query the initial password:

kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d && echo ""

image desc

Enter the default username of the administrator account “admin” and the returned password.

image desc

If the following page appears, you have logged on to the Argo CD.

image desc

You can also log on by using the Argo CD client.

Return to the command prompt window and run the following command to install the Argo CD client:

curl -sSL -o /usr/bin/argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64

chmod +x /usr/bin/argocd

image desc

Replace YOUR-ARGO-CD-SERVER in the following command with the IP address of the Argo CD server and then run the command:

argocd login YOUR-ARGO-CD-SERVER

image desc

6. Install Argo Rollouts

Argo Rollouts is a Kubernetes controller and set of CRDs which provide advanced deployment capabilities such as blue-green, canary, canary analysis, experimentation, and progressive delivery features to Kubernetes.

Run the following command to install Argo Rollouts resource objects in the ACK cluster:

kubectl create namespace argo-rollouts

kubectl apply -n argo-rollouts -f https://github.com/argoproj/argo-rollouts/releases/latest/download/install.yaml

image desc

Run the following command to install the Argo Rollouts kubectl plug-in:

curl -LO https://github.com/argoproj/argo-rollouts/releases/latest/download/kubectl-argo-rollouts-linux-amd64

chmod +x kubectl-argo-rollouts-linux-amd64

mv kubectl-argo-rollouts-linux-amd64 /usr/bin/kubectl-argo-rollouts

image desc

Run the following command to verify that the installed version is up-to-date:

kubectl argo rollouts version

image desc

7. Perform a canary release

7.1 Deploy an application

Return to the Argo CD console and create an application named “labex-canary”, as shown in the following figure.

image desc

Specify the GitHub repository URL of the application and other information, as shown in the following figure. If you want to view the application configuration file in details, enter the following URL into the address bar of your browser and press Enter.

https://github.com/andi1991/argocd-example-apps

Set Path to “labex-canary”.

image desc

Specify Source and Destination, and then click Create.

image desc

Click SYNC after the application is created. Then, the system automatically creates resources in the ACK cluster based on the synchronized configuration file.

image desc

image desc

After the resources are deployed, click the application name to view resource details.

image desc

The page shows detailed information about the deployed resources.

image desc

7.2 Access the application

Log on to the ACK console and navigate to the cluster details page.

image desc

Click Update as shown in the following figure.

image desc

Modify the settings as shown in the following figure.

image desc

Click Refresh.

image desc

If the following page appears, it indicates that the application is deployed.

image desc

In the preceding figure, each block represents a simulated request sent to the backend Service. The answered requests are all in blue. This indicates that the backend Service is a “blue” version.

7.3 Perform a canary release

First we deploy a Rollout resource and a Kubernetes Service targeting that Rollout. The example Rollout in this guide utilizes a canary update strategy which sends 20% of traffic to the canary, followed by a manual promotion, and finally gradual automated traffic increases for the remainder of the upgrade. This behavior is described in the following portion of the Rollout spec:

spec:
  replicas: 5
  strategy:
    canary:
      steps:
      - setWeight: 20
      - pause: {}
      - setWeight: 40
      - pause: {duration: 10}
      - setWeight: 60
      - pause: {duration: 10}
      - setWeight: 80
      - pause: {duration: 10}

Return to the ECS command prompt window.

Run the following command to query the status of the “rollouts-demo” resource and monitor the progress of the further rollout:

kubectl argo rollouts get rollout rollouts-demo --watch

image desc

The output shows that the current image version is “blue” and five pods are in use.

Open another ECS command prompt window, and then name the first and second ECS command prompt windows “Command Prompt 1” and “Command Prompt 2”.

Run the following command in Command Prompt 2 to perform a canary release. The new version to be released is “yellow”.

kubectl argo rollouts set image rollouts-demo rollouts-demo=argoproj/rollouts-demo:yellow

image desc

Return to Command Prompt 1 and check the rollout progress.

During a rollout update, the controller will progress through the steps defined in the Rollout’s update strategy. The example rollout sets a 20% traffic weight to the canary, and pauses the rollout indefinitely until user action is taken to unpause/promote the rollout. After updating the image, watch the rollout again until it reaches the paused state:

image desc

When the demo rollout reaches the second step, we can see from the plugin that the Rollout is in a paused state, and now has 1 of 5 replicas running the new version of the pod template, and 4 of 5 replicas running the old version. This equates to the 20% canary weight as defined by the setWeight: 20 step.

Return to the Argo CD console. The page shows that 20% of the requests have turned to yellow.

image desc

The rollout is now in a paused state. When a Rollout reaches a pause step with no duration, it will remain in a paused state indefinitely until it is resumed/promoted.

Run the following command in Command Prompt 2 to start a promotion:

kubectl argo rollouts promote rollouts-demo

image desc

After promotion, Rollout will proceed to execute the remaining steps. The remaining rollout steps in our example are fully automated, so the Rollout will eventually complete steps until it has has fully transitioned to the new version.

Return to Command Prompt 1.

image desc

Return to the Argo CD console. The page shows that all of the requests have turned to yellow.

image desc

7.4 Abort and roll back

Run the following command in Command Prompt 2 to deploy a “red” version:

kubectl argo rollouts set image rollouts-demo rollouts-demo=argoproj/rollouts-demo:red

image desc

Return to Command Prompt 1.

image desc

This time, instead of promoting the rollout to the next step, we will abort the update, so that it falls back to the “stable” version. The plugin provides an abort command as a way to manually abort a rollout at any time during an update:

Run the following command in Command Prompt 2:

kubectl argo rollouts abort rollouts-demo

image desc

When a rollout is aborted, it will scale up the “stable” version of the ReplicaSet (in this case the yellow image), and scale down any other versions. Although the stable version of the ReplicaSet may be running and is healthy, the overall rollout is still considered Degraded, since the desired version (the red image) is not the version which is actually running.

image desc

Run the following command in Command Prompt 2 to roll back:

kubectl argo rollouts set image rollouts-demo rollouts-demo=argoproj/rollouts-demo:yellow

image desc

Return to Command Prompt 1. You should notice that the Rollout immediately becomes Healthy, and there is no activity with regards to new ReplicaSets becoming created.

image desc

8. Perform a blue-green release

8.1 Deploy an application

Return to the Argo CD console and create an application named “labex-bluegreen”, as shown in the following figure.

image desc

Specify the GitHub repository URL of the application, set Path to “labex-bluegreen”, and click Create, as shown in the following figure. If you want to view the detailed content of the application configuration file, enter the following URL into the address bar of your browser and press Enter:

https://github.com/andi1991/argocd-example-apps

image desc

Click SYNC.

image desc

Navigate to the application details page.

image desc

image desc

8.2 Perform a blue-green release

Return to the ACK console. The page shows that two Services named “rollout-bluegreen-active” and “rollout-bluegreen-preview” are deployed.

image desc

Click the external endpoints of the Services. Both results show that you are accessing the “blue” version of the application.

image desc

Run the following command in Command Prompt 1 to check the progress of the rollout:

kubectl argo rollouts get rollout rollout-bluegreen --watch

image desc

Run the following command in Command Prompt 2 to release the “green” version:

kubectl argo rollouts set image rollout-bluegreen rollouts-demo=argoproj/rollouts-demo:green

image desc

Return to Command Prompt 1. The output shows that the “green” version is ready and in the “preview” state.

image desc

Click the external endpoint of the “rollout-bluegreen-preview” Service.

image desc

The page shows the “green” version.

image desc

Click the external endpoint of the “rollout-bluegreen-active” Service.

image desc

The page shows the “blue” version.

image desc

This indicates that both versions are in use. However, the two versions use different endpoints.

The following procedure describes how to route all traffic to the “green” version after it passes the tests.

Run the following command in Command Prompt 2 to start a promotion:

kubectl argo rollouts promote rollout-bluegreen

image desc

Return to Command Prompt 1. The output shows that the “blue” version is gradually phased out.

image desc

image desc

The external endpoints of both the “rollout-bluegreen-active” and “rollout-bluegreen-preview” Services are updated to the endpoint of the “green” version.

image desc

8.3 Abort and roll back

The following procedure describes how to roll back to the earlier version when the new version encounters an error.

Run the following command in Command Prompt 2 to perform a blue-green release:

kubectl argo rollouts set image rollout-bluegreen rollouts-demo=argoproj/rollouts-demo:red

image desc

Return to Command Prompt 1. The output shows that the “red” version is in the “preview” state.

image desc

Click the external endpoint of the “rollout-bluegreen-preview” Service. The page shows that the “red” version is deployed.

image desc

Roll back when the new version encounters an error.

Run the following command in Command Prompt 2 to roll back:

kubectl argo rollouts abort rollout-bluegreen

image desc

Return to Command Prompt 1. The output shows that the new version is terminated.

image desc

Run the following command in Command Prompt 2 to roll back to the earlier version.

kubectl argo rollouts set image rollout-bluegreen rollouts-demo=argoproj/rollouts-demo:green

image desc

Return to Command Prompt 1. The output shows that the earlier version is restored.

image desc

Reminder:
Before you leave this lab, remember to log out your Alibaba RAM account before you click the ‘stop’ button of your lab. Otherwise you’ll encounter some issues when opening a new lab session in the same browser:

image descimage desc

9. Experiment summary

This experiment describes how to use Argo CD to perform canary releases and blue-green releases. In Argo CD, Application definitions, configurations, and environments can be declarative and version controlled. Application deployment and lifecycle management could be automated, auditable, and easy to understand.