Create helm repository

First, create a basic Helm template repository:

1
helm create template .

For actual deployment, you need to customize your own helm template according to your business. I will directly use our internal custom universal template for quick deployment; you can also refer to the helm chart maintained by bitnami (https://github.com/bitnami/charts/tree/master/bitnami)

Jenkins credential configuration argocd token information

argocd and jenkins

Configure Jenkins pipeline writing

Here we take the gotest project (https://code.test.cn/hqliang/gotest) as an example

1
2
3
4
5
pipeline {
environment {
GOPROXY = "http://repo.test.cn/repository/goproxy/"
HUB_URL = "registry.test.cn" ARGOCD_SERVER="qacd.test.cn" ARGOCD_PROJ="test-project" ARGOCD_APP="gotest" ARGOCD_REPO="https://code.test.cn/devops/cicd/qa.git" ARGOCD_PATH="devops/gotest" ARGOCD_CLUSTER="https://172.16.19.250:8443" ARGOCD_NS ="default" } agent { node { label 'aiops' } } stages { stage ('Docker_Build') { steps { withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '12ff2942-972c-4df3-8d2d-2cfcb25e00de', usernameVariable: 'DOCKER_HUB_USER', passwordVariable: 'DOCKER_HUB_PASSWORD']]) { sh ''' TAG=$(git describe --tags `git rev-list --tags --max-count=1`) docker login registry.test.cn -u ${DOCKER_HUB_USER} -p ${DOCKER_HUB_PASSWORD} make docker-all VERSION=$TAG ''' } } } stage ('Deploy_K8S') { steps { withCredentials([string(credentialsId: "qa-argocd", variable: 'ARGOCD_AUTH_TOKEN')]) { sh ''' TAG=$(git describe --tags `git rev-list --tags --max-count=1`) # create app ARGOCD_SERVER=$ARGOCD_SERVER argocd --grpc-web app create $ARGOCD_APP --project $ARGOCD_PROJ --repo $ARGOCD_REPO --path $ARGOCD_PATH --dest-namespace $ARGOCD_NS --dest-server $ARGOCD_CLUSTER --upsert --insecure # deploy app ARGOCD_SERVER=$ARGOCD_SERVER argocd --grpc-web app set $ARGOCD_APP -p containers.tag=$TAG --insecure # Deploy to ArgoCD ARGOCD_SERVER=$ARGOCD_SERVER argocd --grpc-web app sync $ARGOCD_APP --force --insecure ARGOCD_SERVER=$ARGOCD_SERVER argocd --grpc-web app wait $ARGOCD_APP --timeout 600 --insecure ''' } } }
}

Configure gitlab webhook to trigger Jenkins

Jenkins configuration to trigger build

argocd and jenkins

gitlab configuration webhook

argocd and jenkins

Push tag to remote branch

argocd and jenkins

Jenkins pipeline build

Go to Jenkins to view the pipeline build results as follows:

Docker automatically packages and pushes to harbor

argocd and jenkins

Create the Argo application and deploy it to the k8s cluster argocd and jenkins

Finally, check the synchronization status. It shows that it has been published to the k8s cluster normally: argocd and jenkins

Let’s go to the argocd dashboard to see the application flow chart. The various components of the application are running normally. argocd and jenkins

Use kubectl to obtain the created resources:

argocd and jenkins

Finally, verify whether the business is accessible. Visit http://gotest.test.cn/df to view the container disk space

argocd and jenkins

Summary & Optimization

Whether through the jenkins pipeline or through gitlab CI, we can better integrate argocd and finally achieve one-click deployment of business applications.