añadidos archivos de wireguard
This commit is contained in:
BIN
cephrook.pdf
BIN
cephrook.pdf
Binary file not shown.
BIN
cluster_init.pdf
BIN
cluster_init.pdf
Binary file not shown.
Binary file not shown.
@@ -8,7 +8,7 @@ controller:
|
|||||||
service:
|
service:
|
||||||
enabled: true
|
enabled: true
|
||||||
type: LoadBalancer
|
type: LoadBalancer
|
||||||
loadBalancerIP: 192.168.1.100
|
loadBalancerIP: 192.168.0.101
|
||||||
ports:
|
ports:
|
||||||
http:
|
http:
|
||||||
port: 80
|
port: 80
|
||||||
|
|||||||
BIN
kubevirt.pdf
BIN
kubevirt.pdf
Binary file not shown.
Binary file not shown.
28
wireguard/daemonset/iptables-daemonset.yaml
Normal file
28
wireguard/daemonset/iptables-daemonset.yaml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: DaemonSet
|
||||||
|
metadata:
|
||||||
|
name: wg-nat-rules
|
||||||
|
namespace: wireguard
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: wg-nat-rules
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: wg-nat-rules
|
||||||
|
spec:
|
||||||
|
hostNetwork: true
|
||||||
|
containers:
|
||||||
|
- name: iptables
|
||||||
|
image: alpine:latest
|
||||||
|
securityContext:
|
||||||
|
privileged: true
|
||||||
|
command:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- |
|
||||||
|
sysctl -w net.ipv4.ip_forward=1
|
||||||
|
iptables -t nat -C POSTROUTING -s 192.168.254.0/24 -d 192.168.0.0/24 -j MASQUERADE || iptables -t nat -A POSTROUTING -s 192.168.254.0/24 -d 192.168.0.0/24 -j MASQUERADE
|
||||||
|
iptables -t nat -C POSTROUTING -s 192.168.254.0/24 -d 10.42.0.0/16 -j MASQUERADE || iptables -t nat -A POSTROUTING -s 192.168.254.0/24 -d 10.42.0.0/16 -j MASQUERADE
|
||||||
|
sleep infinity
|
||||||
49
wireguard/deployments/deployment.yaml
Normal file
49
wireguard/deployments/deployment.yaml
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: wg-easy
|
||||||
|
namespace: wireguard
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: wg-easy
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: wg-easy
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: wg-easy
|
||||||
|
image: ghcr.io/wg-easy/wg-easy
|
||||||
|
env:
|
||||||
|
- name: WG_HOST
|
||||||
|
value: "wireguard.c2et.net"
|
||||||
|
- name: WG_PORT
|
||||||
|
value: "51819"
|
||||||
|
- name: WG_DEFAULT_ADDRESS
|
||||||
|
value: "192.168.254.x"
|
||||||
|
- name: WG_DEFAULT_ALLOWEDIPS
|
||||||
|
value: "192.168.0.0/24,10.42.0.0/16"
|
||||||
|
- name: WG_DEFAULT_DNS
|
||||||
|
value: "192.168.0.1"
|
||||||
|
- name: PASSWORD_HASH
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: wg-easy-secret
|
||||||
|
key: PASSWORD_HASH
|
||||||
|
ports:
|
||||||
|
- containerPort: 51819
|
||||||
|
protocol: UDP
|
||||||
|
- containerPort: 51821
|
||||||
|
protocol: TCP
|
||||||
|
volumeMounts:
|
||||||
|
- name: config
|
||||||
|
mountPath: /etc/wireguard
|
||||||
|
securityContext:
|
||||||
|
capabilities:
|
||||||
|
add: ["NET_ADMIN", "SYS_MODULE"]
|
||||||
|
volumes:
|
||||||
|
- name: config
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: wg-easy-config
|
||||||
26
wireguard/ingress/ingress.yaml
Normal file
26
wireguard/ingress/ingress.yaml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: wg-easy-web
|
||||||
|
namespace: wireguard
|
||||||
|
annotations:
|
||||||
|
cert-manager.io/cluster-issuer: "letsencrypt-prod"
|
||||||
|
nginx.ingress.kubernetes.io/ssl-redirect: "true"
|
||||||
|
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
|
||||||
|
spec:
|
||||||
|
ingressClassName: nginx
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- wireguard.c2et.net
|
||||||
|
secretName: wg-easy-tls
|
||||||
|
rules:
|
||||||
|
- host: wireguard.c2et.net
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: wg-easy-web
|
||||||
|
port:
|
||||||
|
number: 51821
|
||||||
9
wireguard/kustomization.yaml
Normal file
9
wireguard/kustomization.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
resources:
|
||||||
|
- namespace.yaml
|
||||||
|
- pvc/pvc.yaml
|
||||||
|
- secret.yaml
|
||||||
|
- deployments/deployment.yaml
|
||||||
|
- services/service-tcp.yaml
|
||||||
|
- services/service-udp.yaml
|
||||||
|
- daemonset/iptables-daemonset.yaml
|
||||||
|
- ingress/ingress.yaml
|
||||||
4
wireguard/namespace.yaml
Normal file
4
wireguard/namespace.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: wireguard
|
||||||
12
wireguard/pvc/pvc.yaml
Normal file
12
wireguard/pvc/pvc.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: wg-easy-config
|
||||||
|
namespace: wireguard
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 1Gi
|
||||||
|
storageClassName: ceph-rbd
|
||||||
159
wireguard/readme.md
Normal file
159
wireguard/readme.md
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
# WireGuard en Kubernetes (wg-easy)
|
||||||
|
|
||||||
|
Este despliegue proporciona acceso VPN mediante **WireGuard** dentro de un clúster Kubernetes, utilizando la imagen `wg-easy`, expuesto por un `Service` tipo `NodePort` y gestionado con reglas de `iptables` en el host.
|
||||||
|
|
||||||
|
## 🔐 ¿Qué es WireGuard?
|
||||||
|
|
||||||
|
WireGuard es un protocolo de VPN moderno, rápido y seguro, que utiliza criptografía de última generación para establecer túneles cifrados entre dispositivos.
|
||||||
|
|
||||||
|
Este despliegue usa `wg-easy`, una interfaz web y API para administrar fácilmente instancias de WireGuard.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚖️ Estructura del despliegue
|
||||||
|
|
||||||
|
```
|
||||||
|
.
|
||||||
|
├── daemonset
|
||||||
|
│ └── iptables-daemonset.yaml # Reglas de NAT
|
||||||
|
├── deployments
|
||||||
|
│ └── deployment.yaml # Despliegue de wg-easy
|
||||||
|
├── ingress
|
||||||
|
│ └── ingress.yaml # (opcional)
|
||||||
|
├── pvc
|
||||||
|
│ └── pvc.yaml # Configuración persistente
|
||||||
|
├── services
|
||||||
|
│ └── service.yaml # Service tipo NodePort
|
||||||
|
├── secret.yaml # HASH de contraseña para interfaz web
|
||||||
|
├── namespace.yaml
|
||||||
|
└── kustomization.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚫 Seguridad y acceso
|
||||||
|
|
||||||
|
### Contraseña
|
||||||
|
|
||||||
|
Para acceder a la interfaz web protegida de wg-easy, se define un `Secret` con un hash de contraseña.
|
||||||
|
|
||||||
|
Puedes generar el hash con `htpasswd` (instalado con `apache2-utils`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
apt install apache2-utils
|
||||||
|
htpasswd -nBC 10 "admin"
|
||||||
|
```
|
||||||
|
|
||||||
|
Copia el resultado (sin el `admin:`) en el archivo `secret.yaml` como `PASSWORD_HASH`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📁 Volúmenes
|
||||||
|
|
||||||
|
La configuración de WireGuard se guarda en `/etc/wireguard` dentro del contenedor. Esto se monta con un `PersistentVolumeClaim` para que los peers se conserven aunque se reinicie el pod.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛂 Puertos y exposición
|
||||||
|
|
||||||
|
El `Service` es tipo `NodePort`, lo que significa:
|
||||||
|
|
||||||
|
* Puerto del contenedor WireGuard: `51820/UDP`
|
||||||
|
* Puerto de la interfaz web: `51821/TCP`
|
||||||
|
* Puerto `NodePort` expuesto:
|
||||||
|
|
||||||
|
* UDP: `31820` (WireGuard)
|
||||||
|
* TCP: `31821` (Interfaz Web)
|
||||||
|
|
||||||
|
Los `NodePort` deben estar en el rango 30000–32767 (por defecto en Kubernetes).
|
||||||
|
|
||||||
|
El router debe redirigir estos puertos al nodo donde corre `wg-easy`.
|
||||||
|
|
||||||
|
Ejemplo de reenvío:
|
||||||
|
|
||||||
|
* `31820/UDP` → nodo `tartaro`, puerto `31820`
|
||||||
|
* `31821/TCP` → nodo `tartaro`, puerto `31821`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 Reenvío de tráfico y NAT
|
||||||
|
|
||||||
|
WireGuard entrega a los clientes direcciones como `192.168.200.x`, pero por defecto no tendrían acceso a otras redes como:
|
||||||
|
|
||||||
|
* Red de administración: `192.168.1.0/24`
|
||||||
|
* Red de pods (Flannel): `10.42.0.0/16`
|
||||||
|
* Red Multus (ejemplo): `192.168.201.0/24`
|
||||||
|
|
||||||
|
Para ello, se despliega un `DaemonSet` que aplica reglas `iptables` directamente en el host físico:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
iptables -t nat -A POSTROUTING -s 192.168.200.0/24 -d 192.168.1.0/24 -j MASQUERADE
|
||||||
|
iptables -t nat -A POSTROUTING -s 192.168.200.0/24 -d 10.42.0.0/16 -j MASQUERADE
|
||||||
|
```
|
||||||
|
|
||||||
|
Con esto, los paquetes generados por los clientes WireGuard se traducen a la IP del host, y así acceden a otras redes internas.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠️ Acceso a redes aisladas con Multus
|
||||||
|
|
||||||
|
Si se desea permitir acceso a una red definida por un `NetworkAttachmentDefinition` (NAD) con Multus, como por ejemplo:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: "k8s.cni.cncf.io/v1"
|
||||||
|
kind: NetworkAttachmentDefinition
|
||||||
|
metadata:
|
||||||
|
name: br-servicios
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
config: '{
|
||||||
|
"cniVersion": "0.3.1",
|
||||||
|
"type": "bridge",
|
||||||
|
"bridge": "br-servicios",
|
||||||
|
"ipam": {
|
||||||
|
"type": "host-local",
|
||||||
|
"subnet": "192.168.201.0/24",
|
||||||
|
"rangeStart": "192.168.201.100",
|
||||||
|
"rangeEnd": "192.168.201.199"
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
Entonces basta con añadir una regla más en el `DaemonSet`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
iptables -t nat -A POSTROUTING -s 192.168.200.0/24 -d 192.168.201.0/24 -j MASQUERADE
|
||||||
|
```
|
||||||
|
|
||||||
|
No es necesario conectar el contenedor de wg-easy directamente a esta red: el tráfico se enruta y NATea desde el host físico.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 Reaplicar cambios
|
||||||
|
|
||||||
|
Siempre que modifiques el `DaemonSet` o el `Deployment`, puedes aplicar los cambios con:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl apply -k .
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✨ Resultado
|
||||||
|
|
||||||
|
Una vez desplegado y con el reenvío del router correctamente configurado, puedes acceder a la interfaz web en:
|
||||||
|
|
||||||
|
```
|
||||||
|
https://manabo.org:31821
|
||||||
|
```
|
||||||
|
|
||||||
|
Y configurar tus clientes WireGuard escaneando el QR generado, o descargando el archivo de configuración.
|
||||||
|
|
||||||
|
Los clientes podrán acceder a:
|
||||||
|
|
||||||
|
* `192.168.1.0/24` (red local)
|
||||||
|
* `10.42.0.0/16` (pods del clúster)
|
||||||
|
* `192.168.201.0/24` (red multus, si se añade la regla correspondiente)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
8
wireguard/secret.yaml
Normal file
8
wireguard/secret.yaml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: wg-easy-secret
|
||||||
|
namespace: wireguard
|
||||||
|
type: Opaque
|
||||||
|
stringData:
|
||||||
|
PASSWORD_HASH: "$2y$10$zsEKyp1SjKQO0.KKX/.0dueSxrPRVIDp0Zqg47zp0zOckuT/gRsLu"
|
||||||
14
wireguard/services/service-tcp.yaml
Normal file
14
wireguard/services/service-tcp.yaml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: wg-easy-web
|
||||||
|
namespace: wireguard
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
selector:
|
||||||
|
app: wg-easy
|
||||||
|
ports:
|
||||||
|
- name: web
|
||||||
|
port: 51821
|
||||||
|
targetPort: 51821
|
||||||
|
protocol: TCP
|
||||||
15
wireguard/services/service-udp.yaml
Normal file
15
wireguard/services/service-udp.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: wg-easy-udp
|
||||||
|
namespace: wireguard
|
||||||
|
spec:
|
||||||
|
type: LoadBalancer
|
||||||
|
loadBalancerIP: 192.168.0.101
|
||||||
|
selector:
|
||||||
|
app: wg-easy
|
||||||
|
ports:
|
||||||
|
- name: wireguard-udp
|
||||||
|
port: 51819
|
||||||
|
targetPort: 51819
|
||||||
|
protocol: UDP
|
||||||
Reference in New Issue
Block a user