Example project to demonstrate GitOps using Kustomize, GitHub Actions and ArgoCD
To implement this scenario, we will use Minikube as the Kubernetes cluster.
brew install minikube
minikube start
kubectl create ns hello-gitops
kubectl create ns argocd
minikube addons enable ingress
Refer to the official setup instructions for a detailed guide. To sum it up
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
ArgoCD can be interacted with using
If you want to install the CLI
brew tap argoproj/tap
brew install argoproj/tap/argocd
For this example, we will use the web UI. It can be made accessible using a port forward
kubectl port-forward svc/argocd-server -n argocd 8080:443
Check you have access to the web UI at http://localhost:8080 using your browser
adminkubectl get pods -n argocd -l app.kubernetes.io/name=argocd-server -o name | cut -d'/' -f 2You are of course encouraged to change this password
Login to your DockerHub account and create a new repository by clicking Create Repository

It's easier to make the repository public. If you want to use a private repository (like I did) you will need to allow your Minikube cluster to pull image from this repo by creating a secret. Procedure is explained later.
You will also need to generate a token for use by GitHub by going into your account settings then Security and clicking New Access Token

First, fork this repository by using the GitHub Fork button
Then clone your new forked repository
git clone https://github.com/<your-username>/hello-gitops.git
hello-gitops repository as upstreamcd hello-gitops
git remote add upstream https://github.com/esys/hello-gitops.git
git pull upstream master
You will need to expose your DockerHub credentials as GitHub secrets.
Settings then Secrets
DOCKER_USERNAME and DOCKER_PASSWORD (Docker password is the previously generated token for github on DockerHub).github/workflows/go.yml to check parameters and familiarize yourself with the workflow
Kustomize manifests are in the kustomize folder.
The kustomization.yaml is updated automatically by the GitHub workflow to add a new images transformation setting the right image name and tag.
images:
- name: hello-gitops
newTag: baadd7d7832f74e3c6d37b3f07b179d7e86c4017
newName: emmsys/hello-gitops
No need to touch these settings as they are updated by the workflow.
Edit kustomize/base/deployment.yaml to remove any reference to an imagePullSecrets
spec:
containers:
- image: hello-gitops
name: hello-gitops
ports:
- name: http
containerPort: 8080
Note: you can also make these changes with a Kustomize patch in a new overlay
You will need to create a DockerHub token to allow Minikube pulling this images
kubectl -n hello-gitops create secret docker-registry my-registry-creds --docker-server="https://index.docker.io/v1/" --docker-username="YOUR_USERNAME" --docker-password="YOUR_DOCKER_TOKEN" --docker-email="YOUR@EMAIL"
kustomize/base/deployment.yaml to reference this secret as an imagePullSecrets spec:
containers:
- image: hello-gitops
name: hello-gitops
ports:
- name: http
containerPort: 8080
imagePullSecrets:
- name: my-registry-creds
At this point, you should certainly have made code changes.
Commit and push them
git commit -am "customized settings"
git push origin master
At the end of the workflow, Kustomize manifests are referencing the newly built Docker image. We will configure ArgoCD to observe changes to Kustomize files and update the application in the K8s cluster.
HEAD or master revisionkustomize/base as the Path parameterhello-gitops as namespace
Sync button
Application is reachable on port 8080 inside the cluster. It displays a simple Hello World string with the hostname.
You can reach it through a port forward command
kubectl -n hello-gitops port-forward $(kubectl -n hello-gitops get po -o name) 8111:8080
curl localhost:8111
# Hello from hello-gitops-6f7d4878c9-qg4l6
Or by using the ingress controller
INGRESS_IP=`kubectl -n hello-gitops get ingress -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}'`
curl $INGRESS_IP
# Hello from hello-gitops-6f7d4878c9-qg4l6
Content type
Image
Digest
Size
6.4 MB
Last updated
almost 5 years ago
docker pull sumitroopchandani/hello-gitops