This is a basic example showing the use of docker compose to run applications locally and how to deploy applications to a remote server using GitOps, ie a docker host using 🚢Dockhand and a kubernetes cluster using 🐙ArgoCD.
To get started fork this repo and replace the domain andrewlee.cloud with your own domain.
Dockerinstalled locallyDomainrecords pointing to the servers' IP address
Dockhandhost hasTraefikconfigured to listen for container labels on the networkproxyand acertresolvercalledletsencrypt.ArgoCDhost hasTraefikingress controller andCert-Managerinstalled.
To start the whoami-example on your local machine run:
docker compose -f ./docker/compose.yaml -f ./docker/compose.local.yaml upThis will merge the two files and expose the port 8888 on localhost.
To stop the whoami-example use Ctrl+C and run:
docker compose -f ./docker/compose.yaml -f ./docker/compose.local.yaml downDockhand is a modern, powerful Docker management platform with a focus on simplicity and ease of use. It allows you to manage and monitor Docker infrastructure from a single interface. With Git integration, you can easily deploy applications from Git repositories.
Go to Settings > Git. To deploy the whoami-example to Dockhand first add a deploy key in GitHub then add it to Dockhand credentials. SSH keys and GitHub Tokens are supported.
Add the repo to Dockhand using the correct branch and url. SSH keys url looks like git@github.com:andrewthomaslee/whoami-example.git. GitHub Tokens url looks like https://github.com/andrewthomaslee/whoami-example.git.
Go to Stacks > From Git. Select the repo you just added and the branch you want to deploy and the path to the compose.yaml file. Toggle Deploy Now and click Deploy.
The compose.yaml file is merged with the compose.override.yaml file to generate the production deployment.
Once deployed you can view the logs and the application by clicking the Inspect Container button.
When changes are made to the compose.yaml files the application will automatically be refreshed on a timer if enabled. To manually sync the changes use the Sync from Git button.
ArgoCD is a declarative, GitOps continuous delivery tool for Kubernetes. It follows the GitOps pattern of using Git repositories as the source of truth for defining the desired state of the application.
Go to Settings > Connect Repo. Add the deploy key from GitHub to the whoami-example repo. SSH keys and GitHub Tokens are supported.
Enusre the credentials are added successfully and can connect to the repo.
Go to Applications > New App. Fill in the details for how the application will be deployed.
Fill in the details for the source and destination.
Press Create and the application will be deployed.
Once created you can view the application in the Applications tab.
Click the application tile to view the application's created objects.
This application's manifest has 4 objects:
Issuer: issues TLS certificatesDeployment: runs the whoami containerService: exposes the deployment to the clusterIngress: comsumes TLS certificate and exposes the service to the internet
The Deployment object creates a ReplicaSet and Pod.
The Ingress object creates a Certificate and Secret.
In the repo's kubernetes/whoami.yaml file use Ctrl+F to search for 8888 and replace it with 8080 and push the changes. This simply changes the port the application listens on. In the ArgoCD wait for the sync to happen automatically or press the Refresh button to sync the changes.
The old Pod will be terminated once the new Pod is deployed.
Since a change was made to the Deployment object a new ReplicaSet will be created.
To rollback to the previous version of the Deployment object use the History and Rollback button.
Rolling back will use the old ReplicaSet and take the application off auto-sync and will require a manual sync to be triggered to re-enable auto-sync.
To delete the application use the Delete button. This will delete all the objects created by the application.
This tutorial demonstrated how to use the GitOps pattern to deploy applications to a docker host and a kubernetes cluster! Congratulations on making it this far! 🎉


















