- API Example
- How-to Guide
- I. Running model locally
- II. Model-serving with Google Kubernetes Engine (GKE)
- Install GCloud Packages
- 2.1 Create GKE cluster with Terraform (infrastruture as code)
- 2.2 Connect to GKE cluster with GCloud command
- 2.3 Switch to your GKE cluster environment (using kubectl)
- 2.4 Create cluster namespace
- 2.5 Deploy Nginx Ingress Controller with Helm-chart
- 2.6 Deploy Cat Breed Classification Application
- 2.7 Config Domain Name to nginx-ingress's External IP
- 2.8 Access Application UI
- III. Tracing with Jaeger & Opentelemetry
- IV. Monitoring with Prometheus & Grafana (kube-prometheus-stack)
- V. CI/CD with Jenkins & Google Compute Engine (GCE)
Cat Image to classify:
conda create -n my_env python==3.9
conda activate my_env
pip install -r requirements.txt
cd ./app/
uvicorn main:app --host 0.0.0.0 --port 30000
After that, you can enjoy API at address: http://localhost:30000/docs
*** If you already have Docker Engine in your local machine, just execute 1 command:
docker compose -f docker-compose.yaml up -d
- Install Gcloud CLI
- Install gke-gcloud-auth-plugin:
sudo apt-get install google-cloud-cli-gke-gcloud-auth-plugin
- Setup your GCloud project:
- Initialize GCloud account:
gcloud init
- Authorize & Login:
gcloud auth application-default login
cd terraform # Navigate to terraform folder
terraform plan # Preview cluster plan
terraform apply # Create cluster
2.3 Switch to your GKE cluster environment (using kubectl)
kubectx your_gke_cluster
kubectl create ns nginx-ingress # Nginx Ingress Controller
kubectl create ns model-serving
2.5 Deploy Nginx Ingress Controller with Helm-chart
helm upgrade --install nginx-ingress helm-charts/nginx-ingress -n nginx-ingress
helm upgrade --install nginx-ingress helm-charts/model-serving -n model-serving
kubectl get svc -a # Listing all services & finding your nginx External IP
sudo vim /etc/hosts # Editting hosts_file with Vim
your_nginx_externalIP
your_nginx-ingress_host cbp.com # Updated content
2.8 Access application at above address http://cbp.com/docs
kubectl create ns jaeger-tracing
helm upgrade --install jaeger-tracing helm-charts/jaeger-tracing -n jaeger-tracing
sudo vim /ect/hosts
your_nginx-ingress_host cbp.jaeger.com
3.3 Access Jaeger UI - http://cbp.jaeger.com/ & start tracing
4. Monitoring with Prometheus & Grafana (kube-prometheus-stack)
kubectl create ns monitoring
helm upgrade --install -f helm-charts/monitoring/personal_gf_calues.yaml kube-prometheus-stack helm-charts/monitoring/kube-prometheus-stack -n monitoring # Deploy with personal values.yaml to config grafana
sudo vim /ect/hosts
your_nginx-ingress_host cbp.monitoring.com
4.3 Access Grafana UI & enjoy monitoring dashboards - http://cbp.monitoring.com/grafana
** User: admin; Password: prom-operator
-
Create new Service Account
-
Navigate to Service Account page, then create a new service account with role as Compute Admin
-
Save above json file into
ansible/secrects
directory. -
Update service account's file path in
ansible/playbook/create_compute_instance.yaml
-
-
Create Google Compute Engine with Ansible
ansible-playbook ansible/playbooks/create_compute_instance.yaml
- Update SSH key
- Generate a new SSH key with command:
ssh-keygen
- Config the SSH key on Google Cloud Console at path:
Setting/Metadata/SSH KEYS
- Config
ansible/inventory
file with External IP of your Compute Engine Instance & the path to SSH Keys (id_rsa).
- Generate a new SSH key with command:
- Execute this command to deploy Jenkins on your GCE instance
ansible-playbook ansible/playbook/deploy_jenkins.yaml
-
Connect to Jenkins UI
- Checking Jenkins installed successfully on GCE
- Access the GCE instance
ssh -i ~/.ssh/id_rsa YOUR_USERNAME@INSTANCE_EXTERNAL_IP
- Verify if Jenkins is running in the Compute Engine instance
sudo docker ps
- Access the GCE instance
- Access Jenkins UI via
INSTANCE_EXTERNAL_IP:8081
- Follow the instruction to log in into Jenkins.
- The password can be retrieved by this way
# Inside your GCE instance sudo docker exec -ti jenkins bash cat /var/jenkins_home/secrets/initialAdminPassword
- Checking Jenkins installed successfully on GCE
-
Connect Jenkins to Github Repo
-
Add Jenkins to Github Repo Webhook:
-
Add GitHub Repo to Jenkins:
-
-
Add DockerHub Token to Jenkins Credential:
-
Install Jenkins's Plugins
-
Setup GKE Connection for Jenkins
-
Create
ClusterRoleBinding
in you GKE instancekubectl create clusterrolebinding model-serving-admin-binding \ --clusterrole=admin \ --serviceaccount=default:default \ --namespace=default kubectl create clusterrolebinding anonymous-admin-binding \ --clusterrole=admin \ --user=system:anonymous \ --namespace=default
-
Grant permission for Jenkins to access the GCP Filestore Storage - Config RBAC
kubectl apply -f k8s/rbac ```
-
Config Cloud Connection on Jenkins at
http://INSTANCE_EXTERNAL_IP:8081/manage/configureClouds/
- Get
Kubernetes URL
&Kubernetes server certificate key
with bash command
cat ~/.kube/config # if you don't have MiniKF on your machine cat ~/minikf-kubeconfig # if you already have MiniKF
- Get
-
- You can start manually Build new image & Deploy new version of service application with Trigger Button on Jenkins UI.
- Another way, when the are changes merged to
main/ master
branch, the Pipeline on Jenkins will Run, Build & Deploy new app version from DockerHub to GKE Cluster automatically.