## GCLI
`gcloud auth login` - Authorizes the CLI using your Google user credentials.
`gcloud auth login` - Opens a browser to authenticate your terminal.
`gcloud config set [PROPERTY] [VALUE]` - Sets default configurations so you don't have to type them every time.
`gcloud config set project mutonex-prod-123` - Sets your active working project.
`gcloud config list` - Shows your currently active configuration (project, zone, account).
`gcloud config list` - Crucial for verifying your environment before deploying.
`gcloud container clusters get-credentials [CLUSTER_NAME]` - Fetches cluster authentication credentials and updates your local kubeconfig file.
`gcloud container clusters get-credentials mutonex-cluster --zone europe-north1-a` - Connects your local kubectl to your GCP cluster.
## IAM
`gcloud projects add-iam-policy-binding` - Binds a role to a user, group, or service account at the project level.
`gcloud projects add-iam-policy-binding mutonex-prod --member="user:dev@email.com" --role="roles/viewer"` - Grants viewer access to a specific user.
`gcloud iam service-accounts create` - Creates a non-human account for your applications to use.
`gcloud iam service-accounts create db-accessor --display-name="DB Access"` - Creates a service account for database access.
## GKE
`gcloud container clusters create` - Provisions a new GKE cluster.
`gcloud container clusters create mutonex-cluster --num-nodes=3 --zone=us-central1-a` - Creates a 3-node cluster in a specific zone.
`gcloud container clusters resize` - Scales the underlying Compute Engine nodes in a cluster pool.
`gcloud container clusters resize mutonex-cluster --node-pool default-pool --num-nodes 5` - Resizes the default node pool to 5 nodes.
## Compute Engine/VMs
`gcloud compute instances create` - Provisions a new VM.
`gcloud compute instances create test-server --machine-type=e2-micro --zone=us-central1-a --preemptible` - Creates a preemptible VM (frequently tested on the ACE).
`gcloud compute instances list` - Lists all Compute Engine Virtual Machines in your project.
`gcloud compute instances list --filter="zone:europe-north1-a"` - Shows VMs only in a specific zone.
`gcloud compute ssh` - Securely connects to a VM using GCP's identity proxy, automatically handling SSH keys.
`gcloud compute ssh test-server --zone=us-central1-a` - Opens an SSH session into the test server.
## Kubectl
`kubectl apply -f [FILE]` - Creates or updates resources from a YAML file.
`kubectl apply -f mutonex-backend.yaml` - Deploys your Elixir server manifest.
`kubectl get [RESOURCE]` - Lists resources (pods, services, deployments, nodes).
`kubectl get pods -n default` - Lists all running pods in the default namespace.
`kubectl describe [RESOURCE] [NAME]` - Shows detailed state and recent events for a specific resource.
`kubectl describe pod nginx-front-5c8f5` - Crucial for figuring out why a pod is stuck in Pending or CrashLoopBackOff.
`kubectl logs [POD_NAME]` - Prints the logs for a container in a pod.
`kubectl logs phoenix-app-pod -f` - Streams the Elixir application logs in real-time.
`kubectl exec -it [POD_NAME] -- [COMMAND]` - Executes a command directly inside a running container.
`kubectl exec -it postgres-db-pod -- psql -U admin` - Opens a Postgres shell inside your database pod.
`kubectl port-forward [POD_NAME] [LOCAL_PORT]:[POD_PORT]` - Forwards a local port to a port on the pod for debugging.
`kubectl port-forward nginx-front-5c8f5 8080:80` - Allows local testing without exposing a public IP.
`kubectl scale deployment` - Manually scales the number of pod replicas.
`kubectl scale deployment nginx-front --replicas=5` - Scales the Nginx frontend to 5 replicas.
`kubectl expose deployment` - Creates a Kubernetes Service to route traffic to your pods.
`kubectl expose deployment nginx-front --type=LoadBalancer --port=80` - Triggers GCP to spin up a Cloud Load Balancer for the deployment.
`kubectl delete [RESOURCE] [NAME]` - Deletes a specific resource.
`kubectl delete service nginx-front` - Removes the service and tears down the associated Cloud Load Balancer.
## ACE Exam Scenarios
Format:
- Given [Scenario], run [Command]
- Given [Constraint], choose [Resource]
### Need to connect local terminal to GKE cluster?
`gcloud container clusters get-credentials [CLUSTER_NAME]`
### Don't want to manage Compute Engine VMs, but want a GKE cluster?
- Use GKE Autopilot