improved kubernetes example

This commit is contained in:
ghe0 2025-04-01 04:10:59 +03:00
parent 9d4f2fbb12
commit ae3999d4f7
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
4 changed files with 101 additions and 12 deletions

@ -1,4 +1,4 @@
# WireGuard cluster example
# Kubernetes cluster example
This example will create 5 kubernetes nodes using k3s: a master and 4 workers.
All VMs have public IPs, which can be used to publish ports.
@ -8,7 +8,44 @@ To create the VMs, run:
./create_vms.sh
```
And to deploy:
And to deploy Kubernetes:
```
./deploy.sh
```
After this, you can deploy an nginx service to all nodes:
```
./nginx_service.sh
```
## Succesful output
Assuming everything went fine, at the end you should see something like this:
```
daemonset.apps/nginx-daemonset unchanged
service/nginx-service unchanged
NGINX DEPLOYED! PLEASE FIND DETAILS OF PODS AND SERVICES BELOW:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/nginx-daemonset-dr84t 1/1 Running 0 3s 10.42.1.4 k3s-node-4 <none> <none>
pod/nginx-daemonset-lj4tp 1/1 Running 0 3s 10.42.3.5 k3s-node-2 <none> <none>
pod/nginx-daemonset-r4q5n 1/1 Running 0 3s 10.42.4.4 k3s-node-1 <none> <none>
pod/nginx-daemonset-t56dd 1/1 Running 0 3s 10.42.0.9 k3s-master <none> <none>
pod/nginx-daemonset-z5tmn 0/1 Pending 0 3s <none> k3s-node-3 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 2m <none>
service/nginx-service NodePort 10.43.108.125 <none> 80:30080/TCP 3s app=nginx
TO CHECK IF NGINX IS WORKING, USE THE FOLLOWING COMMANDS:
curl http://149.36.48.101:30080
curl http://149.36.48.104:30080
curl http://149.36.48.105:30080
curl http://149.36.48.102:30080
curl http://149.36.48.103:30080
```
## Tutorial
A more elaborate tutorial can be found [in the docs](http://docs.detee.ltd/tutorials/kubernetes).

@ -2,32 +2,32 @@
set -e
mkdir -p tmp
detee-cli vm deploy --hostname k3s-master --vcpus 4 \
--memory 4000 --disk 20 --location Random --public-ip |
detee-cli vm deploy --hostname k3s-master --vcpus 2 \
--memory 3000 --disk 20 --location Random --public-ip |
tail -1 > tmp/master_ssh_command &&
echo "k3s-master successfully created" &
sleep 1
detee-cli vm deploy --hostname k3s-node-1 --vcpus 4 \
--memory 4000 --disk 20 --location Random --public-ip |
detee-cli vm deploy --hostname k3s-node-1 --vcpus 2 \
--memory 3000 --disk 20 --location Random --public-ip |
tail -1 > tmp/node1_ssh_command &&
echo "k3s-node-1 successfully created" &
sleep 1
detee-cli vm deploy --hostname k3s-node-2 --vcpus 4 \
--memory 4000 --disk 20 --location Random --public-ip |
detee-cli vm deploy --hostname k3s-node-2 --vcpus 2 \
--memory 3000 --disk 20 --location Random --public-ip |
tail -1 > tmp/node2_ssh_command &&
echo "k3s-node-2 successfully created" &
sleep 1
detee-cli vm deploy --hostname k3s-node-3 --vcpus 4 \
--memory 4000 --disk 20 --location Random --public-ip |
detee-cli vm deploy --hostname k3s-node-3 --vcpus 2 \
--memory 3000 --disk 20 --location Random --public-ip |
tail -1 > tmp/node3_ssh_command &&
echo "k3s-node-3 successfully created" &
sleep 1
detee-cli vm deploy --hostname k3s-node-4 --vcpus 4 \
--memory 4000 --disk 20 --location Random --public-ip |
detee-cli vm deploy --hostname k3s-node-4 --vcpus 2 \
--memory 3000 --disk 20 --location Random --public-ip |
tail -1 > tmp/node4_ssh_command &&
echo "k3s-node-4 successfully created" &

33
kubernetes/k8s_nginx.yml Normal file

@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nginx-daemonset
labels:
app: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: nginx
ports:
- port: 80
targetPort: 80
nodePort: 30080

19
kubernetes/nginx_service.sh Executable file

@ -0,0 +1,19 @@
#!/bin/bash
ssh_master=$(cat tmp/master_ssh_command)
set -e
cat k8s_nginx.yml | $ssh_master kubectl apply -f -
echo
echo NGINX DEPLOYED! PLEASE FIND DETAILS OF PODS AND SERVICES BELOW:
echo
$ssh_master kubectl get pods,svc -o wide
echo
echo TO CHECK IF NGINX IS WORKING, USE THE FOLLOWING COMMANDS:
grep -r ssh tmp/ | cut -d '@' -f2 |
xargs -i echo " curl http://{}:30080"
echo