Setting up ArgoCD on Private Google Kubernetes Engine Cluster for GitOps Deployment

Merlin SahaMerlin Saha
3 min read

ArgoCD is a popular open-source tool for implementing GitOps principles and managing Kubernetes resources declaratively using Git as a single source of truth. In this blog post, we'll learn how to deploy ArgoCD on a private Google Kubernetes Engine (GKE) cluster and set up GitOps deployment using GitHub as the Git repository.

Prerequisites:

  • A Google Cloud Platform (GCP) account

  • gcloud command-line tool installed and authenticated

  • A GitHub account

  • A private Git repository for storing your Kubernetes manifests

Step 1: Create a GKE cluster Create a new private GKE cluster or use an existing one. Make sure to enable the necessary APIs and grant the required permissions for your GCP account.

# From jump host/autorised host
gcloud auth login
sudo apt-get install google-cloud-sdk-gke-gcloud-auth-plugin
gcloud compute start-iap-tunnel private-gke-jump-host 22 --local-host-port=localhost:<LOCAL_PORT> #you can use any open port or remove --local-host-port=localhost:49222 and let's use random port

ssh -J localhost:<LOCAL_PORT> 192.168.1.7

gcloud auth login
sudo apt-get install google-cloud-sdk-gke-gcloud-auth-plugin
gcloud container clusters get-credentials private-empmng-cluster --zone us-east4-c --project hand-on-lab-404211
gcloud config set run/region us-east4
gcloud auth configure-docker
kubectl get nodes

Step 2: Install ArgoCD Install ArgoCD on your GKE cluster using the official manifests

kubectl create namespace argocd

kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
kubectl -n argocd get pods -w
kubectl -n argocd get svc

Step 3: Expose ArgoCD API Server

The ArgoCD API server allow you to access the web UI.

kubectl patch svc argocd-server -n argocd --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"}]'
kubectl -n argocd get svc

Step 4: Access the ArgoCD Web UI

The ArgoCD web UI using the NodePort IP on localhost:8088 using port forwarding.

  • Retreive the cluster node to use securely:

      kubectl get nodes
    
  • Retrieve the initial admin password using the following command:

  •       kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath='{.data.password}' | base64 -d
    
  • Connect to the cluster node using IAP-tunnel, change <gke-private-cluster-node>, <argocd-node-port> (eg: 32347) and <cluster-location>

  •       gcloud compute start-iap-tunnel <gke-private-cluster-node> <argocd-node-port> --local-host-port=localhost:8088 --zone=<cluster-location>
    
  • Connect to ArgoCD Web UI using localhost:8088

Step 5: Configure ArgoCD with GitHub In the ArgoCD web UI, navigate to the "Settings" section, "Repositories" and connect ArgoCD to your GitHub account. You'll need to create a GitHub personal access token with the necessary permissions (repo, admin:repo_hook, read:user, user:email) and provide it to ArgoCD.

CONNECTION STATUS:

Step 6: Create an Application in ArgoCD

Create a new ArgoCD application and point it to your GitHub repository containing the Kubernetes manifests. Specify the repository URL, target revision (branch or tag), and the path to your manifests.

Navigate to the "Applications" section and click on "+ NEW APP".

  • GENERAL section

  • SOURCE section

  • DESTINATION section

Step 7: Sync and Deploy Once the application is created,

You can sync and deploy your Kubernetes resources to the GKE cluster. ArgoCD will continuously monitor the Git repository for changes and automatically sync the cluster with the desired state defined in the manifests.

Step 8: Verify the Deployment Verify that your Kubernetes resources are deployed correctly on the GKE cluster.

You can use the kubectl command or the GKE console to inspect the resources,

change <your-app-namespace>

kubectl get deployment -n <your-app-namespace>

Congratulations! You've successfully deployed ArgoCD on a private GKE cluster and set up GitOps deployment with GitHub. You can now leverage the power of GitOps to manage your Kubernetes resources in a declarative and version-controlled manner.

Note: This blog post provides a high-level overview of the steps involved. For more detailed instructions and troubleshooting, refer to the official ArgoCD documentation and GKE guides.

Youtube Demo Video: https://youtu.be/u7O1wqbChK0?t=729

0
Subscribe to my newsletter

Read articles from Merlin Saha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Merlin Saha
Merlin Saha

"Unlocking Cloud Potential: A Journey of Innovation and Expertise" Welcome to my corner of the digital realm, where the convergence of cutting-edge technology and business innovation unfolds.