Welcome to this comprehensive tutorial! 🚀 In this guide, we’ll walk through every step to set up a Kubernetes cluster on DigitalOcean. Whether you’re a DevOps engineer or a curious developer, get ready for a professional yet approachable journey! ✨
Prerequisites 📋
DigitalOcean account: Sign up at DigitalOcean if you don’t have one. doctl CLI: DigitalOcean’s command-line tool for managing resources. kubectl: Kubernetes command-line utility. SSH key: Added to your DigitalOcean account for secure droplet access. Basic Linux Kubernetes knowledge: Familiarity with the terminal and Kubernetes concepts.
Step 1: Install and Configure doctl 🛠️
1.1 Download doctl
Choose your OS and fetch the latest release:macOS:brew install doctl Linux: Download binary from doctl releases and move it to /usr/local/bin. Windows: Use scoop install doctl or download the ZIP.
1.2 Authenticate doctl
Run the following to link doctl with your account:doctl auth initYou’ll be prompted to paste a Personal Access Token. Generate one from the API Tokens page.
Step 2: Create Your Kubernetes Cluster 🌐
2.1 Choose Cluster Specifications
Decide on:Region (e.g., nyc1, sfo2) Node size (e.g., s-2vcpu-4gb) Node count (start with 3 for high availability)
2.2 Create the Cluster
Execute:doctl kubernetes cluster create my-cluster –region nyc1 –version 1.27.3-do.0 –size s-2vcpu-4gb –count 3⌛ Wait a few minutes. You’ll see status updates in your terminal.
Step 3: Configure kubectl ⚙️
3.1 Fetch Credentials
Run:doctl kubernetes cluster kubeconfig save my-clusterThis updates your ~/.kube/config, allowing kubectl to target your new cluster.
3.2 Verify Connectivity
Test with:kubectl get nodesYou should see three ready nodes listed. 🎉
Make it accessible via a LoadBalancer:kubectl expose deployment nginx –port=80 –type=LoadBalancerUse kubectl get svc to grab the external IP and visit it in your browser. 🚀
Step 5: Scale and Manage 📈
5.1 Scale Up
Increase replicas for higher traffic:kubectl scale deployment nginx –replicas=5
5.2 Update the Cluster
Keep your Kubernetes version current:doctl kubernetes cluster upgrade my-cluster –version 1.28.0-do.0Always test upgrades in a staging environment first! 🧪
Step 6: Clean Up 🔒
When you’re done, delete resources to avoid extra costs:kubectl delete service nginx kubectl delete deployment nginx doctl kubernetes cluster delete my-cluster –forceAll done! You’ve successfully built, managed, and torn down a Kubernetes cluster on DigitalOcean. 🎓