GitOps: Deploying the Tetris App on AKS with ArgoCD

Credits to Cloud Champ for the idea and the image of Tetris in Java. We will deploy a Tetris App to an Azure Kubernetes Services (AKS) cluster. Prerequisites: Deploy a basic AKS Cluster with Terraform. How to connect to the Azure Kubernetes

AI-assisted translation, approved by Mateo.

Credits to Cloud Champ for the idea and the image of Tetris in Java.

We will deploy a Tetris App to an Azure Kubernetes Services (AKS) cluster.

Prerequisites:

  • Deploy a basic AKS Cluster with Terraform.
  • How to connect to the Azure Kubernetes Services (AKS) CLI.
  • Deploy ArgoCD on AKS.

(I will be writing a post on each of these prerequisites soon :))

Linking a Git repository

Repository to use

In this case, we will use the repository https://github.com/mdiloreto/N4si-tetris-game.

Here we will find the manifest for deploying our App on AKS:

YAML
# tetris-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: tetris-deployment
spec:
replicas: 1 # You can adjust the number of replicas as needed
selector:
matchLabels:
app: tetris
template:
metadata:
labels:
app: tetris
spec:
containers:
- name: tetris
image: nasi101/tetris # Replace with the actual image tag
ports:
- containerPort: 80 # Replace with the port your Tetris game listens on
YAML
apiVersion: v1
kind: Service
metadata:
name: tetris-service
spec:
selector:
app: tetris
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer

Add Repository in ArgoCD

We must connect to ArgoCD through the public endpoint of our argocd-server service.

Open the following URL in the browser: https://20.124.172.62/

Now, in Argo, go to Settings>Repositories.

Click "+ Connect Repo"

Configure the options:

  • Method: via HTTPS.
  • Type: Git.
  • Project: in this case, it will be "Default".
  • Repository: https://github.com/mdiloreto/N4si-tetris-game/
  • Leave the rest of the options empty.
  • Finally, click "Connect"

If we complete the steps correctly, our repo will have the status "Successful":

Deploying the Application

Now, with our repository connected, we will deploy our app.

First, we will navigate to the "Applications" section in our ArgoCD console. Then we will click "+New App".

In this case, we will configure the basic general options:

  • Name: "tetris" (lowercase).
  • Project Name: "Default".
  • Sync policy: Automatic.

In Source, we will configure the repository configured in the previous step. In the path, we must specify the folder where our K8s manifests are located; in this case, it will be "manifests":

In the Destination options, we will configure our Default Cluster URL: https://kubernetes.default.svc

After configuring the specified parameters, we will click "Create". This will start the deployment of our application. In the "Applications" section, we can see the status:

After a moment, the App will be created in our AKS.

If we click this App, we can see the structure in detail:

Deployed application

After the successful deployment, we can see:

  • That a pod was created:
  • We can also see the creation of a deployment:
  • And the creation of a service:

When accessing the External-IP of "tetris-service" through a browser, we will find our application running:

Benefits of ArgoCD

ArgoCD is a popular Continuous Delivery tool for Kubernetes that has gained traction in the community due to a variety of features and benefits.

One of its main benefits is the simplification of GitOps.

ArgoCD uses a GitOps approach, where the desired state of an application is described in the Git repository. This allows synchronization and the management of history and changes through this medium. This sync can be manual or automatic.

Automatic state synchronization

In this case, we will test automatic synchronization by making 2 changes to the K8s manifest:

  • We will change the version of the Docker image.
  • We will change the number of replicas (pods) for this deployment.

Edit Manifest

Go to the GitHub repository and edit the tetris-deploy.yaml file.

Edit the image:

And edit the number of replicas:

Automatic change

As we mentioned previously, the automatic synchronization features allow ArgoCD to detect the change in our repo and update the status of our application:

We can verify that a new version of the App is running (keep browser cache in mind for testing):

In our AKS Cluster, we can detect 2 new pods for this app:

Thanks for reading. The learning continues in the next article.