This project provides a comprehensive solution for setting up and managing a desktop/web application using Docker and Kubernetes on Google Cloud. It includes scripts for building and pushing Docker images, starting the application, and configuring Google Cloud resources.
- tq_solution
http://34.32.71.110:3000/apptq_frontend.html
./start_desktop_solution.sh
Note: do you have mac / windows? make sure you read https://github.com/pprajap/tq_frontend/blob/main/README.md to set up necessary environment
CLUSTER_NAME="your-cluster-name"
ZONE="your-cluster-zone"
gcloud init
gcloud auth login
gcloud config set project YOUR_PROJECT_ID
gcloud container clusters create $CLUSTER_NAME --num-nodes=3 --zone=$ZONE
gcloud container clusters get-credentials $CLUSTER_NAME --zone=$ZONE
- Download latest Kompose:
# Download and install Kompose
curl -L https://github.com/kubernetes/kompose/releases/latest/download/kompose-linux-amd64 -o kompose
chmod +x kompose
sudo mv kompose /usr/local/bin/kompose
- Convert Docker Compose to Kubernetes Manifests:
kompose convert -f docker-compose-web.yml
- Apply the Manifests:
kubectl apply -f k8_manifests/.
kubectl get services
kubectl get deployments
kubectl get pods
kubectl get nodes
- Get the Current Node Version:
CURRENT_NODE_VERSION=$(gcloud container clusters describe $CLUSTER_NAME --zone $ZONE --format="get(currentNodeVersion)")
- Upgrade the Nodes to the Same Version to Restart Them:
gcloud container clusters upgrade $CLUSTER_NAME --zone $ZONE --cluster-version $CURRENT_NODE_VERSION
Let's break down the CI/CD (Continuous Integration/Continuous Deployment) process for the tq_solution project in a way that's easy to understand, even for those who may not be familiar with computer science.
Continuous Integration (CI) is a practice where developers frequently integrate their code changes into a shared repository. Each integration is automatically verified by running tests to detect errors as early as possible.
Continuous Deployment (CD) is a practice where code changes are automatically deployed to a production environment after passing all tests. This ensures that the software is always in a deployable state.
The CI/CD process starts automatically whenever code is pushed to the "main" branch or when a pull request is made to the "main" branch. It can also be triggered manually from the Actions tab in GitHub.
- Checkout Code: The first step is to check out the code from the repository.
- Set Up Python: Python is set up with the required version (3.10).
- Install Dependencies: All necessary Python packages are installed.
- Run Tests: The backend tests are run using a tool called pytest. This ensures that the backend code is working correctly.
- Checkout Code: The code is checked out from the repository.
- Install Dependencies: All necessary packages, including Qt (a framework for building graphical user interfaces), are installed.
- Start Xvfb: A virtual display server (Xvfb) is started to simulate a display environment for running graphical tests.
- Build and Run Tests: The frontend code is built and the tests are run. This ensures that the frontend code is working correctly.
- Backend Image: After the backend tests pass, a Docker image for the backend is built and pushed to Docker Hub (a repository for Docker images).
- Frontend Web Image: After the frontend tests pass, a Docker image for the frontend web application is built and pushed to Docker Hub.
- Frontend Desktop Image: Similarly, a Docker image for the frontend desktop application is built and pushed to Docker Hub.
- Reverse Proxy Image: A Docker image for the reverse proxy (a server that directs client requests to the appropriate backend services) is built and pushed to Docker Hub.
- Authenticate to Google Cloud: The workflow authenticates to Google Cloud using a service account key.
- Set Up GKE Credentials: The workflow sets up credentials to access the Google Kubernetes Engine cluster.
- Verify Cluster Services: Before deployment, the workflow verifies the current state of the cluster services.
- Download and Set Up Kompose: Kompose is a tool that converts Docker Compose files to Kubernetes manifests.
- Convert and Apply Manifests: The Docker Compose file is converted to Kubernetes manifests and applied to the cluster.
- Update Images in Deployments: The workflow updates the images in the Kubernetes deployments to the latest versions.
- Check Rollout Status: The workflow checks the rollout status of the deployments to ensure they are successfully updated.
- Verify Cluster Services: After deployment, the workflow verifies the state of the cluster services again.
- Early Detection of Errors: By running tests automatically on every code change, errors are detected early, making them easier to fix.
- Consistent Deployment: Automated deployment ensures that the software is always in a deployable state, reducing the risk of deployment failures.
- Faster Development: Developers can focus on writing code rather than manually testing and deploying it, leading to faster development cycles.