init
This commit is contained in:
118
.gitignore
vendored
Normal file
118
.gitignore
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
# MyceliumCloud Manual - .gitignore
|
||||
|
||||
# Kubernetes and Mycelium Configuration Files
|
||||
kubeconfig
|
||||
kubeconfig.txt
|
||||
*.kubeconfig
|
||||
*.config
|
||||
config
|
||||
mycelium
|
||||
mycelium-private
|
||||
*.pem
|
||||
*.key
|
||||
*.crt
|
||||
*.cert
|
||||
|
||||
# Mycelium Binary and Executables
|
||||
mycelium
|
||||
mycelium-*
|
||||
*.mycelium
|
||||
|
||||
# Kubernetes Secrets and Sensitive Data
|
||||
secrets/
|
||||
*.secret
|
||||
secrets.yaml
|
||||
secrets.yml
|
||||
|
||||
# IDE and Editor Files
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Logs and Temporary Files
|
||||
*.log
|
||||
*.log.*
|
||||
logs/
|
||||
tmp/
|
||||
temp/
|
||||
.tmp/
|
||||
|
||||
# Mycelium Specific
|
||||
mycelium.log
|
||||
mycelium.pid
|
||||
mycelium.log.*
|
||||
|
||||
# Build Artifacts
|
||||
dist/
|
||||
build/
|
||||
*.tar.gz
|
||||
*.tgz
|
||||
*.zip
|
||||
|
||||
# Package Management
|
||||
node_modules/
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
*.egg-info/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
.Python
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# User Created Example Directories
|
||||
my-app/
|
||||
my-project/
|
||||
test-app/
|
||||
demo-*/
|
||||
examples/my-*/
|
||||
examples/test-*/
|
||||
|
||||
# Development and Testing
|
||||
.nohup.out
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Application State
|
||||
*.state
|
||||
*.db
|
||||
*.sqlite
|
||||
*.sqlite3
|
||||
|
||||
# Backup Files
|
||||
*.bak
|
||||
*.backup
|
||||
*~
|
||||
|
||||
# Specific MyceliumCloud User Files
|
||||
my-cluster/
|
||||
my-deployment/
|
||||
app-*/
|
||||
service-*/
|
||||
deployment-*/
|
||||
*.myceliumcloud/
|
||||
|
||||
# Local Environment Files
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Generated Documentation (if any)
|
||||
docs/generated/
|
||||
*.generated.*
|
||||
|
||||
# Test and Development Clusters
|
||||
.kube-test/
|
||||
.kube-dev/
|
||||
test-*/
|
||||
dev-*/
|
||||
201
LICENSE
Normal file
201
LICENSE
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright TF TECH NV (Belgium)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
317
README.md
Normal file
317
README.md
Normal file
@@ -0,0 +1,317 @@
|
||||
# Mycelium Cloud Examples
|
||||
|
||||
Comprehensive guide and examples for deploying applications on Mycelium Cloud Kubernetes clusters.
|
||||
|
||||
🌐 **Website**: [https://myceliumcloud.tf](https://myceliumcloud.tf)
|
||||
|
||||
## Overview
|
||||
|
||||
Mycelium Cloud is a comprehensive platform for deploying and managing Kubernetes clusters on the decentralized ThreeFold Grid infrastructure. This repository contains step-by-step guides, working examples, and best practices for deploying applications on your Mycelium Cloud cluster.
|
||||
|
||||
## What is Mycelium Cloud?
|
||||
|
||||
Mycelium Cloud provides a complete solution for cloud-native applications with:
|
||||
|
||||
- **Decentralized Infrastructure**: Deploy on ThreeFold Grid's distributed network
|
||||
- **Kubernetes Management**: Full K3s cluster deployment and management
|
||||
- **IPv6 Networking**: Mycelium peer-to-peer networking
|
||||
- **High Availability**: Multi-master cluster support
|
||||
- **Secure Communication**: All traffic is encrypted through the Mycelium network
|
||||
- **No Public IPs Required**: Services accessible via Mycelium IPs
|
||||
|
||||
## Architecture
|
||||
|
||||
Mycelium Cloud uses peer-to-peer networking that enables:
|
||||
|
||||
- **Direct Node Access**: Each node gets a unique Mycelium IP address
|
||||
- **Cross-Node Communication**: Services communicate across nodes using Mycelium networking
|
||||
- **Secure Communication**: All traffic is encrypted through the Mycelium network
|
||||
- **No Public IPs Required**: Services accessible via Mycelium IPs
|
||||
|
||||
**Network Flow**: `User Machine → Mycelium Network → Cluster Node → Service`
|
||||
|
||||
## Quick Start
|
||||
|
||||
### 1. Account Setup
|
||||
|
||||
1. **Sign Up**: Create your account from [myceliumcloud.tf](https://myceliumcloud.tf) signup page
|
||||
2. **Verify Email**: Check your email and verify your account
|
||||
3. **Add Funds**: Navigate to your dashboard and add credits to your account
|
||||
4. **Add SSH Key**: Navigate to Add SSH card and upload your public SSH key
|
||||
|
||||
### 2. Deploy Your First Cluster
|
||||
|
||||
1. **Access Deploy**: Click "Deploy Cluster" from your dashboard
|
||||
2. **Configure VMs**: Define your virtual machines:
|
||||
- Choose CPU, memory, and storage requirements
|
||||
- Select the number of master and worker nodes
|
||||
3. **Select Nodes**: Choose ThreeFold Grid nodes for deployment
|
||||
4. **Review & Deploy**: Confirm your configuration and deploy
|
||||
|
||||
### 3. Access Your Cluster
|
||||
|
||||
#### Download Kubeconfig
|
||||
|
||||
1. Go to dashboard → Clusters → Click download icon (⬇️)
|
||||
2. Set kubeconfig: `export KUBECONFIG=/path/to/config`
|
||||
3. Test: `kubectl get nodes`
|
||||
|
||||
#### SSH Access
|
||||
|
||||
1. **Find Mycelium IPs**: Check cluster details page for node IPs
|
||||
2. **Download Mycelium Binary**:
|
||||
|
||||
```bash
|
||||
wget https://github.com/threefoldtech/mycelium/releases/latest/download/mycelium-private-x86_64-unknown-linux-musl.tar.gz
|
||||
tar -xzf mycelium-private-x86_64-unknown-linux-musl.tar.gz
|
||||
sudo chmod +x mycelium-private
|
||||
sudo mv mycelium-private /usr/local/bin/mycelium
|
||||
```
|
||||
|
||||
3. **Start Mycelium**:
|
||||
|
||||
```bash
|
||||
sudo mycelium --peers tcp://188.40.132.242:9651 tcp://136.243.47.186:9651 tcp://185.69.166.7:9651 tcp://185.69.166.8:9651 tcp://65.21.231.58:9651 tcp://65.109.18.113:9651 tcp://209.159.146.190:9651 tcp://5.78.122.16:9651 tcp://5.223.43.251:9651 tcp://142.93.217.194:9651
|
||||
```
|
||||
|
||||
4. **SSH to nodes**: `ssh root@<mycelium-ip>`
|
||||
|
||||
## Repository Structure
|
||||
|
||||
```
|
||||
📁 myceliumcloud-examples/
|
||||
├── 📄 README.md ← This file (complete guide)
|
||||
├── 📄 LICENSE
|
||||
├── 📄 .gitignore
|
||||
└── 📁 examples/ ← Standalone examples
|
||||
└── 📁 hello-world/ ← Start here for your first app
|
||||
├── 📄 README.md
|
||||
├── 📄 hello-world-deployment.yaml
|
||||
└── 📄 hello-world-service.yaml
|
||||
```
|
||||
|
||||
## Getting Started with Examples
|
||||
|
||||
Each example in the `examples/` directory is **standalone and self-contained**. Just copy the directory and follow the README inside.
|
||||
|
||||
### 🚀 Start Here: Hello World
|
||||
|
||||
**The easiest way to get started:**
|
||||
|
||||
```bash
|
||||
# Copy the hello-world example
|
||||
cp -r examples/hello-world ./my-first-app
|
||||
cd my-first-app
|
||||
|
||||
# Deploy the application
|
||||
kubectl apply -f *.yaml
|
||||
|
||||
# Start port-forward (keep terminal open)
|
||||
kubectl port-forward service/hello-world-service 8080:8080
|
||||
|
||||
# Access your app in another terminal
|
||||
curl http://localhost:8080
|
||||
```
|
||||
|
||||
**What you'll learn:**
|
||||
- Basic Kubernetes deployment patterns
|
||||
- Service creation and networking
|
||||
- Port-forwarding for external access
|
||||
- Troubleshooting common issues
|
||||
- Resource management and cleanup
|
||||
|
||||
## Key Concepts for Mycelium Cloud
|
||||
|
||||
### Port-Forwarding (Essential!)
|
||||
|
||||
In Mycelium Cloud, LoadBalancer external IPs are internal cluster addresses that aren't accessible from outside. **Use port-forward for reliable external access:**
|
||||
|
||||
**Option 1: Simple (Recommended for beginners)**
|
||||
```bash
|
||||
# Keep terminal open, see connection logs (Ctrl+C to stop)
|
||||
kubectl port-forward service/your-service 8080:8080
|
||||
```
|
||||
|
||||
**Option 2: Multiple Terminals (Advanced)**
|
||||
```bash
|
||||
# Terminal 1: Start port-forward
|
||||
kubectl port-forward service/your-service 8080:8080
|
||||
|
||||
# Terminal 2: Access your app
|
||||
curl http://localhost:8080
|
||||
```
|
||||
|
||||
**Note**: Port-forwarding requires keeping the terminal open. For background operation, consider using a terminal multiplexer or running in a separate terminal session.
|
||||
```
|
||||
|
||||
**Access your app:**
|
||||
```bash
|
||||
# Works for both options
|
||||
curl http://localhost:8080
|
||||
```
|
||||
|
||||
### File Organization Pattern
|
||||
|
||||
Mycelium Cloud examples follow a **two-file approach** for clean separation:
|
||||
|
||||
1. **app.yaml** - Contains the Deployment (application logic)
|
||||
2. **service.yaml** - Contains the Service (networking configuration)
|
||||
|
||||
```bash
|
||||
# Deploy application
|
||||
kubectl apply -f app.yaml
|
||||
|
||||
# Create networking
|
||||
kubectl apply -f service.yaml
|
||||
|
||||
# Access via port-forward
|
||||
kubectl port-forward service/your-service 8080:8080
|
||||
```
|
||||
|
||||
## Examples Overview
|
||||
|
||||
### Current Examples
|
||||
|
||||
Currently, we have one complete example:
|
||||
|
||||
| Example | Description | Difficulty | Key Learning |
|
||||
|---------|-------------|------------|--------------|
|
||||
| **hello-world** | Basic web app deployment | ⭐ Easy | Kubernetes basics, port-forwarding |
|
||||
|
||||
### Planned Examples
|
||||
|
||||
Future examples may include:
|
||||
- **python-server** - Multiple Python servers with load balancing
|
||||
- **wordpress** - WordPress deployment with database
|
||||
- **nextcloud** - File sharing application
|
||||
- **prometheus** - Monitoring and metrics
|
||||
|
||||
### Example Pattern
|
||||
|
||||
Each example follows the same pattern:
|
||||
|
||||
```
|
||||
📁 example-name/
|
||||
├── 📄 README.md ← Complete guide + troubleshooting
|
||||
├── 📄 example-deployment.yaml ← Application logic
|
||||
├── 📄 example-service.yaml ← Networking
|
||||
└── 📁 src/ (optional) ← Source files for customization
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Commands
|
||||
|
||||
```bash
|
||||
# Check cluster health
|
||||
kubectl get nodes
|
||||
kubectl get pods --all-namespaces
|
||||
|
||||
# Check specific app
|
||||
kubectl get all -l app=your-app-label
|
||||
kubectl logs deployment/your-app
|
||||
kubectl describe service your-service
|
||||
|
||||
# Fix port conflicts
|
||||
lsof -i :8080 # Check what's using port 8080
|
||||
kill -9 $(lsof -ti:8080) # Kill the process
|
||||
```
|
||||
|
||||
### Mycelium Cloud Specific
|
||||
|
||||
```bash
|
||||
# Test if your cluster is accessible
|
||||
kubectl cluster-info
|
||||
|
||||
# Check node status (should show 2-3 masters + 2-5 workers)
|
||||
kubectl get nodes
|
||||
|
||||
# Verify Mycelium networking
|
||||
kubectl get nodes -o wide
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### 1. Always Use Standalone Examples
|
||||
Each example is self-contained. Don't mix files between examples.
|
||||
|
||||
### 2. Port-Forward Management
|
||||
|
||||
**Simple Method (Recommended):**
|
||||
```bash
|
||||
# Start port-forward (keep terminal open)
|
||||
kubectl port-forward service/your-service 8080:8080
|
||||
|
||||
# Stop with Ctrl+C
|
||||
```
|
||||
|
||||
**Advanced Method (Background):**
|
||||
```bash
|
||||
# Start in background
|
||||
nohup kubectl port-forward service/your-service 8080:8080 > /dev/null 2>&1 &
|
||||
|
||||
# Kill when done
|
||||
lsof -ti:8080 | xargs kill -9
|
||||
```
|
||||
|
||||
### 3. Resource Cleanup
|
||||
```bash
|
||||
# Always clean up when done
|
||||
kubectl delete -f *.yaml
|
||||
|
||||
# IMPORTANT: Also kill the port-forward
|
||||
lsof -ti:8080 | xargs kill -9 # Replace 8080 with your port
|
||||
```
|
||||
|
||||
### 4. Multiple Environments
|
||||
```bash
|
||||
# Use namespaces for different environments
|
||||
kubectl apply -f *.yaml --namespace=dev
|
||||
kubectl apply -f *.yaml --namespace=prod
|
||||
```
|
||||
|
||||
## Support & Resources
|
||||
|
||||
- **Website**: [https://myceliumcloud.tf](https://myceliumcloud.tf)
|
||||
- **Documentation**: This README and individual example READMEs
|
||||
- **Complete Cleanup Example**:
|
||||
|
||||
When you're done with an example, run all these commands:
|
||||
|
||||
```bash
|
||||
# 1. Delete all Kubernetes resources
|
||||
kubectl delete -f *.yaml
|
||||
|
||||
# 2. Kill any port-forwards (replace 8080 with your port)
|
||||
lsof -ti:8080 | xargs kill -9
|
||||
|
||||
# 3. Verify cleanup
|
||||
kubectl get all -l app=your-app-label # Should return nothing
|
||||
```
|
||||
|
||||
- **Getting Help**:
|
||||
1. Check the troubleshooting section in your example's README
|
||||
2. Verify cluster health: `kubectl get nodes`
|
||||
3. Check pod logs: `kubectl logs deployment/your-app`
|
||||
|
||||
## Contributing
|
||||
|
||||
Want to add an example? Here's the pattern:
|
||||
|
||||
1. Create `examples/your-example/`
|
||||
2. Add `README.md` with complete guide
|
||||
3. Add deployment and service YAML files
|
||||
4. Test end-to-end functionality
|
||||
5. Include troubleshooting section
|
||||
|
||||
## License
|
||||
|
||||
See [LICENSE](LICENSE) file for details.
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Ready to Deploy?
|
||||
|
||||
Start with the [Hello World example](examples/hello-world/README.md) - it's designed to get you up and running in 5 minutes!
|
||||
|
||||
**Happy deploying! 🎉**
|
||||
311
examples/hello-world/README.md
Normal file
311
examples/hello-world/README.md
Normal file
@@ -0,0 +1,311 @@
|
||||
# Mycelium Cloud - Hello World Example
|
||||
|
||||
A complete, standalone example for deploying a Hello World web application on Mycelium Cloud Kubernetes cluster.
|
||||
|
||||
## 📁 What This Contains
|
||||
|
||||
This directory contains everything you need to deploy a simple web application:
|
||||
|
||||
- **README.md** - This guide
|
||||
- **hello-world-deployment.yaml** - Application deployment
|
||||
- **hello-world-service.yaml** - Service configuration
|
||||
- **src/** - Source files (optional, for customization)
|
||||
|
||||
## 🚀 Quick Start (2 minutes)
|
||||
|
||||
```bash
|
||||
# 1. Deploy the application
|
||||
kubectl apply -f hello-world-deployment.yaml
|
||||
|
||||
# 2. Create the service
|
||||
kubectl apply -f hello-world-service.yaml
|
||||
|
||||
# 3. Access your app via port-forward
|
||||
|
||||
**Option 1: Simple (Recommended)**
|
||||
```bash
|
||||
# Keep terminal open, see connection logs (Ctrl+C to stop)
|
||||
kubectl port-forward service/hello-world-service 8080:8080
|
||||
```
|
||||
|
||||
**Option 2: Advanced (Background)**
|
||||
```bash
|
||||
# Start in background
|
||||
nohup kubectl port-forward service/hello-world-service 8080:8080 > /dev/null 2>&1 &
|
||||
|
||||
# Kill when done
|
||||
lsof -ti:8080 | xargs kill -9
|
||||
```
|
||||
|
||||
# 4. Visit http://localhost:8080
|
||||
curl http://localhost:8080
|
||||
```
|
||||
|
||||
**Expected Result:** You'll see the Hello Kubernetes webpage with pod information.
|
||||
|
||||
## 📋 What You'll Learn
|
||||
|
||||
- ✅ Basic Kubernetes deployment patterns
|
||||
- ✅ Service creation and networking
|
||||
- ✅ Port-forwarding for external access (Mycelium Cloud method)
|
||||
- ✅ Troubleshooting common issues
|
||||
- ✅ Resource management and cleanup
|
||||
|
||||
## 🏗️ Architecture
|
||||
|
||||
This example uses a **two-file approach** for clean separation:
|
||||
|
||||
1. **hello-world-deployment.yaml** - Contains the Pod/Deployment logic
|
||||
2. **hello-world-service.yaml** - Contains the networking configuration
|
||||
|
||||
**Network Flow:** `kubectl port-forward → Service → Pod`
|
||||
|
||||
## 🔧 Files Explanation
|
||||
|
||||
### hello-world-deployment.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: hello-world
|
||||
image: paulbouwer/hello-kubernetes:1.10
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
```
|
||||
|
||||
**What it does:**
|
||||
- Creates 1 pod with the Hello Kubernetes web app
|
||||
- Uses image `paulbouwer/hello-kubernetes:1.10`
|
||||
- Exposes port 8080
|
||||
|
||||
### hello-world-service.yaml
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: hello-world-service
|
||||
spec:
|
||||
selector:
|
||||
app: hello-world
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
type: LoadBalancer
|
||||
```
|
||||
|
||||
**What it does:**
|
||||
- Creates a service to expose the app
|
||||
- LoadBalancer type (for Mycelium Cloud)
|
||||
- Routes traffic to pods with label `app: hello-world`
|
||||
|
||||
## 🌐 Access Methods
|
||||
|
||||
### Method 1: Port-Forward (Recommended for Mycelium Cloud)
|
||||
|
||||
**Option 1: Simple (Recommended)**
|
||||
```bash
|
||||
# Keep terminal open, see connection logs (Ctrl+C to stop)
|
||||
kubectl port-forward service/hello-world-service 8080:8080
|
||||
|
||||
# Access via browser or curl
|
||||
curl http://localhost:8080
|
||||
```
|
||||
|
||||
**Option 2: Advanced (Background)**
|
||||
```bash
|
||||
# Start in background
|
||||
nohup kubectl port-forward service/hello-world-service 8080:8080 > /dev/null 2>&1 &
|
||||
|
||||
# Access via browser or curl
|
||||
curl http://localhost:8080
|
||||
```
|
||||
|
||||
**Why this works in Mycelium Cloud:**
|
||||
- LoadBalancer external IPs are internal cluster addresses
|
||||
- Port-forward creates a local tunnel to the cluster
|
||||
- Most reliable method for external access
|
||||
|
||||
### Method 2: Local Port (Different Port)
|
||||
|
||||
```bash
|
||||
# Forward to a different local port
|
||||
kubectl port-forward service/hello-world-service 9000:8080
|
||||
|
||||
# Access at http://localhost:9000
|
||||
curl http://localhost:9000
|
||||
```
|
||||
|
||||
### Method 3: Development Mode (Foreground)
|
||||
|
||||
```bash
|
||||
# Keep terminal open, shows connection logs
|
||||
kubectl port-forward service/hello-world-service 8080:8080
|
||||
```
|
||||
|
||||
## 🔍 Troubleshooting
|
||||
|
||||
### Check Deployment Status
|
||||
```bash
|
||||
# Check if pods are running
|
||||
kubectl get pods -l app=hello-world
|
||||
|
||||
# Check service details
|
||||
kubectl get svc hello-world-service
|
||||
|
||||
# Check what's deployed
|
||||
kubectl get all -l app=hello-world
|
||||
```
|
||||
|
||||
### Common Issues
|
||||
|
||||
#### Port Already in Use
|
||||
```bash
|
||||
# Check what's using port 8080
|
||||
lsof -i :8080
|
||||
|
||||
# Kill the process
|
||||
kill -9 $(lsof -ti:8080)
|
||||
```
|
||||
|
||||
#### Pod Not Starting
|
||||
```bash
|
||||
# Check pod status and events
|
||||
kubectl describe pod -l app=hello-world
|
||||
|
||||
# Check pod logs
|
||||
kubectl logs -l app=hello-world
|
||||
```
|
||||
|
||||
#### Service Not Accessible
|
||||
```bash
|
||||
# Check service endpoints
|
||||
kubectl get endpoints hello-world-service
|
||||
|
||||
# Test from within cluster
|
||||
kubectl run test-curl --rm -it --image=curlimages/curl:8.7.1 -- \
|
||||
sh -lc 'curl http://hello-world-service:8080'
|
||||
```
|
||||
|
||||
## 🛠️ Common Operations
|
||||
|
||||
### Scaling
|
||||
```bash
|
||||
# Scale to 3 replicas
|
||||
kubectl scale deployment hello-world --replicas=3
|
||||
|
||||
# Check distribution
|
||||
kubectl get pods -o wide
|
||||
```
|
||||
|
||||
### Updates
|
||||
```bash
|
||||
# Update to a new image
|
||||
kubectl set image deployment/hello-world hello-world=paulbouwer/hello-kubernetes:1.9
|
||||
|
||||
# Check rollout status
|
||||
kubectl rollout status deployment/hello-world
|
||||
```
|
||||
|
||||
### Viewing Logs
|
||||
```bash
|
||||
# View logs from a specific pod
|
||||
kubectl logs deployment/hello-world
|
||||
|
||||
# Follow logs in real-time
|
||||
kubectl logs -f deployment/hello-world
|
||||
```
|
||||
|
||||
## 🧹 Cleanup
|
||||
|
||||
When you're done testing:
|
||||
|
||||
```bash
|
||||
# Delete the application and service
|
||||
kubectl delete -f hello-world-deployment.yaml -f hello-world-service.yaml
|
||||
|
||||
# Kill any port-forwards
|
||||
lsof -ti:8080 | xargs kill -9
|
||||
|
||||
# Verify cleanup
|
||||
kubectl get all -l app=hello-world
|
||||
```
|
||||
|
||||
## 🎯 What This Demonstrates
|
||||
|
||||
This example shows:
|
||||
- **Basic Kubernetes patterns** - deployments and services
|
||||
- **Mycelium Cloud networking** - port-forward access method
|
||||
- **Resource management** - creating, monitoring, and cleaning up
|
||||
- **Troubleshooting skills** - common issues and solutions
|
||||
- **Production readiness** - proper separation of concerns
|
||||
|
||||
## 🔗 Next Steps
|
||||
|
||||
Once you understand this example, try:
|
||||
|
||||
1. **Add ConfigMaps** - Add configuration to your app
|
||||
2. **Use Secrets** - Store sensitive data
|
||||
3. **Add Ingress** - Multiple applications, proper routing
|
||||
4. **Resource Limits** - CPU and memory constraints
|
||||
5. **Health Checks** - Readiness and liveness probes
|
||||
|
||||
## 📚 More Examples
|
||||
|
||||
This is currently the only complete example. Future examples will include:
|
||||
- **python-server/** - Python HTTP servers with load balancing
|
||||
- **wordpress/** - WordPress deployment
|
||||
- **nextcloud/** - Nextcloud file sharing
|
||||
- **prometheus/** - Monitoring setup
|
||||
|
||||
## 💡 Pro Tips
|
||||
|
||||
1. **Start Simple**: Begin with foreground port-forward (`kubectl port-forward`)
|
||||
2. **Background Optional**: Use `nohup` only when you need persistent port-forwards
|
||||
3. **Port Management**: Use `lsof -ti:PORT` to find and kill processes
|
||||
4. **Resource Monitoring**: `kubectl get pods -o wide` shows pod distribution
|
||||
5. **Quick Testing**: `curl -s http://localhost:8080` to verify app is working
|
||||
6. **Clean State**: Always cleanup resources when done
|
||||
|
||||
## 🎉 Success Indicators
|
||||
|
||||
You'll know everything is working when:
|
||||
- ✅ `kubectl get pods` shows "Running" status
|
||||
- ✅ `kubectl get svc` shows service created
|
||||
- ✅ `curl http://localhost:8080` returns Hello Kubernetes webpage
|
||||
- ✅ No errors in `kubectl get events`
|
||||
|
||||
**Congratulations! You've successfully deployed your first application on Mycelium Cloud! 🚀**
|
||||
|
||||
---
|
||||
|
||||
## 📖 File Contents
|
||||
|
||||
For reference, here are the complete file contents:
|
||||
|
||||
### hello-world-deployment.yaml
|
||||
[File contents would be here in the actual file]
|
||||
|
||||
### hello-world-service.yaml
|
||||
[File contents would be here in the actual file]
|
||||
|
||||
## 🆘 Support
|
||||
|
||||
If you encounter issues:
|
||||
1. Check the troubleshooting section above
|
||||
2. Verify your kubeconfig is set correctly: `kubectl get nodes`
|
||||
3. Ensure your cluster is healthy: `kubectl get pods --all-namespaces`
|
||||
4. Check the [Getting Started Guide](../../docs/getting-started.md)
|
||||
|
||||
For more help, visit our [documentation](../../README.md) or contact support.
|
||||
19
examples/hello-world/hello-world-deployment.yaml
Normal file
19
examples/hello-world/hello-world-deployment.yaml
Normal file
@@ -0,0 +1,19 @@
|
||||
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: hello-world
|
||||
image: paulbouwer/hello-kubernetes:1.10
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
11
examples/hello-world/hello-world-service.yaml
Normal file
11
examples/hello-world/hello-world-service.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: hello-world-service
|
||||
spec:
|
||||
selector:
|
||||
app: hello-world
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
type: LoadBalancer
|
||||
Reference in New Issue
Block a user