Skip to content

henriqueatila/golang-gin-best-practices / skills/golang-gin-deploy

golang-gin-deploy

Verified

Deploy Go Gin APIs with Docker, docker-compose, Kubernetes. Use when Dockerizing a Go app, setting up docker-compose, deploying to K8s, or configuring CI/CD and health probes.

references/kubernetes-probes-hpa-ingress-pvc.md

View on GitHub
# Kubernetes — Probes, HPA, Ingress, PVC, PDB, and NetworkPolicy

## Liveness and Readiness Probes

Both probes hit `/health` from the **golang-gin-api** skill's `HealthHandler`.

```yaml
livenessProbe:
  httpGet: { path: /health, port: http }
  initialDelaySeconds: 15; periodSeconds: 20; timeoutSeconds: 5; failureThreshold: 3

readinessProbe:
  httpGet: { path: /health, port: http }
  initialDelaySeconds: 5; periodSeconds: 10; timeoutSeconds: 3; failureThreshold: 3
```

| Probe | On failure | On success |
|-------|-----------|------------|
| `livenessProbe` | Restart container | Nothing |
| `readinessProbe` | Remove from Service endpoints | Add to endpoints |

**Split endpoints when DB check is slow:**

```go
r.GET("/health/live",  func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"status": "ok"}) })
r.GET("/health/ready", healthHandler.Check)
```

**Startup probe (slow-starting apps):** `startupProbe.httpGet.path: /health/live`, `failureThreshold: 30`, `periodSeconds: 10` — 5 min max startup. Runs first — prevents liveness from killing a legitimately slow-starting pod.

---

## Horizontal Pod Autoscaler

```yaml
# k8s/hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: myapp
  namespace: myapp
spec:
  scaleTargetRef: { apiVersion: apps/v1, kind: Deployment, name: myapp }
  minReplicas: 2; maxReplicas: 10
  metrics:
    - type: Resource
      resource: { name: cpu, target: { type: Utilization, averageUtilization: 70 } }
    - type: Resource
      resource: { name: memory, target: { type: Utilization, averageUtilization: 80 } }
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300  # wait 5 min before scaling down
      policies: [{ type: Pods, value: 1, periodSeconds: 60 }]
    scaleUp:
      stabilizationWindowSeconds: 30
      policies: [{ type: Pods, value: 2, periodSeconds: 60 }]
```

`resources.requests` must be set in the Deployment for HPA to calculate utilization.

---

## Ingress

```yaml
# k8s/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myapp
  namespace: myapp
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "10m"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "30"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  ingressClassName: nginx
  tls:
    - hosts: [api.example.com]
      secretName: myapp-tls
  rules:
    - host: api.example.com
      http:
        paths:
          - path: /; pathType: Prefix
            backend: { service: { name: myapp, port: { name: http } } }
```

---

## PVC for PostgreSQL

Use a managed database (RDS, Cloud SQL) in production. For self-hosted, use a StatefulSet with `postgres:17-alpine`, `containerPort: 5432`, secret-backed `POSTGRES_PASSWORD`, `volumeMounts` at `/var/lib/postgresql/data`, and a `volumeClaimTemplate` requesting `10Gi` with `ReadWriteOnce` access mode.

Resources: `requests: { memory: 256Mi, cpu: 100m }`, `limits: { memory: 512Mi, cpu: 500m }`.

---

## PodDisruptionBudget

```yaml
# k8s/pdb.yaml
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata: { name: myapp-pdb, namespace: myapp }
spec:
  minAvailable: 1
  selector: { matchLabels: { app: myapp } }
```

PDB only protects against voluntary disruptions (kubectl drain, upgrades) — not crashes.

---

## NetworkPolicy

```yaml
# k8s/netpol.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: { name: myapp-netpol, namespace: myapp }
spec:
  podSelector: { matchLabels: { app: myapp } }
  policyTypes: [Ingress]
  ingress:
    - from:
        - namespaceSelector: { matchLabels: { name: ingress-nginx } }
      ports: [{ port: 8080 }]
```

Label the namespace: `kubectl label namespace ingress-nginx name=ingress-nginx`. Requires a CNI plugin that supports NetworkPolicy (Calico, Cilium, Weave).

> For complete manifests, Helm chart, and GitHub Actions CI/CD: see [kubernetes-complete-helm-cicd.md](kubernetes-complete-helm-cicd.md).
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 323kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall