Skip to main content

Solución de problemas

image.png

Pod Temporal

Para pruebas de conectividad y resolución DNS puede ser muy útil un POD desde el ejecutar herramientas de diagnostico

Con herramientas básicas (Alpine Linux)

kubectl run -it --rm network-tester \
  --image=alpine/curl \
  --restart=Never \
  -- sh

Una vez dentro del pod, ejecuta pruebas:

# Instala herramientas (ping, dig, etc.)
apk add --no-cache bind-tools iputils

# Prueba DNS
nslookup google.com
dig google.com

# Prueba conectividad HTTP
curl -v https://google.com

# Prueba ping (si el clúster lo permite)
ping google.com

# Prueba puertos TCP (ejemplo: HTTP)
nc -zv google.com 80

Con todas las herramientas preinstaladas (Debian)

apiVersion: v1
kind: Pod
metadata:
  name: network-tester
spec:
  containers:
  - name: network-tester
    image: debian:latest
    command: ["sleep", "3600"]  # Mantiene el pod activo 1 hora
    resources:
      requests:
        cpu: "100m"
        memory: "100Mi"

Aplica y accede al pod:

kubectl apply -f network-tester.yaml
kubectl exec -it network-tester -- bash

Dentro del pod, instala herramientas y ejecuta pruebas:

# Instala utilidades
apt update && apt install -y \
  dnsutils \    # dig, nslookup
  iputils-ping \ # ping
  curl \
  netcat-openbsd # nc

# Pruebas
ping google.com
dig google.com
curl -I https://google.com
nc -zv google.com 443

Si el pod no puede resolver DNS:

Verifica el DNS del clúster:

kubectl get pods -n kube-system -l k8s-app=kube-dns
Prueba con un DNS público (ej: Google DNS):
kubectl exec -it network-tester -- sh -c "echo 'nameserver 8.8.8.8' > /etc/resolv.conf"

Eliminar el pod después de usar:

kubectl delete pod network-tester

Verificar el DNS configurado en los pods

Los pods heredan el DNS del nodo (definido en /etc/resolv.conf del nodo) o usan el servicio kube-dns (IP del cluster).
Para ver la IP del servicio DNS del clúster:

kubectl get svc -n kube-system -l k8s-app=kube-dns

Ejemplo de salida:

NAME       TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)         AGE
kube-dns   ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP   5d
  • La IP 10.96.0.10 debe estar en el /etc/resolv.conf de los pods.

  • Verifica el resolv.conf de un pod:

    kubectl exec -it tu-pod -- cat /etc/resolv.conf

    Debe incluir:

    nameserver 10.96.0.10  # IP del servicio kube-dns
    search default.svc.cluster.local svc.cluster.local cluster.local # no debe aparecer otro dominio
    options ndots:5