actualizacion domingo
This commit is contained in:
35
k8s-external/configmaps/configmap.yaml
Normal file
35
k8s-external/configmaps/configmap.yaml
Normal file
@@ -0,0 +1,35 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: nginx-router-config
|
||||
namespace: external
|
||||
data:
|
||||
router.conf: |
|
||||
server {
|
||||
listen 80 default_server;
|
||||
server_name router.manabo.org;
|
||||
location / {
|
||||
proxy_pass https://192.168.1.1;
|
||||
proxy_ssl_verify off;
|
||||
}
|
||||
}
|
||||
|
||||
ilo1.conf: |
|
||||
server {
|
||||
listen 80;
|
||||
server_name ilo1.manabo.org;
|
||||
location / {
|
||||
proxy_pass https://192.168.0.4;
|
||||
proxy_ssl_verify off;
|
||||
}
|
||||
}
|
||||
|
||||
ilo2.conf: |
|
||||
server {
|
||||
listen 80;
|
||||
server_name ilo2.manabo.org;
|
||||
location / {
|
||||
proxy_pass https://192.168.0.5;
|
||||
proxy_ssl_verify off;
|
||||
}
|
||||
}
|
||||
25
k8s-external/deployments/deployment.yaml
Normal file
25
k8s-external/deployments/deployment.yaml
Normal file
@@ -0,0 +1,25 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: external-router-proxy
|
||||
namespace: external
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: router-proxy
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: router-proxy
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:alpine
|
||||
volumeMounts:
|
||||
- name: nginx-config
|
||||
mountPath: /etc/nginx/conf.d
|
||||
volumes:
|
||||
- name: nginx-config
|
||||
configMap:
|
||||
name: nginx-router-config
|
||||
27
k8s-external/ingress/router.yaml
Normal file
27
k8s-external/ingress/router.yaml
Normal file
@@ -0,0 +1,27 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: router-ingress
|
||||
namespace: external
|
||||
annotations:
|
||||
cert-manager.io/cluster-issuer: "letsencrypt-prod"
|
||||
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
|
||||
nginx.ingress.kubernetes.io/ssl-redirect: "true"
|
||||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||
spec:
|
||||
ingressClassName: nginx
|
||||
tls:
|
||||
- hosts:
|
||||
- router.manabo.org
|
||||
secretName: router-tls
|
||||
rules:
|
||||
- host: router.manabo.org
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: external-router-svc
|
||||
port:
|
||||
number: 80
|
||||
10
k8s-external/kustomization.yaml
Normal file
10
k8s-external/kustomization.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
resources:
|
||||
- namespace.yaml
|
||||
- configmaps/configmap.yaml
|
||||
- deployments/deployment.yaml
|
||||
- services/service.yaml
|
||||
- ingress/router.yaml
|
||||
|
||||
5
k8s-external/namespace.yaml
Normal file
5
k8s-external/namespace.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: external
|
||||
|
||||
166
k8s-external/readme.md
Normal file
166
k8s-external/readme.md
Normal file
@@ -0,0 +1,166 @@
|
||||
# 🌐 k8s-external-router
|
||||
|
||||
Este proyecto despliega un proxy inverso en Kubernetes que permite acceder a dispositivos o servicios externos (fuera del clúster) mediante dominios públicos gestionados con TLS, a través de NGINX y cert-manager.
|
||||
|
||||
## 📝 Componentes
|
||||
|
||||
* **Deployment**: contenedor `nginx:alpine` que actúa como proxy.
|
||||
* **ConfigMap**: define los proxies en archivos `.conf` cargados en `/etc/nginx/conf.d`.
|
||||
* **Service**: expone el contenedor internamente en el clúster.
|
||||
* **Ingress**: gestiona el acceso externo con certificados TLS (Let’s Encrypt).
|
||||
|
||||
## 💠 Estructura del proyecto
|
||||
|
||||
```bash
|
||||
k8s-external/
|
||||
├── configmaps/
|
||||
│ └── configmap.yaml # Configuración de NGINX
|
||||
├── deployments/
|
||||
│ └── deployment.yaml # Proxy con hostNetwork
|
||||
├── services/
|
||||
│ └── service.yaml # Service interno
|
||||
├── ingress/
|
||||
│ └── router.yaml # Ingress TLS público
|
||||
```
|
||||
|
||||
## 🚀 Despliegue
|
||||
|
||||
1. Aplica todos los recursos:
|
||||
|
||||
```bash
|
||||
kubectl apply -k .
|
||||
```
|
||||
|
||||
> Asegúrate de que tu clúster ya tenga:
|
||||
>
|
||||
> * `cert-manager` instalado.
|
||||
> * Un `ClusterIssuer` llamado `letsencrypt-prod`.
|
||||
> * Un controlador Ingress funcionando (por ejemplo, `nginx`).
|
||||
|
||||
2. Reinicia el deployment para recargar cambios del `ConfigMap`:
|
||||
|
||||
```bash
|
||||
kubectl rollout restart deployment external-router-proxy -n external
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ➕ Añadir un nuevo proxy
|
||||
|
||||
Para añadir un nuevo dominio que apunte a una IP externa:
|
||||
|
||||
### 1. Edita el `ConfigMap`
|
||||
|
||||
```yaml
|
||||
switch.conf: |
|
||||
server {
|
||||
listen 80;
|
||||
server_name switch.manabo.org;
|
||||
location / {
|
||||
proxy_pass https://192.168.0.100;
|
||||
proxy_ssl_verify off;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> Guarda el archivo como `configmaps/configmap.yaml`.
|
||||
|
||||
### 2. Aplica el nuevo `ConfigMap` y reinicia el deployment
|
||||
|
||||
```bash
|
||||
kubectl apply -f configmaps/configmap.yaml
|
||||
kubectl rollout restart deployment external-router-proxy -n external
|
||||
```
|
||||
|
||||
### 3. Crea un nuevo `Ingress`
|
||||
|
||||
Guarda este archivo en `ingress/switch.yaml`:
|
||||
|
||||
```yaml
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: switch-ingress
|
||||
namespace: external
|
||||
annotations:
|
||||
cert-manager.io/cluster-issuer: "letsencrypt-prod"
|
||||
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
|
||||
spec:
|
||||
ingressClassName: nginx
|
||||
tls:
|
||||
- hosts:
|
||||
- switch.manabo.org
|
||||
secretName: switch-tls
|
||||
rules:
|
||||
- host: switch.manabo.org
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: external-router-svc
|
||||
port:
|
||||
number: 80
|
||||
```
|
||||
|
||||
Y aplícalo:
|
||||
|
||||
```bash
|
||||
kubectl apply -f ingress/switch.yaml
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔍 Verificación
|
||||
|
||||
* Verifica que el pod proxy esté funcionando:
|
||||
|
||||
```bash
|
||||
kubectl get pods -n external
|
||||
```
|
||||
|
||||
* Verifica que el endpoint externo responde desde dentro del contenedor:
|
||||
|
||||
```bash
|
||||
kubectl exec -n external deploy/external-router-proxy -- curl -k https://192.168.X.X
|
||||
```
|
||||
|
||||
* Verifica que el dominio esté expuesto correctamente:
|
||||
|
||||
```bash
|
||||
curl -k https://switch.manabo.org
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔐 Seguridad
|
||||
|
||||
* Los proxys usan certificados TLS automáticos con Let’s Encrypt.
|
||||
* La verificación de certificados en el `proxy_pass` está desactivada (`proxy_ssl_verify off`) para permitir certificados autofirmados de los dispositivos.
|
||||
|
||||
---
|
||||
|
||||
## 🗜 Limpieza
|
||||
|
||||
Para eliminar un proxy:
|
||||
|
||||
1. Borra la entrada del `ConfigMap`.
|
||||
2. Borra el `Ingress` correspondiente:
|
||||
|
||||
```bash
|
||||
kubectl delete ingress switch-ingress -n external
|
||||
```
|
||||
|
||||
3. Vuelve a aplicar y reiniciar:
|
||||
|
||||
```bash
|
||||
kubectl apply -f configmaps/configmap.yaml
|
||||
kubectl rollout restart deployment external-router-proxy -n external
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✨ Créditos
|
||||
|
||||
Mantenido por [Xavor](https://manabo.org) — Kubernetes DevOps Homelab.
|
||||
11
k8s-external/services/service.yaml
Normal file
11
k8s-external/services/service.yaml
Normal file
@@ -0,0 +1,11 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: external-router-svc
|
||||
namespace: external
|
||||
spec:
|
||||
selector:
|
||||
app: router-proxy
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
Reference in New Issue
Block a user