diff --git a/coredns/configmap.yaml b/coredns/configmap.yaml new file mode 100644 index 0000000..eb91e06 --- /dev/null +++ b/coredns/configmap.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: coredns-config + namespace: coredns-multus +data: + Corefile: | + .:53 { + log + errors + forward . 8.8.8.8 + cache 30 + hosts { + 192.168.0.41 apolo.c2et.com + fallthrough + } + } diff --git a/coredns/deployment.yaml b/coredns/deployment.yaml new file mode 100644 index 0000000..6e0ddcc --- /dev/null +++ b/coredns/deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: v1 +kind: Pod +metadata: + name: coredns-multus + namespace: coredns-multus + annotations: + k8s.v1.cni.cncf.io/networks: | + [ + { "name": "br-admin", "namespace": "kube-system" }, + { "name": "br-srv", "namespace": "kube-system" } + ] +spec: + hostNetwork: true + containers: + - name: coredns + image: coredns/coredns:1.11.1 + volumeMounts: + - name: config-volume + mountPath: /etc/coredns/Corefile + subPath: Corefile + ports: + - containerPort: 53 + protocol: UDP + - containerPort: 53 + protocol: TCP + volumes: + - name: config-volume + configMap: + name: coredns-config + tolerations: + - operator: "Exists" + dnsPolicy: "Default" diff --git a/coredns/namespace.yaml b/coredns/namespace.yaml new file mode 100644 index 0000000..c1eefa3 --- /dev/null +++ b/coredns/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: coredns-multus diff --git a/coredns/net-attach-def-admin.yaml b/coredns/net-attach-def-admin.yaml new file mode 100644 index 0000000..8140712 --- /dev/null +++ b/coredns/net-attach-def-admin.yaml @@ -0,0 +1,20 @@ +apiVersion: "k8s.cni.cncf.io/v1" +kind: NetworkAttachmentDefinition +metadata: + name: br-admin + namespace: coredns-multus +spec: + config: '{ + "cniVersion": "0.3.1", + "type": "bridge", + "bridge": "br-admin", + "ipam": { + "type": "static", + "addresses": [ + { + "address": "192.168.1.100/24", + "gateway": "192.168.1.1" + } + ] + } + }' diff --git a/coredns/net-attach-def-srv.yaml b/coredns/net-attach-def-srv.yaml new file mode 100644 index 0000000..68dfe10 --- /dev/null +++ b/coredns/net-attach-def-srv.yaml @@ -0,0 +1,20 @@ +apiVersion: "k8s.cni.cncf.io/v1" +kind: NetworkAttachmentDefinition +metadata: + name: br-srv + namespace: coredns-multus +spec: + config: '{ + "cniVersion": "0.3.1", + "type": "bridge", + "bridge": "br-srv", + "ipam": { + "type": "static", + "addresses": [ + { + "address": "192.168.200.100/22", + "gateway": "192.168.200.1" + } + ] + } + }' diff --git a/multus/readme.md b/multus/readme.md new file mode 100644 index 0000000..cfdead7 --- /dev/null +++ b/multus/readme.md @@ -0,0 +1,162 @@ +# CoreDNS con Multus: README de Configuración + +Este documento explica cómo desplegar un pod de CoreDNS en Kubernetes con **Multus CNI** para conectarlo a dos redes físicas (bridges) distintas, asignándole una dirección IP en cada una, y usando `hostNetwork` para exponer el servicio DNS de forma estándar en el host. + +--- + +## Objetivo + +* Desplegar CoreDNS con: + + * IP 192.168.1.100/24 en la red **br-admin** + * IP 192.168.200.100/22 en la red **br-srv** +* Utilizar `hostNetwork: true` para que CoreDNS escuche en el puerto 53 real del host +* Añadir un sidecar de herramientas para inspección de red + +--- + +## ¿Por qué Multus? + +* Kubernetes estándar solo permite una interfaz por pod (la principal). +* Multus permite añadir interfaces **adicionales**, conectando el pod a varias redes físicas (como bridges de Linux). +* En este caso, usamos Multus para asignar a CoreDNS dos IPs fijas en dos bridges diferentes, actuando como DNS en ambas redes. + +--- + +## Componentes principales + +1. **NetworkAttachmentDefinition** para cada bridge físico: + + * `br-admin` (192.168.1.0/24) + * `br-srv` (192.168.200.0/22) +2. **ConfigMap** con el `Corefile` (configuración de CoreDNS) +3. **Pod** con: + + * `hostNetwork: true` + * Anotación Multus para conectar ambas redes + * Sidecar de utilidades (`busybox`) + +--- + +## Paso a paso + +### 1. NetworkAttachmentDefinition + +Define una NetworkAttachmentDefinition por red, ejemplo: + +`br-admin.yaml`: + +```yaml +apiVersion: "k8s.cni.cncf.io/v1" +kind: NetworkAttachmentDefinition +metadata: + name: br-admin + namespace: coredns-multus +spec: + config: '{ + "cniVersion": "0.3.1", + "type": "bridge", + "bridge": "br-admin", + "ipam": { + "type": "static", + "addresses": [ + { + "address": "192.168.1.100/24", + "gateway": "192.168.1.1" + } + ] + } + }' +``` + +`br-srv.yaml` igual, cambiando nombre y dirección IP. + +--- + +### 2. ConfigMap con Corefile + +Ejemplo: + +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: coredns-config + namespace: coredns-multus +data: + Corefile: | + .:53 { + log + errors + forward . 8.8.8.8 + cache 30 + } +``` + +--- + +### 3. Pod con Multus y sidecar de utilidades + +```yaml +apiVersion: v1 +kind: Pod +metadata: + name: coredns-multus + namespace: coredns-multus + annotations: + k8s.v1.cni.cncf.io/networks: | + [ + { "name": "br-admin", "namespace": "coredns-multus" }, + { "name": "br-srv", "namespace": "coredns-multus" } + ] +spec: + hostNetwork: true + containers: + - name: coredns + image: coredns/coredns:1.11.1 + volumeMounts: + - name: config-volume + mountPath: /etc/coredns/Corefile + subPath: Corefile + ports: + - containerPort: 53 + protocol: UDP + - containerPort: 53 + protocol: TCP + - name: tools + image: busybox + command: [ "sleep", "infinity" ] + volumes: + - name: config-volume + configMap: + name: coredns-config + tolerations: + - operator: "Exists" + dnsPolicy: "Default" +``` + +--- + +## Comprobación de las interfaces + +Para ver las interfaces asignadas por Multus: + +```sh +kubectl -n coredns-multus exec -it coredns-multus -c tools -- ip a +``` + +Deberías ver: + +* La interfaz principal (del host, por `hostNetwork`) +* Una interfaz extra con IP 192.168.1.100 +* Otra interfaz extra con IP 192.168.200.100 + +--- + +## Notas importantes + +* `hostNetwork: true` expone el puerto 53 real en el host. +* La IP principal será la del host, las secundarias las de Multus. +* Puedes poner el pod en modo Deployment para alta disponibilidad, pero solo una instancia por host con `hostNetwork: true`. +* El sidecar puede eliminarse después de la verificación, no es necesario para producción. +