This article is shared from the HUAWEI CLOUD community "Argo CD Interconnects with CCE to Complete Service Deployment in Different Tests and Production Environments-Cloud Community-HUAWEI CLOUD".
1. Background note
- Argo CD is a declarative GitOps continuous delivery tool for Kubernetes that follows the GitOps pattern, which uses Git repositories as the source of truth to define the desired application state.
- Argo CD automatically deploys the desired application state in a specified target environment, and application deployments can track updates to branches, tags, or pinned to a specific version of the manifest at the time of Git commit.
- In this document, two CCE clusters (cce-test-cluster and cce-prod-cluster) are used to simulate the test and production environments, the gitlab repository is used as the application to deploy the yaml file storage repository, and the Argo CD is used to connect with different CCE clusters to complete the service deployment in the test and production environments.
2. Argo CD installation configuration
This section describes the basic deployment of Argo CD and the associated configurations in the following sections.
2.1 ArgoCD部署
Argo CD deployment can refer to https://github.com/argoproj/argo-cd/releases/tag/v2.9.3, the current new version is 2.9.3, and the deployment demonstration is conducted in a non-HA way.
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.9.3/manifests/install.yaml
Once the Argo CD is installed, it looks like this:
Change the serivce type of the argocd-server application to nodeport and use the IP+port of the node to access the Argo CD UI.
2.2 Argo CD Client Tool Usage
Argo CD provides a command-line tool that allows you to add clusters and change the login password through the command-line client.
wget https://github.com/argoproj/argo-cd/releases/download/v2.9.3/argocd-linux-amd64
cp argocd-linux-amd64 /usr/local/bin/argocd
chmod +x /usr/local/bin/argocd
To view the version information:
Log in to argo, the address is the argo address, the username is admin, and the password is obtained as follows:
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
The Argo CD web interface is logged in via https, login and initial password changes through the argocd client tool.
argocd login 192.168.1.137:31000 --username admin --password VQME4b7HSdl8REAu
Run the following command to change the password of the admin user:
argocd account update-password \ --current-password VQME4b7HSdl8REAu \ --new-password Aa123456
2.3 Argo CD添加多集群
Multi-cluster management is to connect different K8S clusters through Argo, and then deploy and manage services on each cluster. Obtain the config configuration information of the destination cluster, and obtain the name information of the destination cluster based on the config configuration information
Argo CD is deployed on the cce-test-prod cluster, and you can run the following command to view the cluster managed by argocd:
argocd cluster list
You can see that there is a default cluster, which is the cluster where argocd is deployed. In order to make it easier to distinguish between clusters, add the following clusters and set the names
argocd cluster add internal --kubeconfig /root/.kube/config --name cce-test-cluster
Add another CCE cluster to complete the configuration of argocd to connect to multiple clusters.
3. ArgoCD is associated with the yaml repository to complete the deployment of services in different environments
3.1 Argo CD login and configure the git repository
Log in to the argo CD interface with the username admin and password Aa123456
View the cluster information of an Argo CD connection:
Add git repository information to Settings:
This is to connect to the git repository via https
After the configuration is complete, make sure that the git repository is connected properly
The gitlab repository directory structure is as follows, and different environments are distinguished by folders:
3.2 Business Release
Create an app on the Applications page, fill in the application page, or select it, and deploy the service to the cce-test-cluster cluster.
Application Name: 自定义的应用名。
Project: Use the default project created by default.
SYNC POLICY: Synchronization mode, you can choose automatic or manual, here we choose manual synchronization.
Repository URL: The Git address of the project.
Revision: 分支名。
Path: yaml 资源文件所在的相对路径。
After the application is created, the application state is OutOfSync (when the running state of the deployed application deviates from the target state, argoCD will be treated as OutOfSync).
Click Sync to sync
After the deployment is successful, the application status is Healthy
查看cce-test-cluster集群应用部署情况:
用类似的配置方法部署应用到cce-prod-cluster集群:
查看cce-prod-cluster集群应用部署情况:
3.3 Deploy services across clusters
- The ApplicationSet controller is a Kubernetes controller that adds support for the ApplicationSet CustomResourceDefinition (CRD). This controller/CRD enables automation and greater flexibility in managing Argo CD applications across a large number of clusters and single nodes. Starting with Argo CD v2.3, Argo CD integrates the ApplicationSet controller.
- The ApplicationSet controller provides: the ability to target multiple Kubernetes clusters using a single Kubernetes manifest via the Argo CD; The ability to deploy multiple applications from one or more Git repositories using a single Kubernetes manifest via Argo CD.
- When you deploy an application on the UI, you can only select a single cluster, and you cannot deploy services in multiple clusters.
This section shows how to deploy the nginx application to two CCE clusters, and the yaml file is as follows:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: my-test
spec:
generators:
- list:
elements:
- cluster: cce-prod
url: https://192.168.1.112:5443
- cluster: cce-test
url: https://192.168.1.132:5443
template:
metadata:
name: '{{cluster}}'
spec:
project: default
source:
repoURL: http://192.168.1.218:32182/devops/argocd.git
targetRevision: main
path: '{{cluster}}'
destination:
server: '{{url}}'
namespace: default
该crd实现的结果就是从同一个git仓库中获取配置清单并部署到cce-test-cluster、cce-prod-cluster这两个集群,path和server中采用变量方式,分别获取list中对应的值。
Deploy the app:
argocd appset create app.yaml
Check the status of your app
argocd app list
Then you can synchronize the two apps, and after the synchronization is completed, the following operations are completed:
Follow #HUAWEI CLOUD Developer Alliance# Click below to learn about HUAWEI CLOUD's fresh technologies~
HUAWEI CLOUD Blog_Big Data Blog_AI Blog_Cloud Computing Blog_Developer Center-HUAWEI CLOUD