This repository contains a simple application that uses ArgoCD to deploy its Tekton pipeline to Docker Desktop. It uses Tekton to build an image and publish it to the Container Registry after a developer commits changes to the application. And it executes an ArgoCD sync to deploy the application.
The sample application is created following this tutorial simulating how a new user might learn to containerize a Node Application.
-
To run the application locally, Install Docker Desktop.
-
We can run the application locally if we have node installed
cd awesome-application/
npm install
node server.js
- Since we have the code, docker build with a tag
docker build -t <your username>/demo .
- Run the application in a container.
docker run -p 49162:8082 -d <your username>/demo
- Check that the container is running.
docker ps
- Test the Application
curl -i localhost:49162
To complete this tutorial, we need:
Install ArgoCD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Download ArgoCD CLI
brew install argocd
Change the argocd-server service type to LoadBalancer:
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'
Kubectl port-forwarding can also be used to connect to the API server without exposing the service.
kubectl port-forward svc/argocd-server -n argocd 8090:443
The API server can then be accessed using the http://localhost:8090
Login Using the CLI, using the username admin
and the password from below:
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
Change the password using the command:
argocd login localhost:8090
argocd account update-password
Register a cluster docker-desktop
to deploy apps to
argocd cluster add docker-desktop
kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml
kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/interceptors.yaml
kubectl apply --filename https://storage.googleapis.com/tekton-releases/dashboard/latest/tekton-dashboard-release.yaml
The Dashboard can be accessed through its ClusterIP Service by running kubectl proxy. Assuming tekton-pipelines
is the installed namespace for the Dashboard, run the following command:
kubectl proxy
Browse http://localhost:8001/api/v1/namespaces/tekton-pipelines/services/tekton-dashboard:http/proxy/ to access your Dashboard.
kubectl create namespace demo
After Tekton builds the application and pushes the container image into the Image Repository, Tekton needs to trigger a new Deployment. There is a special task that allows Tekton to trigger a ArgoCD sync. We have to install the Argo CD Tekton Task for that.
kubectl apply -n demo -f https://raw.githubusercontent.com/tektoncd/catalog/main/task/argocd-task-sync-and-wait/0.1/argocd-task-sync-and-wait.yaml
There is a file called argocdsecret.template
which contains
argocd-env-configmap
:ConfigMap
withARGOCD_SERVER
used for server addressargocd-env-secret
:Secret
withARGOCD_USER
andARGOCD_PASSWORD
used for authentication
Create a copy of that file as yaml.
cd pipeline/
cp argocdsecret.template argocdsecret.yaml
In the newly created file, replace the value for ARGOCD_SERVER
(localhost:8090
) with the ArgoCD server,
ARGOCD_USERNAME
with the username and ARGOCD_PASSWORD
with the Base 64 encoded password.
There is a file called serviceaccount.template
which contains
dockerhub-user-pass
:Secret
with${DOCKER_USERNAME}
and${DOCKER_PASSWORD}
used for authenticationdemo-app-builder
:ServiceAccount
using the secretdockerhub-user-pass
Create a copy of that file as yaml.
cd pipeline/
cp serviceaccount.template serviceaccount.yaml
In the newly created file, replace the value for DOCKER_USERNAME
and DOCKER_PASSWORD
with your docker credentials.
-
pipeline-resources.yaml: Pipeline Resources are configured for the pipeline. We will create two resources (
git
andimage
), which will need the name of the git repository, and the name of the Container Image using the Docker Hub. Note, the resources here allow us to run a Pipeline from the Tekton Dashboard or CLI. It hard codes default values. They will be overridden by Trigger Template when builds are done via a git push. -
pipeline.yaml: Our Pipeline for building, publishing, and deploying our application. There are two Tasks. We make use of the shared tasks rather than creating our own. Tasks:
- the
build-and-publish-image
uses Kaniko to build an image. - the
argocd-sync-deployment
uses the ArgoCD task we installed earlier.
- the
-
triggertemplate.yaml: Now that the pipeline is setup, there are several resources created in this file. This file creates the needed resources for triggering builds from an external source, in our case a Git webhook. We can learn more about Tekton Triggers here. We have created the following.
-
A TriggerTemplate is used to create a template of the same pipeline resources, but dynamically generated to not hard code image name or source. It also creates a PipelineRun Template that will be created when a build is triggered.
-
A TriggerBinding that binds the incoming event data to the template (this will populate things like git repo name, revision, etc)
-
An EventListener that will create a pod application bringing together a binding and a template.
-
We can use ArgoCD to deploy the Tekton build for the application.
argocd app create demo-app-build --repo https://github.com/pritidesai/awesome-application --path pipeline --dest-name docker-desktop --dest-namespace demo
Once you run sync, your pipeline should be deployed, and your screen in ArgoCD should look like below.
argocd app sync demo-app-build
kubectl get eventlistener -n demo
NAME ADDRESS AVAILABLE REASON READY REASON
demo-el http://el-demo-el.demo.svc.cluster.local:8080 True MinimumReplicasAvailable
kubectl port-forward svc/el-demo-el -n demo 8080
-
deployment.yaml - This represents our Kubernetes Deployment.
-
service.yaml: This expose the sample application to the cluster.
Just like we used ArgoCD to deploy the tekton
pipeline, we will create another ArgoCD app that corresponds to the
deployment.
argocd app create demo-app-deploy --repo https://github.com/pritidesai/awesome-application --path deployment --dest-name docker-desktop --dest-namespace demo