|
1 | 1 | # K8s DevMachine |
2 | 2 |
|
3 | | -A containerized development environment for Kubernetes that provides a VM-like dev experience with SSH access. |
| 3 | +Containerized development environment for Kubernetes with SSH access. Perfect for VS Code Remote SSH development. |
4 | 4 |
|
5 | 5 | ## ✨ Features |
6 | 6 |
|
7 | | -- **Complete development toolkit** with pre-installed tools: |
8 | | - - Terraform |
9 | | - - Packer |
10 | | - - Ansible with Python libraries |
11 | | - - Git, Vim, SSH utilities |
12 | | - - MinIO Client |
13 | | -- **SSH access** on port 2222 |
| 7 | +- **Development Tools**: Terraform, Packer, Ansible, Python 3, Git, Vim |
| 8 | +- **System Tools**: htop, tmux, mc, mcli (minio cli), curl, jq, ping, dig, dmidecode, lshw |
| 9 | +- **Cloud Tools**: MinIO Client, SSH server with key-based auth |
| 10 | +- **VS Code Remote SSH ready** - full IDE experience |
| 11 | +- **Go development support** - easily install Go SDK |
14 | 12 | - **Persistent storage** for home directory |
15 | | -- **Secure configuration** with non-root user |
16 | | -- **Python virtual environment** auto-activated |
17 | | -- **Customizable SSH keys** via ConfigMap |
| 13 | +- **Non-root user** (UID 1001) with auto-activated Python venv |
18 | 14 |
|
19 | 15 | ## 🚀 Quick Start |
20 | 16 |
|
21 | | -### Prerequisites |
22 | | - |
23 | | -- Kubernetes cluster (>= 1.20) |
24 | | -- Helm 3.x |
25 | | -- Storage class (Longhorn recommended) |
26 | | -- LoadBalancer support (for external access) |
27 | | - |
28 | | -### Installation |
29 | | - |
30 | | -1. **Clone the repository** |
31 | 17 | ```bash |
| 18 | +# 1. Clone repo |
32 | 19 | git clone https://github.com/syntax3rror404/k8s-devmachine.git |
33 | 20 | cd k8s-devmachine |
34 | | -``` |
35 | | - |
36 | | -2. **Configure SSH keys** |
37 | | -Edit `chart/values.yaml` and add your public SSH keys: |
38 | 21 |
|
39 | | -```yaml |
| 22 | +# 2. Add your SSH keys to chart/values.yaml |
40 | 23 | ssh: |
41 | 24 | authorizedKeys: | |
42 | 25 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC... user@hostname |
43 | | - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... user@hostname |
44 | | -``` |
45 | 26 |
|
46 | | -3. **Deploy with Helm** |
47 | | -```bash |
| 27 | +# 3. Deploy |
48 | 28 | helm install devmachine ./chart |
49 | | -``` |
50 | 29 |
|
51 | | -4. **Get external IP and connect** |
52 | | -```bash |
| 30 | +# 4. Connect |
53 | 31 | kubectl get svc devmachine-service |
54 | 32 | ssh -p 2222 dev@<EXTERNAL-IP> |
55 | 33 | ``` |
56 | 34 |
|
57 | | -## 🔧 Configuration |
58 | | - |
59 | | -### values.yaml |
60 | | - |
61 | | -```yaml |
62 | | -replicaCount: 1 |
63 | | - |
64 | | -image: |
65 | | - source: ghcr.io/syntax3rror404/k8s-devmachine@sha256:... |
66 | | - pullPolicy: IfNotPresent |
67 | | - |
68 | | -service: |
69 | | - type: LoadBalancer |
70 | | - port: 2222 |
71 | | - targetPort: 2222 |
72 | | - |
73 | | -persistence: |
74 | | - enabled: true |
75 | | - size: 10Gi |
76 | | - storageClass: "longhorn" |
| 35 | +## 💻 VS Code Remote SSH |
77 | 36 |
|
78 | | -ssh: |
79 | | - authorizedKeys: | |
80 | | - # Add your SSH public keys here |
| 37 | +1. Install "Remote - SSH" extension in VS Code |
| 38 | +2. Add to `~/.ssh/config`: |
81 | 39 | ``` |
82 | | -
|
83 | | -### Resource limits (optional) |
84 | | -
|
85 | | -```yaml |
86 | | -resources: |
87 | | - requests: |
88 | | - memory: "512Mi" |
89 | | - cpu: "250m" |
90 | | - limits: |
91 | | - memory: "2Gi" |
92 | | - cpu: "1000m" |
| 40 | +Host k8s-devmachine |
| 41 | + HostName <EXTERNAL-IP> |
| 42 | + Port 2222 |
| 43 | + User dev |
93 | 44 | ``` |
| 45 | +3. Connect via VS Code: `Ctrl+Shift+P` → "Remote-SSH: Connect to Host" |
94 | 46 |
|
95 | | -## 🔐 Access |
| 47 | +## 🛠️ Install Additional Tools |
96 | 48 |
|
97 | | -### SSH Connection |
| 49 | +### Go Installation |
98 | 50 | ```bash |
99 | | -# Get external IP |
100 | | -EXTERNAL_IP=$(kubectl get svc devmachine-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}') |
101 | | - |
102 | | -# Connect via SSH |
103 | | -ssh -p 2222 dev@$EXTERNAL_IP |
| 51 | +ssh -p 2222 dev@<EXTERNAL-IP> |
| 52 | +cd /tmp |
| 53 | +wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz |
| 54 | +tar -xzf go1.21.5.linux-amd64.tar.gz |
| 55 | +mv go ~/bin/ |
| 56 | +go version # Already in PATH |
104 | 57 | ``` |
105 | 58 |
|
106 | | -### Port Forwarding (alternative) |
| 59 | +### Node.js |
107 | 60 | ```bash |
108 | | -kubectl port-forward svc/devmachine-service 2222:2222 |
109 | | -ssh -p 2222 dev@localhost |
| 61 | +curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - |
| 62 | +sudo apt-get install -y nodejs |
110 | 63 | ``` |
111 | 64 |
|
112 | | -## 📁 Container Structure |
113 | | - |
114 | | -``` |
115 | | -/home/dev/ |
116 | | -├── .ssh/authorized_keys # Your SSH keys |
117 | | -├── .bashrc # Shell configuration |
118 | | -├── venv/ # Python virtual environment |
119 | | -├── ssh_keys/ # SSH host keys (persistent) |
120 | | -└── run/ # Runtime files |
121 | | -``` |
122 | | - |
123 | | -## 🛠️ Development |
124 | | - |
125 | | -### Building the image |
126 | | - |
127 | | -The container image is automatically built via GitHub Actions on push to master branch. |
| 65 | +## 🔧 Configuration |
128 | 66 |
|
129 | | -For local development: |
130 | | -```bash |
131 | | -docker build -t k8s-devmachine . |
132 | | -docker run -p 2222:2222 k8s-devmachine |
| 67 | +Key `values.yaml` options: |
| 68 | +```yaml |
| 69 | +replicaCount: 1 |
| 70 | +service: |
| 71 | + type: LoadBalancer # or NodePort |
| 72 | + port: 2222 |
| 73 | +persistence: |
| 74 | + size: 10Gi |
| 75 | + storageClass: "longhorn" |
| 76 | +ssh: |
| 77 | + authorizedKeys: | |
| 78 | + # Your SSH public keys here |
133 | 79 | ``` |
134 | 80 |
|
135 | | -### Installed Tools |
| 81 | +## 🔐 Access Options |
136 | 82 |
|
137 | | -- **Infrastructure**: Terraform, Packer, TF-Helper |
138 | | -- **Configuration Management**: Ansible with extensive Python libraries |
139 | | -- **Utilities**: Git, Vim, curl, jq, openssh, MinIO client |
140 | | -- **System Tools**: ping, dig, dmidecode, lshw |
| 83 | +**SSH Direct**: `ssh -p 2222 dev@<EXTERNAL-IP>` |
| 84 | +**Port Forward**: `kubectl port-forward svc/devmachine-service 2222:2222` |
| 85 | +**NodePort**: `kubectl patch svc devmachine-service -p '{"spec":{"type":"NodePort"}}'` |
141 | 86 |
|
142 | 87 | ## 🐛 Troubleshooting |
143 | 88 |
|
144 | | -### Common Issues |
145 | | - |
146 | | -**SSH connection refused** |
147 | 89 | ```bash |
148 | | -# Check pod status |
| 90 | +# Check status |
149 | 91 | kubectl get pods -l app=devmachine |
150 | | - |
151 | | -# View logs |
152 | 92 | kubectl logs -l app=devmachine |
153 | 93 |
|
154 | | -# Debug inside pod |
155 | | -kubectl exec -it devmachine-0 -- /bin/bash |
156 | | -``` |
157 | | - |
158 | | -**LoadBalancer pending** |
159 | | -```bash |
160 | | -# Use NodePort instead |
161 | | -kubectl patch svc devmachine-service -p '{"spec":{"type":"NodePort"}}' |
162 | | - |
163 | | -# Or use port-forwarding |
164 | | -kubectl port-forward svc/devmachine-service 2222:2222 |
165 | | -``` |
166 | | - |
167 | | -**Storage issues** |
168 | | -```bash |
169 | | -# Check storage class |
170 | | -kubectl get storageclass |
| 94 | +# Debug connection |
| 95 | +kubectl exec -it devmachine-0 -- ss -tuln | grep 2222 |
171 | 96 |
|
172 | | -# Check PVC status |
| 97 | +# Storage issues |
173 | 98 | kubectl get pvc |
| 99 | +kubectl describe pvc home-volume-devmachine-0 |
174 | 100 | ``` |
175 | 101 |
|
176 | | -### Debug Commands |
| 102 | +## 📁 Directory Structure |
177 | 103 |
|
178 | | -```bash |
179 | | -# Check service endpoints |
180 | | -kubectl get endpoints devmachine-service |
181 | | - |
182 | | -# Describe pod for events |
183 | | -kubectl describe pod devmachine-0 |
184 | | - |
185 | | -# Test SSH service inside pod |
186 | | -kubectl exec devmachine-0 -- ss -tuln | grep 2222 |
187 | | -``` |
188 | | - |
189 | | -## 📊 Operations |
190 | | - |
191 | | -### Backup |
192 | | -```bash |
193 | | -# Backup home directory |
194 | | -kubectl exec devmachine-0 -- tar czf - /home/dev > backup.tar.gz |
195 | | - |
196 | | -# Restore |
197 | | -kubectl exec -i devmachine-0 -- tar xzf - -C / < backup.tar.gz |
198 | 104 | ``` |
199 | | - |
200 | | -### Updates |
201 | | -```bash |
202 | | -# Update image tag in values.yaml, then: |
203 | | -helm upgrade devmachine ./chart |
204 | | - |
205 | | -# Rolling restart |
206 | | -kubectl rollout restart statefulset/devmachine |
207 | | -``` |
208 | | - |
209 | | -### Scaling |
210 | | -```bash |
211 | | -# Scale to multiple instances |
212 | | -helm upgrade devmachine ./chart --set replicaCount=3 |
| 105 | +/home/dev/ |
| 106 | +├── .ssh/authorized_keys # SSH keys |
| 107 | +├── venv/ # Python venv (auto-activated) |
| 108 | +├── bin/ # Your binaries or optional bin/go installation |
| 109 | +└── projects/ # Your code |
213 | 110 | ``` |
214 | 111 |
|
215 | 112 | ## 🔒 Security |
216 | 113 |
|
217 | | -- Runs as non-root user (UID 1001) |
218 | | -- Password authentication disabled |
219 | | -- Key-based SSH authentication only |
| 114 | +- Non-root user (UID 1001) |
| 115 | +- Key-based SSH only |
220 | 116 | - Seccomp profile enabled |
221 | | -- Read-only root filesystem (where possible) |
222 | | - |
223 | | -## 🤝 Contributing |
224 | | - |
225 | | -1. Fork the repository |
226 | | -2. Create a feature branch (`git checkout -b feature/amazing-feature`) |
227 | | -3. Commit your changes (`git commit -m 'Add amazing feature'`) |
228 | | -4. Push to the branch (`git push origin feature/amazing-feature`) |
229 | | -5. Open a Pull Request |
230 | | - |
231 | | -## 🙏 Acknowledgments |
232 | | - |
233 | | -- Built with Debian Bookworm Slim |
234 | | -- Uses HashiCorp tools (Terraform, Packer) |
235 | | -- Ansible automation platform |
236 | | -- Kubernetes community |
| 117 | +- No privilege escalation |
237 | 118 |
|
238 | 119 | --- |
239 | 120 |
|
240 | | -> **Note**: This development machine is designed for development and testing purposes. Consider additional security measures for production environments. |
| 121 | +Perfect for remote development with persistent storage and full tool access with VSCode! |
0 commit comments