Skip to content

A mini project to play around with a few technologies.

License

Notifications You must be signed in to change notification settings

FaisalAl-Rayes/go-k8-argocd

Repository files navigation

You can connect with me through LinkedIn using the link the following link: LinkedIn

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. Contact
  6. Acknowledgments

About The Project

This is a project to share my approach to building a basic go website using multiple technologies that can be seen in the Built With section. The motivation behind this project is to display the learning process of new technologies involved in building this project as well as its CI/CD pipeline. The successful functional end result should be as displayed here if you follow the Functional Run:

go-app-results-page

However if you are just interested in the serving of the webapp in the kubernetes cluster you should follow the Basic Run which would make the successful end result looking like:

go-app-landing-page

(back to top)

Built With

  • Go
  • Docker
  • Kubernetes
  • Github
  • ArgoCD

(back to top)

Getting Started

Here are the sequential steps to get the project up and running!

Prerequisites

  • Ensure that you have docker installed on your machine. To install docker please follow the instructions of installation on the Docker Official Website according to your operating system.

  • Ensure that docker is installed correctly by typing the following command in your shell and getting a response that looks like this

    ~$ docker --version
    Docker version XX.XX.XX ...

    At the time of initiating the project version 24.0.2 of Docker was used.

  • Ensure that you have minikube installed on your machine to simulate a kubernetes cluster locally. To install minikube please follow the instructions of installation on the Minikube Offical Installation Page according to your operating system.

  • Ensure that minikube is installed correctly by typing the following command in your shell and getting a response that looks like this

    ~$ minikube version
    minikube version: vX.XX.X
    commit: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    At the time of initiating the project version 1.30.1 of Minikube was used.

  • OPTIONAL: Install ArgoCD CLI to try and get familiar with controlling the ArgoCD pipeline from the terminal. Use the instructions on the ArgoCD Installation Page. You can check if the installation was successful by running the follwing command in your shell and getting a response that looks like this

    ~$ argocd version
      argocd: vX.X.X+XXXXXXX
          BuildDate: XXXX-XX-XXXXX:XX:XXX
          GitCommit: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
          GitTreeState: XXXXX
          GoVersion: goX.XX.XX
          Compiler: XX
          Platform: XXXXXXX/XXXXX
      argocd-server: vX.X.X+XXXXXXX.XXXXX

    At the time of initiating the project version 2.7.7 of argocd cli was used.

Installation

  1. Using Minikube with Docker as the driver, start a kubernetes cluster with 3 worker nodes running kubernetes version 1.27.3 by running the following command

    ~$ minikube start --driver=docker --kubernetes-version v1.27.3 --nodes 3

    This process might take some time if it is the first start up of minikube.

  2. Install ArgoCD in the kubernetes cluster by running the following commands

    ~$ kubectl create namespace argocd
    ~$ kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/core-install.yaml

    These commands are taken from ArgoCD Installation Page. Make sure that the offical page takes priority over the commands in above.

  3. Login to the ArgoCD UI.

    • Run the following command to serve the ArgoCD service on your local machine on a given port.

      ~$ kubectl port-forward -n argocd svc/argocd-server YOUR_DESIRED_PORT:443
    • Get the initial admin password of ArgoCD to be able to access the ArgoCD service through the UI or CLI through the following command.

      ~$ kubectl get secret -n argocd argocd-initial-admin-secret -o yaml
      apiVersion: v1
      data:
          password: XXXXXXXXXXXXXXXXXXXXXXXX
      kind: Secret
      metadata:
          creationTimestamp: "XXXX-XX-XXXXX:XX:XXX"
          name: argocd-initial-admin-secret
          namespace: argocd
          resourceVersion: "XXXX"
          uid: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
      type: Opaque

      IMPORTANT: The password is base64 encoded so you need to decode the password before using it

      • Base64 Decode using a UNIX shell like sh, bash, zsh:
        ~$ echo "VEhJU19JU19USEVfUEFTU1dPUkQ=" | base64 --decode
        THIS_IS_THE_PASSWORD
      • Base64 Decode using powershell for a Windows Operating System:
        ~$ echo $([Text.Encoding]::Utf8.GetString([Convert]::FromBase64String("VEhJU19JU19USEVfUEFTU1dPUkQ=")))
        THIS_IS_THE_PASSWORD
    • Open your Browser and go the link https://localhost:YOUR_DESIRED_PORT
      NOTE: On the browser it will show that it does not trust the ArgoCD website however this only due to the SSL certificate being self-signed and not signed by some CA (Certificate Authority) that your browser is aware of and trusts. Please procceed to the link without worry for security issues, then you will be able to see the ArgoCD UI.

  4. Create an application.yaml file for ArgoCD with the content of the file in gitops_kubernetes_manifests/application.yaml located in the repository.

(back to top)

Usage

In this section you can see how easy it is to get this kubernetes cluster up and running.

Basic Run

  1. Apply the created application.yaml file using the following command

    ~$ kubectl apply -f path/to/application.yaml

    The application should pop up almost immediatly on the ArgoCD UI open in the browser. Click on the application that popped up and you should see something similar to argocd-preview

  2. Run the following command to serve the Go webapp

    ~$ kubectl port-forward -n development svc/go-webapp-service YOUR_DESIRED_GO_WEBAPP_PORT:8080

    NOTE: make sure that YOUR_DESIRED_GO_WEBAPP_PORT is different from the ArgoCD UI port.

  3. Open your Browser and go the link https://localhost:YOUR_DESIRED_GO_WEBAPP_PORT go-app-landing-page

    IMPORTANT: This makes you see that the cluster is up and running serving the Go webapp however the webapp is not functional for it needs a proper API key that you get directly from newsapi. Check the next section Functional Run.

Functional Run

  1. create your own PRIVATE REPO with the content in this repo so you can actually freely supply the API key into version control.

  2. Give access to ArgoCD of your PRIVATE REPO following the ArgoCD Private Repositories Official Page

  3. Change the content of the gitops_kubernetes_manifests\overlays\development\secrets\news_api_key.secret.example file in your PRIVATE REPO to the API key you get from newsapi

  4. Change the application.yaml file's spec.source.repoURL to your PRIVATE REPO url and then apply it with the following command

    ~$ kubectl apply -f path/to/application.yaml
  5. Open your Browser and go the link https://localhost:YOUR_DESIRED_GO_WEBAPP_PORT and you will have the functioning version of this basic Go webapp go-app-results-page

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Contact

Connect with me on

LinkedIn

(back to top)

Acknowledgments

(back to top)

About

A mini project to play around with a few technologies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published