# k8s op cli example ###### tags: `tutorials` ## Prerequisite - Services and Deployments - App container image ready ( e.g. GCP ARTIFACT REGISTRY ) - kubectl gcloud credentials ``` gcloud components install gke-gcloud-auth-plugin gcloud container clusters get-credentials --project <Project_ID> ``` ## Startup - Set defaults for the Google Cloud CLI ``` gcloud config set project <Project_ID> gcloud config set compute/region asia-east1 ``` - Create a GKE cluster ``` gcloud container clusters create-auto <cluster_name> gcloud container clusters list gcloud container clusters describe <cluster_name> ``` - Setup redis ``` kubectl apply -f redis-deployment.yaml kubectl get pods kubectl apply -f redis-service.yaml kubectl get service ``` - Setup api ``` kubectl apply -f api-deployment.yaml kubectl get pods kubectl apply -f api-service.yaml kubectl get service ``` ## Logs ``` kubectl logs deployment/redis kubectl logs service/redis kubectl logs deployment/api kubectl logs service/api ``` ## Clean up ``` # Delete the Service kubectl delete service api kubectl delete deployment -l app=api kubectl delete service redis kubectl delete deployment -l app=redis # Wait until the Load Balancer provisioned for the api Service is deleted gcloud compute forwarding-rules list # Delete the GKE cluster gcloud container clusters delete <cluster_name> ```