logo
eng-flag

DigitalOcean Cheatsheet

Table of Contents

  1. Introduction to DigitalOcean
  2. DigitalOcean CLI (doctl)
  3. Droplets
  4. Volumes
  5. Networking
  6. Kubernetes
  7. App Platform
  8. Databases
  9. Spaces (Object Storage)
  10. Load Balancers
  11. Firewalls
  12. Monitoring
  13. Projects
  14. Best Practices

Introduction to DigitalOcean

DigitalOcean is a cloud infrastructure provider that offers cloud services to help deploy and scale applications that run simultaneously on multiple computers.

Key Benefits:

  • Simplicity
  • Predictable pricing
  • Developer-friendly
  • High-performance SSD-based virtual machines
  • Global data center availability

DigitalOcean CLI (doctl)

The DigitalOcean Command Line Interface (doctl) allows you to interact with the DigitalOcean API via the command line.

  1. Installation: Follow the instructions at: https://github.com/digitalocean/doctl

  2. Authenticate:

    doctl auth init
    
  3. Basic Command Structure:

    doctl <command> <subcommand> <flags>
    
  4. Get Help:

    doctl help
    doctl <command> --help
    

Droplets

Droplets are DigitalOcean's virtual private servers.

  1. Create a Droplet:

    doctl compute droplet create my-droplet --size s-1vcpu-1gb --image ubuntu-20-04-x64 --region nyc1
    
  2. List Droplets:

    doctl compute droplet list
    
  3. Get Droplet Info:

    doctl compute droplet get <droplet-id>
    
  4. Delete a Droplet:

    doctl compute droplet delete <droplet-id>
    
  5. SSH into a Droplet:

    doctl compute ssh <droplet-name>
    

Volumes

Volumes are network-based block storage devices that can be attached to Droplets.

  1. Create a Volume:

    doctl compute volume create my-volume --region nyc1 --size 100GiB
    
  2. List Volumes:

    doctl compute volume list
    
  3. Attach a Volume to a Droplet:

    doctl compute volume-action attach <volume-id> <droplet-id>
    
  4. Detach a Volume:

    doctl compute volume-action detach <volume-id>
    

Networking

  1. Create a VPC:

    doctl vpcs create --name my-vpc --region nyc1
    
  2. List VPCs:

    doctl vpcs list
    
  3. Create a Firewall:

    doctl compute firewall create --name my-firewall --inbound-rules "protocol:tcp,ports:22,address:0.0.0.0/0"
    
  4. List Firewalls:

    doctl compute firewall list
    

Kubernetes

DigitalOcean Kubernetes (DOKS) is a managed Kubernetes service.

  1. Create a Kubernetes Cluster:

    doctl kubernetes cluster create my-cluster --region nyc1 --size s-2vcpu-2gb --count 3
    
  2. List Clusters:

    doctl kubernetes cluster list
    
  3. Get Kubeconfig:

    doctl kubernetes cluster kubeconfig save my-cluster
    
  4. Delete a Cluster:

    doctl kubernetes cluster delete my-cluster
    

App Platform

App Platform is a Platform-as-a-Service (PaaS) offering.

  1. Create an App:

    doctl apps create --spec app.yaml
    
  2. List Apps:

    doctl apps list
    
  3. Get App Info:

    doctl apps get <app-id>
    
  4. Delete an App:

    doctl apps delete <app-id>
    

Databases

DigitalOcean offers managed database services.

  1. Create a Database Cluster:

    doctl databases create my-db --engine mysql --region nyc1 --size db-s-1vcpu-1gb
    
  2. List Database Clusters:

    doctl databases list
    
  3. Get Database Info:

    doctl databases get <database-id>
    
  4. Delete a Database:

    doctl databases delete <database-id>
    

Spaces (Object Storage)

Spaces is DigitalOcean's object storage service.

  1. Create a Space:

    doctl compute space create my-space --region nyc3
    
  2. List Spaces:

    doctl compute space list
    
  3. Upload a File to a Space:

    doctl compute space upload my-space ./local-file.txt remote-file.txt
    
  4. Delete a Space:

    doctl compute space delete my-space
    

Load Balancers

  1. Create a Load Balancer:

    doctl compute load-balancer create --name my-lb --region nyc1 --droplet-ids <droplet-id-1>,<droplet-id-2>
    
  2. List Load Balancers:

    doctl compute load-balancer list
    
  3. Delete a Load Balancer:

    doctl compute load-balancer delete <load-balancer-id>
    

Firewalls

  1. Create a Firewall:

    doctl compute firewall create --name my-firewall --inbound-rules "protocol:tcp,ports:22,address:0.0.0.0/0"
    
  2. List Firewalls:

    doctl compute firewall list
    
  3. Add a Rule to a Firewall:

    doctl compute firewall add-rules <firewall-id> --inbound-rules "protocol:tcp,ports:80,address:0.0.0.0/0"
    
  4. Delete a Firewall:

    doctl compute firewall delete <firewall-id>
    

Monitoring

  1. Create an Alert Policy:

    doctl monitoring alert-policy create --type v1 --enabled --compare greater_than --value 80 --window 5m --entities <droplet-id> --description "High CPU Usage"
    
  2. List Alert Policies:

    doctl monitoring alert-policy list
    
  3. Delete an Alert Policy:

    doctl monitoring alert-policy delete <policy-id>
    

Projects

Projects help you organize your DigitalOcean resources.

  1. Create a Project:

    doctl projects create --name my-project --purpose "My awesome project"
    
  2. List Projects:

    doctl projects list
    
  3. Assign a Resource to a Project:

    doctl projects resources assign <project-id> --resource <resource-urn>
    
  4. Delete a Project:

    doctl projects delete <project-id>
    

Best Practices

  1. Use SSH Keys for Authentication Always use SSH keys instead of passwords for better security.

  2. Enable and Configure Firewalls Use DigitalOcean's cloud firewalls to control incoming and outgoing traffic.

  3. Regular Backups Use DigitalOcean's backup feature or set up your own backup solution.

  4. Monitor Your Resources Use DigitalOcean's monitoring tools to keep track of your resources' performance.

  5. Use Private Networking When possible, use private networking to communicate between your Droplets.

  6. Utilize Floating IPs For high-availability setups, use Floating IPs to quickly redirect traffic.

  7. Implement Load Balancing For applications that require high availability, use Load Balancers.

  8. Use Tags and Projects Organize your resources with tags and projects for better management.

  9. Keep Your Systems Updated Regularly update your Droplets' operating systems and installed software.

  10. Use Version Control Always use version control for your application code and infrastructure configurations.

2024 © All rights reserved - buraxta.com