Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 35 ยท Projects and Practice

Practice: Troubleshooting DigitalOcean Setups

Practise diagnosing common DigitalOcean problems: cannot connect, 502 errors, failing health checks, full disks, cost surprises, with a diagnosis tool and a command cheat sheet.

Knowing how each service works is half the job. The other half is a calm, systematic way to find out why something is broken. This final lesson gives you a method, a set of realistic scenarios to reason through, a small diagnosing tool and a cheat sheet of the commands from this chapter. DigitalOcean is not available on this site, so everything runnable is a labelled Python stand-in and every command is text.

A method that works

  1. State the symptom precisely. "The site is down" is vague; "HTTPS to example.com times out from my laptop, but works from my phone" is a clue.
  2. Follow the path of a request from the visitor to the data and ask at each hop: does it reach it, and is it answered?
  3. Change one thing at a time and note the result.
  4. Read the logs and the graphs before guessing (monitoring).
  5. Write down the cause and the fix, and add a check or alert so the next occurrence is caught earlier.
flowchart LR
  A["DNS resolves?"] --> B["Port reachable?<br/>(firewall, LB)"]
  B --> C["TLS valid?"]
  C --> D["Proxy / LB healthy?"]
  D --> E["App running?<br/>(systemd, logs)"]
  E --> F["Database reachable?"]

Walk the chain in order: the first failing link is where to dig.

Useful probes

Terminal
dig +short example.com
curl -I https://example.com
curl -v --connect-timeout 5 http://203.0.113.10:8080/healthz
nc -vz 203.0.113.10 22
openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -dates

# on the server
systemctl status app
journalctl -u app -n 100 --no-pager
sudo ss -tlnp
df -h
free -m
top
sudo nginx -t

Scenarios to think through

Try to answer each before reading the diagnosis in the next block.

  1. SSH says "Connection timed out". The packet never gets an answer: usually a Cloud Firewall or ufw rule, a wrong IP, or the Droplet is down. "Connection refused" is different: the host answered but no SSH daemon listens on that port.
  2. Permission denied (publickey). The server reached sshd but rejected your key: wrong user (root versus deploy), key not in authorized_keys, wrong file permissions (~/.ssh must be 700, the file 600), or you did not specify the key (ssh -i).
  3. 502 from Nginx or the Load Balancer. The proxy is fine; the upstream is not. Check the app service and its port.
  4. Load Balancer shows all backends down. The health check path returns non-200, the app listens only on localhost while the balancer connects through the private IP, or a firewall blocks the balancer. Check which interface the app binds to.
  5. Site works for some visitors only. Often IPv6 (an AAAA record without a matching firewall rule or listener), stale DNS caches, or one unhealthy backend behind the balancer.
  6. Everything is slow. Look at CPU, memory (swap thrashing), disk I/O and the database; then at traffic spikes.
  7. Disk full. Logs, Docker images, old releases or a full database. df -h, then sudo du -xh / --max-depth=2 | sort -h | tail. Fix the cause, add rotation and a disk alert, and resize the volume if needed.
  8. Bill higher than expected. Powered-off Droplets, old snapshots, unattached volumes, extra Load Balancers, bandwidth overage (cost control).
  9. Terraform wants to destroy something. Read the plan: a renamed resource, a changed immutable field, or drift. Do not apply until you understand why.
  10. Certificate expired. Renewal failed: port 80 closed, DNS moved, a stale API token (TLS).

A diagnosing stand-in

This stand-in encodes a few of the symptoms and likely causes as a simple rule table, so you can see the logic. It is a study aid, not a real diagnosis tool.

Python Stand-in: symptom to likely cause

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Practice with a log

Reading logs quickly is a skill. This stand-in counts status codes in a fabricated access log and flags a problem.

Python Stand-in: summarise an access log

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The pattern (every failure on one path) points at one broken backend route, not the network.

Command cheat sheet

Task Command
Authenticate doctl auth init --context NAME
List Droplets doctl compute droplet list --format ID,Name,PublicIPv4,Status
Create Droplet doctl compute droplet create NAME --region R --size S --image I --ssh-keys K --wait
Snapshot doctl compute droplet-action snapshot ID --snapshot-name N
Firewalls doctl compute firewall list
Load Balancers doctl compute load-balancer list
Kubernetes credentials doctl kubernetes cluster kubeconfig save NAME
Node pool autoscale doctl kubernetes cluster node-pool update C P --auto-scale --min-nodes 2 --max-nodes 6
Alerts doctl monitoring alert list
Balance and invoices doctl balance get, doctl invoice list
Terraform terraform init, plan -out=tfplan, apply tfplan
Certificates sudo certbot renew --dry-run

Where to go next

Build one real project end to end, keep it in Terraform, and write its runbook. Explore the parts this chapter only touched: App Platform, Spaces with a CDN, managed databases, container registry and global load balancing. Read provider documentation for current limits and prices, because those change faster than any tutorial.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. SSH shows 'Connection timed out'. What is the most likely cause?

    A timeout means no answer came back; refused or permission errors mean the host did answer.
  2. 2. A Load Balancer shows all backends down, but the app answers on localhost. What should you check?

    An app bound to 127.0.0.1 cannot be reached through the private IP; the health check path must also return 200.
  3. 3. What is the first step of good troubleshooting?

    A precise symptom and a hop-by-hop path find the failing link faster than random changes.
  4. 4. Your errors all come from /api/items while other pages work. What does that suggest?

    Failures confined to one path point at that handler or what it calls, such as a database query.

Summary

  • Troubleshoot by stating the symptom, walking the request path (DNS, port, TLS, proxy, app, database) and changing one thing at a time.
  • Timeout, refused and denied mean different things; so do 502, 504 and certificate errors.
  • Use logs, graphs and simple probes (curl, nc, dig, journalctl, df), then add alerts so the problem is caught sooner.
  • Keep a cheat sheet, build a real project and treat prices and limits as things to look up.

Next: Back to the DigitalOcean track