95 lines
2.6 KiB
Markdown
95 lines
2.6 KiB
Markdown
# gcloud Skill
|
|
|
|
Common GCP patterns for the apes platform. All commands invoke gcloud/kubectl/docker directly via Bash.
|
|
|
|
**Project:** `apes-platform`
|
|
**Region:** `europe-west1`
|
|
**Zone:** `europe-west1-b`
|
|
|
|
## Current Infrastructure
|
|
|
|
| Service | Host | VM | IP |
|
|
|---------|------|----|----|
|
|
| Gitea | git.unslope.com | gitea-vm | 34.78.255.104 |
|
|
| Chat (planned) | apes.unslope.com | TBD | TBD |
|
|
|
|
## SSH into VMs
|
|
|
|
```bash
|
|
# Gitea VM
|
|
gcloud compute ssh gitea-vm --zone=europe-west1-b --project=apes-platform
|
|
|
|
# Run a command remotely
|
|
gcloud compute ssh gitea-vm --zone=europe-west1-b --project=apes-platform --command="sudo docker ps"
|
|
```
|
|
|
|
## Docker Compose on VMs
|
|
|
|
```bash
|
|
# Restart a service
|
|
gcloud compute ssh <vm> --zone=europe-west1-b --project=apes-platform \
|
|
--command="sudo bash -c 'cd /opt/<service> && docker compose restart <container>'"
|
|
|
|
# View logs
|
|
gcloud compute ssh <vm> --zone=europe-west1-b --project=apes-platform \
|
|
--command="sudo docker logs <container> --tail 50"
|
|
|
|
# Full redeploy
|
|
gcloud compute ssh <vm> --zone=europe-west1-b --project=apes-platform \
|
|
--command="sudo bash -c 'cd /opt/<service> && docker compose pull && docker compose up -d'"
|
|
```
|
|
|
|
## Static IPs & DNS
|
|
|
|
```bash
|
|
# Reserve a new static IP
|
|
gcloud compute addresses create <name> --region=europe-west1 --project=apes-platform
|
|
|
|
# Get IP value
|
|
gcloud compute addresses describe <name> --region=europe-west1 --project=apes-platform --format='value(address)'
|
|
|
|
# DNS: add A record at Namecheap (Advanced DNS tab) pointing subdomain to IP
|
|
```
|
|
|
|
## Firewall Rules
|
|
|
|
```bash
|
|
# List rules
|
|
gcloud compute firewall-rules list --project=apes-platform
|
|
|
|
# Open a port
|
|
gcloud compute firewall-rules create <name> --allow=tcp:<port> --target-tags=web-server --project=apes-platform
|
|
```
|
|
|
|
## New VM Pattern
|
|
|
|
```bash
|
|
gcloud compute instances create <name> \
|
|
--project=apes-platform \
|
|
--zone=europe-west1-b \
|
|
--machine-type=e2-small \
|
|
--image-family=debian-12 \
|
|
--image-project=debian-cloud \
|
|
--boot-disk-size=20GB \
|
|
--tags=web-server \
|
|
--address=<static-ip-name> \
|
|
--metadata-from-file=startup-script=<script-path>
|
|
```
|
|
|
|
## IAM
|
|
|
|
```bash
|
|
gcloud auth list
|
|
gcloud projects get-iam-policy apes-platform --format=json
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
| Error | Fix |
|
|
|-------|-----|
|
|
| VM SSH timeout | Check firewall: `gcloud compute firewall-rules list --project=apes-platform` |
|
|
| Docker not running | SSH in, run `sudo systemctl start docker` |
|
|
| Caddy cert failed | Check DNS propagation: `dig @dns1.registrar-servers.com <domain> A +short` |
|
|
| Container not starting | Check logs: `sudo docker logs <container> --tail 50` |
|
|
| DNS not resolving | Flush local cache: `sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder` |
|