feat: Add comprehensive documentation structure with farming, mycelium, and cloud guides
This commit is contained in:
340
docs/mycelium-cloud/getting-started.md
Normal file
340
docs/mycelium-cloud/getting-started.md
Normal file
@@ -0,0 +1,340 @@
|
||||
---
|
||||
sidebar_position: 2
|
||||
---
|
||||
|
||||
# Getting Started with Mycelium Cloud
|
||||
|
||||
Deploy your first Kubernetes cluster on the ThreeFold Grid in just a few steps.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before you begin, make sure you have:
|
||||
|
||||
- ✅ **Mycelium installed** - Required for cluster access ([Installation guide](/mycelium-network/install))
|
||||
- ✅ **SSH key pair** - For node access
|
||||
- ✅ **kubectl installed** - For managing your cluster ([Install kubectl](https://kubernetes.io/docs/tasks/tools/))
|
||||
- ✅ **Credits** - To fund your deployment
|
||||
|
||||
## Step 1: Create Your Account
|
||||
|
||||
### Sign Up
|
||||
|
||||
1. Go to [vdc.grid.tf/sign-up](https://vdc.grid.tf/sign-up)
|
||||
2. Fill in your details:
|
||||
- Email address
|
||||
- Password
|
||||
- Confirm password
|
||||
3. Click **Sign Up**
|
||||
|
||||
### Verify Email
|
||||
|
||||
1. Check your email inbox
|
||||
2. Click the verification link
|
||||
3. Your account is now active
|
||||
|
||||
## Step 2: Set Up Your Account
|
||||
|
||||
### Add Credits
|
||||
|
||||
1. Log in to your dashboard
|
||||
2. Navigate to **Credits** or **Billing** section
|
||||
3. Add funds to your account
|
||||
- Choose payment method
|
||||
- Enter amount
|
||||
- Complete payment
|
||||
|
||||
Your credits will be used to pay for cluster resources (CPU, RAM, storage, time).
|
||||
|
||||
### Add SSH Key
|
||||
|
||||
1. Navigate to **SSH Keys** section (or **Add SSH** card)
|
||||
2. Click **Add SSH Key**
|
||||
3. Paste your **public key** (usually `~/.ssh/id_rsa.pub`)
|
||||
4. Give it a name
|
||||
5. Save
|
||||
|
||||
<div className="info-box">
|
||||
|
||||
### 🔐 Need an SSH Key?
|
||||
|
||||
If you don't have one:
|
||||
|
||||
```bash
|
||||
# Generate a new SSH key pair
|
||||
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
|
||||
|
||||
# View your public key
|
||||
cat ~/.ssh/id_rsa.pub
|
||||
```
|
||||
|
||||
Copy the output and paste it into the dashboard.
|
||||
|
||||
</div>
|
||||
|
||||
## Step 3: Deploy Your First Cluster
|
||||
|
||||
### Access Deployment Page
|
||||
|
||||
1. From your dashboard, click **Deploy Cluster** or **New Cluster**
|
||||
2. You'll see the cluster configuration wizard
|
||||
|
||||
### Configure Your Cluster
|
||||
|
||||
#### Basic Settings
|
||||
|
||||
- **Cluster Name**: Give your cluster a unique name
|
||||
- **Description**: Optional description of the cluster purpose
|
||||
|
||||
#### Master Nodes
|
||||
|
||||
Configure your control plane nodes:
|
||||
|
||||
- **Count**: Number of master nodes
|
||||
- 1 for development/testing
|
||||
- 3 for production (high availability)
|
||||
- **CPU**: Number of cores per master (2-4 recommended)
|
||||
- **RAM**: Memory per master (4-8GB recommended)
|
||||
- **Storage**: Disk space per master (20-50GB)
|
||||
|
||||
#### Worker Nodes
|
||||
|
||||
Configure your workload nodes:
|
||||
|
||||
- **Count**: Number of worker nodes (1-10+)
|
||||
- **CPU**: Cores per worker (based on workload)
|
||||
- **RAM**: Memory per worker (based on workload)
|
||||
- **Storage**: Disk space per worker (based on workload)
|
||||
|
||||
**Example Configuration (Starter):**
|
||||
```
|
||||
Masters: 1 node (2 CPU, 4GB RAM, 25GB storage)
|
||||
Workers: 2 nodes (2 CPU, 4GB RAM, 50GB storage each)
|
||||
```
|
||||
|
||||
### Select Nodes
|
||||
|
||||
1. The system will show available ThreeFold Grid nodes
|
||||
2. Select nodes for your deployment
|
||||
- Choose based on location, specs, and availability
|
||||
- System may auto-select optimal nodes
|
||||
3. Review your selections
|
||||
|
||||
### Review & Deploy
|
||||
|
||||
1. Review your configuration:
|
||||
- Node counts and specs
|
||||
- Selected grid nodes
|
||||
- Estimated cost
|
||||
2. Confirm you have sufficient credits
|
||||
3. Click **Deploy**
|
||||
|
||||
The deployment process will begin. This typically takes 5-15 minutes.
|
||||
|
||||
## Step 4: Access Your Cluster
|
||||
|
||||
Once deployed, you can access your cluster in two ways: kubectl and SSH.
|
||||
|
||||
### Method 1: kubectl Access
|
||||
|
||||
#### Download kubeconfig
|
||||
|
||||
1. Go to **Dashboard** → **Clusters**
|
||||
2. Find your cluster
|
||||
3. Click the download icon (⬇️) or **Get Config**
|
||||
4. Save the file (e.g., `mycluster-config.yaml`)
|
||||
|
||||
#### Configure kubectl
|
||||
|
||||
```bash
|
||||
# Set kubeconfig for this session
|
||||
export KUBECONFIG=/path/to/mycluster-config.yaml
|
||||
|
||||
# Or copy to default location
|
||||
mkdir -p ~/.kube
|
||||
cp mycluster-config.yaml ~/.kube/config
|
||||
|
||||
# Test connection
|
||||
kubectl get nodes
|
||||
```
|
||||
|
||||
You should see your cluster nodes listed!
|
||||
|
||||
```
|
||||
NAME STATUS ROLES AGE VERSION
|
||||
master-1 Ready control-plane,master 10m v1.26.0+k3s1
|
||||
worker-1 Ready <none> 9m v1.26.0+k3s1
|
||||
worker-2 Ready <none> 9m v1.26.0+k3s1
|
||||
```
|
||||
|
||||
### Method 2: SSH Access
|
||||
|
||||
#### Start Mycelium
|
||||
|
||||
If not already running, start Mycelium on your local machine:
|
||||
|
||||
```bash
|
||||
sudo mycelium --peers \
|
||||
tcp://188.40.132.242:9651 \
|
||||
quic://185.69.166.8:9651 \
|
||||
tcp://185.69.166.7:9651 \
|
||||
quic://65.21.231.58:9651
|
||||
```
|
||||
|
||||
#### Get Node IPs
|
||||
|
||||
From your dashboard:
|
||||
1. Go to your cluster details
|
||||
2. Find the **Mycelium IPs** for each node
|
||||
3. Note them down (e.g., `400:1234:5678:abcd::1`)
|
||||
|
||||
#### SSH to Nodes
|
||||
|
||||
```bash
|
||||
# SSH to master node
|
||||
ssh root@400:1234:5678:abcd::1
|
||||
|
||||
# SSH to worker node
|
||||
ssh root@400:1234:5678:abcd::2
|
||||
```
|
||||
|
||||
You're now connected to your cluster node!
|
||||
|
||||
## Step 5: Deploy Your First Application
|
||||
|
||||
Let's deploy a simple web application to test your cluster.
|
||||
|
||||
### Create a Deployment
|
||||
|
||||
```bash
|
||||
# Create an nginx deployment
|
||||
kubectl create deployment hello-web --image=nginx:latest
|
||||
|
||||
# Check deployment status
|
||||
kubectl get deployments
|
||||
kubectl get pods
|
||||
```
|
||||
|
||||
### Expose the Service
|
||||
|
||||
```bash
|
||||
# Expose as a service
|
||||
kubectl expose deployment hello-web --port=80 --type=ClusterIP
|
||||
|
||||
# Check service
|
||||
kubectl get services
|
||||
```
|
||||
|
||||
### Access the Service
|
||||
|
||||
```bash
|
||||
# Port forward to your local machine
|
||||
kubectl port-forward service/hello-web 8080:80
|
||||
```
|
||||
|
||||
Open `http://localhost:8080` in your browser. You should see the nginx welcome page!
|
||||
|
||||
## Step 6: Monitor Your Cluster
|
||||
|
||||
### Using Dashboard
|
||||
|
||||
Your Mycelium Cloud dashboard shows:
|
||||
- Cluster status (running, stopped, etc.)
|
||||
- Resource usage
|
||||
- Cost tracking
|
||||
- Node health
|
||||
|
||||
### Using kubectl
|
||||
|
||||
```bash
|
||||
# View cluster info
|
||||
kubectl cluster-info
|
||||
|
||||
# Check node status
|
||||
kubectl get nodes
|
||||
|
||||
# View all resources
|
||||
kubectl get all --all-namespaces
|
||||
|
||||
# Check cluster events
|
||||
kubectl get events
|
||||
```
|
||||
|
||||
## Managing Your Cluster
|
||||
|
||||
### Scale Workers
|
||||
|
||||
Add more worker nodes:
|
||||
1. Go to cluster details in dashboard
|
||||
2. Click **Scale** or **Add Nodes**
|
||||
3. Configure new worker nodes
|
||||
4. Deploy
|
||||
|
||||
### Delete Resources
|
||||
|
||||
```bash
|
||||
# Delete the test deployment
|
||||
kubectl delete deployment hello-web
|
||||
kubectl delete service hello-web
|
||||
```
|
||||
|
||||
### Stop/Start Cluster
|
||||
|
||||
From the dashboard:
|
||||
- **Stop**: Pause cluster (saves costs)
|
||||
- **Start**: Resume cluster
|
||||
- **Delete**: Permanently remove (frees all resources)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Can't Connect with kubectl
|
||||
|
||||
1. **Check kubeconfig**: Ensure KUBECONFIG is set correctly
|
||||
2. **Verify Mycelium**: Make sure Mycelium is running
|
||||
3. **Check cluster status**: Ensure cluster is running in dashboard
|
||||
4. **Test network**: Try pinging cluster nodes via Mycelium IPs
|
||||
|
||||
```bash
|
||||
# Test Mycelium connectivity
|
||||
ping6 <cluster-node-mycelium-ip>
|
||||
```
|
||||
|
||||
### Can't SSH to Nodes
|
||||
|
||||
1. **Mycelium running**: Ensure Mycelium daemon is active
|
||||
2. **SSH key added**: Verify your public key is in dashboard
|
||||
3. **Correct IP**: Double-check Mycelium IP from dashboard
|
||||
4. **Network access**: Test with `ping6` first
|
||||
|
||||
### Pods Not Starting
|
||||
|
||||
```bash
|
||||
# Check pod status
|
||||
kubectl describe pod <pod-name>
|
||||
|
||||
# Check node resources
|
||||
kubectl top nodes
|
||||
|
||||
# Check events
|
||||
kubectl get events --sort-by='.lastTimestamp'
|
||||
```
|
||||
|
||||
## What's Next?
|
||||
|
||||
Now that you have a cluster running, explore more:
|
||||
|
||||
- **[Tutorial](/mycelium-cloud/tutorial)** - Deploy real applications
|
||||
- **[Kubernetes Concepts](https://codescalers.github.io/www_kubecloud/kubernetes-concepts)** - Learn K8s fundamentals
|
||||
- **[FAQ](https://codescalers.github.io/www_kubecloud/faq)** - Common questions
|
||||
|
||||
## Resources
|
||||
|
||||
- **Dashboard**: [vdc.grid.tf](https://vdc.grid.tf)
|
||||
- **Kubernetes Docs**: [kubernetes.io/docs](https://kubernetes.io/docs/)
|
||||
- **kubectl Cheat Sheet**: [kubernetes.io/docs/reference/kubectl/cheatsheet](https://kubernetes.io/docs/reference/kubectl/cheatsheet/)
|
||||
- **Community**: [Telegram](https://t.me/threefoldfarmers)
|
||||
|
||||
---
|
||||
|
||||
:::tip Cluster Running Successfully?
|
||||
Great! Now try the **[Tutorial](/mycelium-cloud/tutorial)** to deploy more complex applications.
|
||||
:::
|
||||
195
docs/mycelium-cloud/overview.md
Normal file
195
docs/mycelium-cloud/overview.md
Normal file
@@ -0,0 +1,195 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# What is Mycelium Cloud?
|
||||
|
||||
Mycelium Cloud lets you deploy and manage **Kubernetes clusters** on the decentralized ThreeFold Grid infrastructure.
|
||||
|
||||
Run your containerized workloads on distributed, cost-effective infrastructure with built-in security and global availability.
|
||||
|
||||
## How It Works
|
||||
|
||||
Mycelium Cloud provides a complete platform for cloud-native applications:
|
||||
|
||||
1. **Sign up** for an account
|
||||
2. **Add credits** to fund your deployments
|
||||
3. **Deploy clusters** with custom configurations
|
||||
4. **Manage workloads** using standard Kubernetes tools
|
||||
|
||||
All running on the ThreeFold Grid's decentralized infrastructure.
|
||||
|
||||
## Why Use Mycelium Cloud?
|
||||
|
||||
### 🌍 Decentralized Infrastructure
|
||||
|
||||
- Deploy on ThreeFold Grid's distributed network
|
||||
- No dependency on centralized cloud providers
|
||||
- Global node distribution
|
||||
- True infrastructure sovereignty
|
||||
|
||||
### 📦 Full Kubernetes Management
|
||||
|
||||
- **K3s clusters** - Lightweight, production-ready Kubernetes
|
||||
- **Multi-master support** - High availability configurations
|
||||
- **Standard tooling** - Use kubectl, Helm, and your favorite tools
|
||||
- **Complete control** - Full cluster access
|
||||
|
||||
### 🔐 Secure by Default
|
||||
|
||||
- **Mycelium networking** - Encrypted peer-to-peer connections
|
||||
- **No public IPs needed** - Access via Mycelium overlay network
|
||||
- **End-to-end encryption** - All traffic secured
|
||||
- **Private by design** - Your infrastructure, your control
|
||||
|
||||
### 💰 Cost Effective
|
||||
|
||||
- **Competitive pricing** on decentralized infrastructure
|
||||
- **Pay for what you use** - Flexible resource allocation
|
||||
- **No vendor lock-in** - Standard Kubernetes portability
|
||||
- **Global availability** - Deploy where you need
|
||||
|
||||
## Key Features
|
||||
|
||||
| Feature | Description |
|
||||
|---------|-------------|
|
||||
| **K3s Kubernetes** | Lightweight, certified Kubernetes distribution |
|
||||
| **Mycelium Networking** | IPv6 overlay with encrypted P2P connections |
|
||||
| **High Availability** | Multi-master clusters for production workloads |
|
||||
| **Global Nodes** | Deploy across worldwide ThreeFold Grid locations |
|
||||
| **Standard APIs** | Use kubectl, Helm, and all Kubernetes tools |
|
||||
| **Web Dashboard** | Manage clusters through intuitive UI |
|
||||
| **SSH Access** | Direct node access for debugging and management |
|
||||
| **Flexible Sizing** | Custom CPU, RAM, and storage configurations |
|
||||
|
||||
## Architecture
|
||||
|
||||
Mycelium Cloud uses peer-to-peer networking for direct access:
|
||||
|
||||
```
|
||||
┌────────────────┐
|
||||
│ Your Machine │
|
||||
│ (kubectl) │
|
||||
└───────┬────────┘
|
||||
│
|
||||
│ Mycelium Network
|
||||
│ (encrypted P2P)
|
||||
│
|
||||
┌───────▼────────────────────────────────┐
|
||||
│ Kubernetes Cluster │
|
||||
│ ┌──────────┐ ┌──────────┐ │
|
||||
│ │ Master │ │ Worker │ │
|
||||
│ │ Node │ │ Node │ ... │
|
||||
│ └──────────┘ └──────────┘ │
|
||||
└────────────────────────────────────────┘
|
||||
ThreeFold Grid Infrastructure
|
||||
```
|
||||
|
||||
**Network Flow:**
|
||||
- Your machine connects via Mycelium network
|
||||
- Each cluster node has unique Mycelium IPv6 address
|
||||
- All communication encrypted end-to-end
|
||||
- Direct node access - no gateways or proxies
|
||||
|
||||
## Common Use Cases
|
||||
|
||||
### Development & Testing
|
||||
|
||||
- Spin up test clusters quickly
|
||||
- Experiment with Kubernetes features
|
||||
- CI/CD pipeline testing
|
||||
- Multi-environment development
|
||||
|
||||
### Production Workloads
|
||||
|
||||
- Web applications and APIs
|
||||
- Microservices architectures
|
||||
- Databases and stateful services
|
||||
- Background processing jobs
|
||||
|
||||
### Decentralized Applications
|
||||
|
||||
- P2P services
|
||||
- Distributed computing
|
||||
- Edge computing deployments
|
||||
- Privacy-focused applications
|
||||
|
||||
### Learning Kubernetes
|
||||
|
||||
- Hands-on practice
|
||||
- Tutorial environments
|
||||
- Training clusters
|
||||
- Safe experimentation
|
||||
|
||||
## Technology Stack
|
||||
|
||||
**Kubernetes:** K3s v1.26+ (production-ready, lightweight)
|
||||
**Networking:** Mycelium CNI with IPv6 support
|
||||
**Infrastructure:** ThreeFold Grid decentralized nodes
|
||||
**Management:** Web dashboard + API + kubectl
|
||||
|
||||
## What You Get
|
||||
|
||||
When you deploy a cluster:
|
||||
|
||||
- ✅ **Fully configured K3s cluster** - Ready to use
|
||||
- ✅ **Mycelium networking** - Secure connectivity
|
||||
- ✅ **kubeconfig file** - Standard kubectl access
|
||||
- ✅ **SSH access** - Direct node management
|
||||
- ✅ **Dashboard monitoring** - Cluster status and metrics
|
||||
- ✅ **Flexible scaling** - Add/remove nodes as needed
|
||||
|
||||
## Getting Started
|
||||
|
||||
Ready to deploy your first cluster? Here's the path:
|
||||
|
||||
1. **[Getting Started](/mycelium-cloud/getting-started)** - Create account and deploy
|
||||
2. **[Tutorial](/mycelium-cloud/tutorial)** - Deploy your first application
|
||||
|
||||
<div className="info-box">
|
||||
|
||||
### 💡 Prerequisites
|
||||
|
||||
You should have:
|
||||
- **Mycelium installed** - For network access ([Install guide](/mycelium-network/install))
|
||||
- **kubectl installed** - For cluster management ([Install kubectl](https://kubernetes.io/docs/tasks/tools/))
|
||||
- **SSH key** - For node access
|
||||
- **Credits** - To fund your deployments
|
||||
|
||||
</div>
|
||||
|
||||
## Pricing
|
||||
|
||||
Pricing is based on resource usage:
|
||||
- CPU cores
|
||||
- RAM allocation
|
||||
- Storage capacity
|
||||
- Deployment duration
|
||||
|
||||
Check the dashboard for current rates. The decentralized infrastructure typically offers competitive pricing compared to traditional cloud providers.
|
||||
|
||||
## Resources
|
||||
|
||||
- **Dashboard**: [vdc.grid.tf](https://vdc.grid.tf) - Deploy and manage clusters
|
||||
- **Documentation**: [Mycelium Cloud Docs](https://codescalers.github.io/www_kubecloud/)
|
||||
- **Kubernetes Docs**: [kubernetes.io](https://kubernetes.io/docs/)
|
||||
- **Community**: [ThreeFold Telegram](https://t.me/threefoldfarmers)
|
||||
- **GitHub**: [kubecloud repository](https://github.com/codescalers/kubecloud)
|
||||
|
||||
## Comparison to Traditional Cloud
|
||||
|
||||
| Aspect | Mycelium Cloud | Traditional Cloud |
|
||||
|--------|----------------|-------------------|
|
||||
| Infrastructure | Decentralized | Centralized |
|
||||
| Control | Full sovereignty | Vendor-controlled |
|
||||
| Networking | P2P encrypted | Public IPs, gateways |
|
||||
| Pricing | Competitive | Often expensive |
|
||||
| Lock-in | None (standard K8s) | Vendor-specific services |
|
||||
| Privacy | High | Varies by provider |
|
||||
| Setup | Quick & simple | Can be complex |
|
||||
|
||||
---
|
||||
|
||||
:::tip Next Step
|
||||
Ready to deploy? Start with the **[Getting Started Guide](/mycelium-cloud/getting-started)** to create your first cluster.
|
||||
:::
|
||||
579
docs/mycelium-cloud/tutorial.md
Normal file
579
docs/mycelium-cloud/tutorial.md
Normal file
@@ -0,0 +1,579 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
---
|
||||
|
||||
# Deployment Tutorials
|
||||
|
||||
Learn by example with these practical deployment tutorials for Mycelium Cloud.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before starting these tutorials, ensure you have:
|
||||
|
||||
- ✅ Deployed cluster with kubectl access
|
||||
- ✅ Mycelium running for network access
|
||||
- ✅ kubectl configured with your cluster
|
||||
|
||||
```bash
|
||||
# Verify your setup
|
||||
kubectl get nodes
|
||||
|
||||
# Should show your cluster nodes
|
||||
```
|
||||
|
||||
## Tutorial 1: Hello World with Nginx
|
||||
|
||||
Deploy a simple web server to verify your cluster is working.
|
||||
|
||||
### Step 1: Create the Deployment
|
||||
|
||||
Save as `hello-world-deploy.yaml`:
|
||||
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: hello-world
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: hello-world
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: hello-world
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.21
|
||||
ports:
|
||||
- containerPort: 80
|
||||
```
|
||||
|
||||
Apply it:
|
||||
|
||||
```bash
|
||||
kubectl apply -f hello-world-deploy.yaml
|
||||
```
|
||||
|
||||
### Step 2: Expose the Service
|
||||
|
||||
Save as `hello-world-svc.yaml`:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: hello-world-service
|
||||
spec:
|
||||
selector:
|
||||
app: hello-world
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
type: ClusterIP
|
||||
```
|
||||
|
||||
Apply it:
|
||||
|
||||
```bash
|
||||
kubectl apply -f hello-world-svc.yaml
|
||||
```
|
||||
|
||||
### Step 3: Access Your Application
|
||||
|
||||
```bash
|
||||
# Port forward to local machine
|
||||
kubectl port-forward service/hello-world-service 8080:80
|
||||
```
|
||||
|
||||
Open `http://localhost:8080` - you should see the Nginx welcome page!
|
||||
|
||||
### Cleanup
|
||||
|
||||
```bash
|
||||
kubectl delete -f hello-world-deploy.yaml
|
||||
kubectl delete -f hello-world-svc.yaml
|
||||
```
|
||||
|
||||
## Tutorial 2: Python Servers with Load Balancing
|
||||
|
||||
Deploy multiple Python HTTP servers to demonstrate load balancing.
|
||||
|
||||
### Step 1: Create the Deployments
|
||||
|
||||
Save as `python-servers.yaml`:
|
||||
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: python-server-1
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: python-server
|
||||
server-id: "1"
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: python-server
|
||||
server-id: "1"
|
||||
spec:
|
||||
containers:
|
||||
- name: python-server
|
||||
image: python:3.9-slim
|
||||
command: ["python", "-c"]
|
||||
args:
|
||||
- |
|
||||
import http.server, socketserver, json
|
||||
class Handler(http.server.SimpleHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self.end_headers()
|
||||
response = {"server": "Python Server 1", "pod": "$(hostname)"}
|
||||
self.wfile.write(json.dumps(response).encode())
|
||||
with socketserver.TCPServer(("", 8000), Handler) as httpd:
|
||||
httpd.serve_forever()
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: python-server-2
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: python-server
|
||||
server-id: "2"
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: python-server
|
||||
server-id: "2"
|
||||
spec:
|
||||
containers:
|
||||
- name: python-server
|
||||
image: python:3.9-slim
|
||||
command: ["python", "-c"]
|
||||
args:
|
||||
- |
|
||||
import http.server, socketserver, json
|
||||
class Handler(http.server.SimpleHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self.end_headers()
|
||||
response = {"server": "Python Server 2", "pod": "$(hostname)"}
|
||||
self.wfile.write(json.dumps(response).encode())
|
||||
with socketserver.TCPServer(("", 8000), Handler) as httpd:
|
||||
httpd.serve_forever()
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: python-server-3
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: python-server
|
||||
server-id: "3"
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: python-server
|
||||
server-id: "3"
|
||||
spec:
|
||||
containers:
|
||||
- name: python-server
|
||||
image: python:3.9-slim
|
||||
command: ["python", "-c"]
|
||||
args:
|
||||
- |
|
||||
import http.server, socketserver, json
|
||||
class Handler(http.server.SimpleHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self.end_headers()
|
||||
response = {"server": "Python Server 3", "pod": "$(hostname)"}
|
||||
self.wfile.write(json.dumps(response).encode())
|
||||
with socketserver.TCPServer(("", 8000), Handler) as httpd:
|
||||
httpd.serve_forever()
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
```
|
||||
|
||||
### Step 2: Create Load Balancing Service
|
||||
|
||||
Save as `python-lb-service.yaml`:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: python-lb
|
||||
spec:
|
||||
selector:
|
||||
app: python-server
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 8000
|
||||
type: ClusterIP
|
||||
```
|
||||
|
||||
### Step 3: Deploy Everything
|
||||
|
||||
```bash
|
||||
kubectl apply -f python-servers.yaml
|
||||
kubectl apply -f python-lb-service.yaml
|
||||
|
||||
# Wait for pods to be ready
|
||||
kubectl get pods -l app=python-server
|
||||
```
|
||||
|
||||
### Step 4: Test Load Balancing
|
||||
|
||||
```bash
|
||||
# Port forward the service
|
||||
kubectl port-forward service/python-lb 8080:80
|
||||
|
||||
# In another terminal, test the load balancing
|
||||
for i in {1..10}; do
|
||||
curl http://localhost:8080
|
||||
done
|
||||
```
|
||||
|
||||
You'll see responses from different servers and pods, showing the load balancing in action!
|
||||
|
||||
### Cleanup
|
||||
|
||||
```bash
|
||||
kubectl delete -f python-servers.yaml
|
||||
kubectl delete -f python-lb-service.yaml
|
||||
```
|
||||
|
||||
## Tutorial 3: Stateful Application with Persistent Storage
|
||||
|
||||
Deploy a simple application that persists data.
|
||||
|
||||
### Step 1: Create Persistent Volume Claim
|
||||
|
||||
Save as `storage.yaml`:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: data-pvc
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
```
|
||||
|
||||
### Step 2: Create Stateful Deployment
|
||||
|
||||
Save as `stateful-app.yaml`:
|
||||
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: data-app
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: data-app
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: data-app
|
||||
spec:
|
||||
containers:
|
||||
- name: app
|
||||
image: busybox:latest
|
||||
command: ["sh", "-c"]
|
||||
args:
|
||||
- |
|
||||
echo "Starting data application..."
|
||||
while true; do
|
||||
date >> /data/log.txt
|
||||
echo "Written at $(date)" >> /data/log.txt
|
||||
sleep 10
|
||||
done
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: data-pvc
|
||||
```
|
||||
|
||||
### Step 3: Deploy and Verify
|
||||
|
||||
```bash
|
||||
kubectl apply -f storage.yaml
|
||||
kubectl apply -f stateful-app.yaml
|
||||
|
||||
# Wait for pod to be ready
|
||||
kubectl get pods -l app=data-app
|
||||
|
||||
# Check the logs being written
|
||||
kubectl exec -it $(kubectl get pod -l app=data-app -o name) -- cat /data/log.txt
|
||||
```
|
||||
|
||||
### Step 4: Test Persistence
|
||||
|
||||
```bash
|
||||
# Delete the pod
|
||||
kubectl delete pod -l app=data-app
|
||||
|
||||
# Wait for new pod to start
|
||||
kubectl get pods -l app=data-app
|
||||
|
||||
# Check data persisted
|
||||
kubectl exec -it $(kubectl get pod -l app=data-app -o name) -- cat /data/log.txt
|
||||
```
|
||||
|
||||
The data from before the pod deletion should still be there!
|
||||
|
||||
### Cleanup
|
||||
|
||||
```bash
|
||||
kubectl delete -f stateful-app.yaml
|
||||
kubectl delete -f storage.yaml
|
||||
```
|
||||
|
||||
## Tutorial 4: Multi-Tier Application
|
||||
|
||||
Deploy a simple web app with a database backend.
|
||||
|
||||
### Step 1: Deploy Redis Database
|
||||
|
||||
Save as `redis.yaml`:
|
||||
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: redis
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: redis
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: redis
|
||||
spec:
|
||||
containers:
|
||||
- name: redis
|
||||
image: redis:7-alpine
|
||||
ports:
|
||||
- containerPort: 6379
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: redis
|
||||
spec:
|
||||
selector:
|
||||
app: redis
|
||||
ports:
|
||||
- port: 6379
|
||||
targetPort: 6379
|
||||
type: ClusterIP
|
||||
```
|
||||
|
||||
### Step 2: Deploy Frontend Application
|
||||
|
||||
Save as `frontend.yaml`:
|
||||
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: frontend
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: frontend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: frontend
|
||||
spec:
|
||||
containers:
|
||||
- name: frontend
|
||||
image: nginx:alpine
|
||||
ports:
|
||||
- containerPort: 80
|
||||
env:
|
||||
- name: REDIS_HOST
|
||||
value: "redis"
|
||||
- name: REDIS_PORT
|
||||
value: "6379"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: frontend
|
||||
spec:
|
||||
selector:
|
||||
app: frontend
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
type: ClusterIP
|
||||
```
|
||||
|
||||
### Step 3: Deploy and Access
|
||||
|
||||
```bash
|
||||
kubectl apply -f redis.yaml
|
||||
kubectl apply -f frontend.yaml
|
||||
|
||||
# Wait for all pods
|
||||
kubectl get pods
|
||||
|
||||
# Port forward to access frontend
|
||||
kubectl port-forward service/frontend 8080:80
|
||||
```
|
||||
|
||||
Open `http://localhost:8080` to access your multi-tier application.
|
||||
|
||||
### Cleanup
|
||||
|
||||
```bash
|
||||
kubectl delete -f frontend.yaml
|
||||
kubectl delete -f redis.yaml
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Resource Limits
|
||||
|
||||
Always set resource limits:
|
||||
|
||||
```yaml
|
||||
resources:
|
||||
requests:
|
||||
memory: "64Mi"
|
||||
cpu: "250m"
|
||||
limits:
|
||||
memory: "128Mi"
|
||||
cpu: "500m"
|
||||
```
|
||||
|
||||
### Health Checks
|
||||
|
||||
Add liveness and readiness probes:
|
||||
|
||||
```yaml
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 8080
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /ready
|
||||
port: 8080
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
```
|
||||
|
||||
### Labels and Annotations
|
||||
|
||||
Use descriptive labels:
|
||||
|
||||
```yaml
|
||||
metadata:
|
||||
labels:
|
||||
app: myapp
|
||||
version: v1.0
|
||||
environment: production
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Pods Not Starting
|
||||
|
||||
```bash
|
||||
# Check pod status
|
||||
kubectl describe pod <pod-name>
|
||||
|
||||
# Check logs
|
||||
kubectl logs <pod-name>
|
||||
|
||||
# Check events
|
||||
kubectl get events --sort-by='.lastTimestamp'
|
||||
```
|
||||
|
||||
### Service Not Accessible
|
||||
|
||||
```bash
|
||||
# Check service
|
||||
kubectl describe service <service-name>
|
||||
|
||||
# Check endpoints
|
||||
kubectl get endpoints <service-name>
|
||||
|
||||
# Test from within cluster
|
||||
kubectl run -it --rm debug --image=alpine --restart=Never -- sh
|
||||
# Then: wget -O- http://service-name
|
||||
```
|
||||
|
||||
### Resource Issues
|
||||
|
||||
```bash
|
||||
# Check node resources
|
||||
kubectl top nodes
|
||||
|
||||
# Check pod resources
|
||||
kubectl top pods
|
||||
|
||||
# Check resource requests/limits
|
||||
kubectl describe nodes
|
||||
```
|
||||
|
||||
## Next Steps
|
||||
|
||||
Now that you've completed these tutorials:
|
||||
|
||||
- Deploy your own applications
|
||||
- Explore [Helm](https://helm.sh/) for package management
|
||||
- Learn about [Ingress controllers](https://kubernetes.io/docs/concepts/services-networking/ingress/) for advanced routing
|
||||
- Study [StatefulSets](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/) for databases
|
||||
- Explore [ConfigMaps and Secrets](https://kubernetes.io/docs/concepts/configuration/) for configuration management
|
||||
|
||||
## Resources
|
||||
|
||||
- **Kubernetes Documentation**: [kubernetes.io/docs](https://kubernetes.io/docs/)
|
||||
- **kubectl Cheat Sheet**: [kubernetes.io/docs/reference/kubectl/cheatsheet](https://kubernetes.io/docs/reference/kubectl/cheatsheet/)
|
||||
- **Mycelium Cloud FAQ**: [codescalers.github.io/www_kubecloud/faq](https://codescalers.github.io/www_kubecloud/faq)
|
||||
- **Community**: [Telegram](https://t.me/threefoldfarmers)
|
||||
|
||||
---
|
||||
|
||||
:::tip Keep Learning
|
||||
|
||||
These tutorials cover the basics. The real power of Kubernetes comes from combining these concepts to build complex, scalable applications on the ThreeFold Grid!
|
||||
:::
|
||||
Reference in New Issue
Block a user