Getting started with Argo CD and Argo Rollout
This article is a guide to Argo CD installation, application setup with Argo, and using Argo Rollout to do canary deployment. It is all done on Linux. There is a bonus section on Argo and CD pipeline at the end. Keep reading!
Argo CD section
- Install Argo CD with UI
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
2. Install Argo CD cli
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
rm argocd-linux-amd64
3. Open the Argo CD to external access, so that we can access the UI
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'
4. Login to Argo CD using the cli
argocd admin initial-password
if the command above does not work, use the command below to get the initial password.
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
Then, login to Argo CD server. The <ARGOCD_SERVER> is the external IP gotten from “kubectl get svc -n argocd”. The username is admin.
argocd login <ARGOCD_SERVER>
If you want, you can change the initial password by calling:
argocd account update-password
5. Register a cluster to deploy Apps
kubectl config get-contexts -o name
you will get something like:
arn:aws:eks:ap-southeast-1:<aws_account_id>:cluster/<cluster_name>
copy the whole thing as cluster to the command below
argocd cluster add <cluster>
6. Create an application from a github repo using ArgoCD cli
Set the current namespace to argocd
kubectl config set-context --current --namespace=argocd
As practice, use example guestbook application with Argo CD
argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace default
The repo https://github.com/argoproj/argocd-example-apps.git contains k8s deployment and service yaml files.
Bonus:
Create an application from a gitlab repo with helm chart
Firstly, you need to authenticate the gitlab repo with Argo CD
argocd repo add https://gitlab.com/mypath/reponame.git --username <gitlab_username> --password <gitlab_passwd>
Then, you use the same command as adding github repo. In the path argument, specify the path helmchart that contains the helm files.
argocd app create helm-app --repo https://gitlab.com/mypath/reponame.git --path helmchart --dest-server https://kubernetes.default.svc --dest-namespace default
7. Use Argo CD web UI to add new app
On browser, enter the url <ARGOCD_SERVER>:80
Click on the new app button:
Add the necessary info to it:
8. Sync the app via Argo CD cli
To sync the web app
argocd app sync guestbook
To see the status of web app
argocd app get guestbook
Finally, you can see the web app is synced up on the Argo CD UI.
Argo Rollout section
We can use kubectl with Argo rollout. This section shows the Argo rollout steps.
- Download the Argo rollout kubectl plugin
curl -LO https://github.com/argoproj/argo-rollouts/releases/latest/download/kubectl-argo-rollouts-linux-amd64
2. Make it executable
chmod +x kubectl-argo-rollouts-linux-amd64
3. Move the binary file to executable path
sudo mv ./kubectl-argo-rollouts-linux-amd64 /usr/local/bin/kubectl-argo-rollouts
4. Confirm that it works
kubectl argo rollouts version
5. Deploy Agro rollout with kubectl
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/docs/getting-started/basic/rollout.yaml
The link https://raw.githubusercontent.com/argoproj/argo-rollouts/master/docs/getting-started/basic/rollout.yaml contains rollout custom resource definition (CRD). The content of the yaml is shown below.
We create the service that references the rollout.
kubectl apply -f https://raw.githubusercontent.com/argoproj/argo-rollouts/master/docs/getting-started/basic/service.yaml
6. Update the rollout
The command below creates a canary deployment, according to spec.strategy.canary in the above rollout yaml file.
kubectl argo rollouts set image rollouts-demo \
rollouts-demo=argoproj/rollouts-demo:yellow
7. Promote the rollout
Basically it means we continue with the canary deployment
kubectl argo rollouts promote rollouts-demo
8. Observe the status of the rollout
kubectl argo rollouts get rollout rollouts-demo — watch
Argo CD works together with Argo Rollout. Argo CD monitors the changes in git repo, and creates a new rollout object. Agro Rollout watches for changes in rollout object, and try to apply new version and apply new version with selected strategy (eg. canary, blue/green).
Argo with CD pipeline
This bonus section describes the interplay between Argo and CD pipeline.
- Create k8s deployment and service yaml file (or helm chart files) for the application, add the application to Argo CD
- The CD pipeline will build and push docker image to gcr/ecr/dockerhub when new PR is merged
- The CD pipeline will update the k8s deployment yaml file with new docker image version (or you can update the k8s deployment file manually).
- Argo CD will re-deploy the k8s deployment upon observing changes in the k8s deployment yaml file.
(argocd app set guestbook --sync-policy automated
)
The end.
Feel free to browse this link: