#!/bin/bash set -euo pipefail # Deploy PowerDNS on k3s # Usage: sudo ./deploy-powerdns.sh # Example: sudo ./deploy-powerdns.sh 3.218.167.115 if [ $# -lt 1 ]; then echo "Usage: $0 " echo "Example: $0 3.218.167.115" exit 1 fi PUBLIC_IP="$1" echo "==========================================" echo "Deploying PowerDNS with IP: $PUBLIC_IP" echo "==========================================" # Create data directory echo "Creating data directory..." mkdir -p /data/powerdns chown 953:953 /data/powerdns # Generate API key PDNS_API_KEY=$(openssl rand -hex 32) echo "$PDNS_API_KEY" > /root/.pdns-api-key chmod 600 /root/.pdns-api-key echo "API key saved to /root/.pdns-api-key" # Deploy PowerDNS echo "Deploying PowerDNS to k3s..." cat < /dev/null 2>&1; do sleep 2 done echo "PowerDNS API is ready!" # Function to create zone create_zone() { local DOMAIN=$1 echo "Creating zone: $DOMAIN" curl -sf -X POST "$PDNS_HOST/api/v1/servers/localhost/zones" \ -H "X-API-Key: $PDNS_API_KEY" \ -H "Content-Type: application/json" \ -d "{ \"name\": \"$DOMAIN.\", \"kind\": \"Native\", \"nameservers\": [\"ns1.$DOMAIN.\", \"ns2.$DOMAIN.\"] }" 2>/dev/null || echo " (zone may already exist)" } # Function to setup records setup_records() { local DOMAIN=$1 echo "Setting up records for: $DOMAIN" curl -sf -X PATCH "$PDNS_HOST/api/v1/servers/localhost/zones/$DOMAIN." \ -H "X-API-Key: $PDNS_API_KEY" \ -H "Content-Type: application/json" \ -d "{ \"rrsets\": [ { \"name\": \"$DOMAIN.\", \"type\": \"NS\", \"ttl\": 86400, \"changetype\": \"REPLACE\", \"records\": [ {\"content\": \"ns1.$DOMAIN.\", \"disabled\": false}, {\"content\": \"ns2.$DOMAIN.\", \"disabled\": false} ] }, { \"name\": \"ns1.$DOMAIN.\", \"type\": \"A\", \"ttl\": 3600, \"changetype\": \"REPLACE\", \"records\": [{\"content\": \"$PUBLIC_IP\", \"disabled\": false}] }, { \"name\": \"ns2.$DOMAIN.\", \"type\": \"A\", \"ttl\": 3600, \"changetype\": \"REPLACE\", \"records\": [{\"content\": \"$PUBLIC_IP\", \"disabled\": false}] }, { \"name\": \"$DOMAIN.\", \"type\": \"A\", \"ttl\": 300, \"changetype\": \"REPLACE\", \"records\": [{\"content\": \"$PUBLIC_IP\", \"disabled\": false}] }, { \"name\": \"www.$DOMAIN.\", \"type\": \"CNAME\", \"ttl\": 300, \"changetype\": \"REPLACE\", \"records\": [{\"content\": \"$DOMAIN.\", \"disabled\": false}] } ] }" } echo "" echo "Creating DNS zones..." for domain in superviber.com muffinlabs.ai letemcook.com appbasecamp.com thanksforborrowing.com alignment.coop; do create_zone $domain setup_records $domain done # Setup superviber.com beyondtheuniverse services echo "" echo "Setting up beyondtheuniverse.superviber.com services..." curl -sf -X PATCH "$PDNS_HOST/api/v1/servers/localhost/zones/superviber.com." \ -H "X-API-Key: $PDNS_API_KEY" \ -H "Content-Type: application/json" \ -d "{ \"rrsets\": [ { \"name\": \"beyondtheuniverse.superviber.com.\", \"type\": \"A\", \"ttl\": 300, \"changetype\": \"REPLACE\", \"records\": [{\"content\": \"$PUBLIC_IP\", \"disabled\": false}] }, { \"name\": \"git.beyondtheuniverse.superviber.com.\", \"type\": \"A\", \"ttl\": 300, \"changetype\": \"REPLACE\", \"records\": [{\"content\": \"$PUBLIC_IP\", \"disabled\": false}] }, { \"name\": \"mail.beyondtheuniverse.superviber.com.\", \"type\": \"A\", \"ttl\": 300, \"changetype\": \"REPLACE\", \"records\": [{\"content\": \"$PUBLIC_IP\", \"disabled\": false}] }, { \"name\": \"auth.beyondtheuniverse.superviber.com.\", \"type\": \"A\", \"ttl\": 300, \"changetype\": \"REPLACE\", \"records\": [{\"content\": \"$PUBLIC_IP\", \"disabled\": false}] }, { \"name\": \"vault.beyondtheuniverse.superviber.com.\", \"type\": \"A\", \"ttl\": 300, \"changetype\": \"REPLACE\", \"records\": [{\"content\": \"$PUBLIC_IP\", \"disabled\": false}] }, { \"name\": \"grafana.beyondtheuniverse.superviber.com.\", \"type\": \"A\", \"ttl\": 300, \"changetype\": \"REPLACE\", \"records\": [{\"content\": \"$PUBLIC_IP\", \"disabled\": false}] } ] }" echo "" echo "==========================================" echo "PowerDNS deployment complete!" echo "==========================================" echo "" echo "Verification:" echo " dig @$PUBLIC_IP superviber.com NS" echo " dig @$PUBLIC_IP git.beyondtheuniverse.superviber.com A" echo "" echo "Next steps:" echo "1. Update GoDaddy glue records for each domain:" echo " - ns1. -> $PUBLIC_IP" echo " - ns2. -> $PUBLIC_IP" echo "" echo "2. Update nameservers at GoDaddy:" echo " - ns1." echo " - ns2." echo "" echo "3. Wait for DNS propagation (up to 48 hours)" echo "=========================================="