0

I'm using microk8s installed on my ubuntu server. and I try to ping outside from my pod

I have docker installed on my machine: when I run a container with docker I can ping outside :

~$ sudo ip addr show docker0
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:a7:9f:15:48 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:a7ff:fe8f:1548/64 scope link
       valid_lft forever preferred_lft forever

on the container :

~$ sudo docker run --rm -it ubuntu:trusty bash
root@dd0af86b1209:/# ip addr show eth0
158: eth0@if159: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
root@dd0af86b1209:/# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
158: eth0@if159: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
root@dd0af86b1209:/# ping google.com
PING google.com (142.250.179.110) 56(84) bytes of data.
64 bytes from par21s20-in-f14.1e100.net (142.250.179.110): icmp_seq=1 ttl=108 time=3.71 ms
64 bytes from par21s20-in-f14.1e100.net (142.250.179.110): icmp_seq=2 ttl=108 time=3.70 ms
64 bytes from par21s20-in-f14.1e100.net (142.250.179.110): icmp_seq=3 ttl=108 time=3.74 ms
64 bytes from par21s20-in-f14.1e100.net (142.250.179.110): icmp_seq=4 ttl=108 time=3.75 ms
64 bytes from par21s20-in-f14.1e100.net (142.250.179.110): icmp_seq=5 ttl=108 time=3.76 ms

but on my pod with microk8s I can't ping outside :

/ # ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
3: eth0@if146: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1440 qdisc noqueue state UP
    link/ether ba:03:bd:4b:66:97 brd ff:ff:ff:ff:ff:ff
    inet 172.17.159.19/32 brd 172.17.159.19 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::b803:bdff:fe44:6697/64 scope link
       valid_lft forever preferred_lft forever

/ # ping google.com
ping: bad address 'google.com'

ufw status :

Anywhere (v6) on cali+     ALLOW       Anywhere (v6)
Anywhere (v6) on cni0      ALLOW       Anywhere (v6)
Anywhere (v6) on cbr0      ALLOW       Anywhere (v6)
Anywhere (v6) on eth0      ALLOW       Anywhere (v6)

EDIT :

I tried to ping IP addresses and it worked, the problem is with hostnames resolution

this is my coredns configmap :

apiVersion: v1
data:
  Corefile: ".:53 {\n    errors\n    health {\n      lameduck 5s\n    }\n    ready\n
    \   log . {\n      class error\n    }\n    kubernetes cluster.local in-addr.arpa
    ip6.arpa {\n      pods insecure\n      fallthrough in-addr.arpa ip6.arpa\n    }\n
    \   prometheus :9153\n    forward . 8.8.8.8 8.8.4.4 \n    cache 30\n    loop\n
    \   reload\n    loadbalance\n}\n"
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"Corefile":".:53 {\n    errors\n    health {\n      lameduck 5s\n    }\n    ready\n    log . {\n      class error\n    }\n    kubernetes cluster.local in-addr.arpa ip6.arpa {\n      pods insecure\n      fallthrough in-addr.arpa ip6.arpa\n    }\n    prometheus :9153\n    forward . 8.8.8.8 8.8.4.4 \n    cache 30\n    loop\n    reload\n    loadbalance\n}\n"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"addonmanager.kubernetes.io/mode":"EnsureExists","k8s-app":"kube-dns"},"name":"coredns","namespace":"kube-system"}}
  creationTimestamp: "2022-06-19T17:07:02Z"
  labels:
    addonmanager.kubernetes.io/mode: EnsureExists
    k8s-app: kube-dns
  name: coredns
  namespace: kube-system
  resourceVersion: "7503127"
  selfLink: /api/v1/namespaces/kube-system/configmaps/coredns
  uid: 0735a387-6970-43ab-8490-cdf49a23f936

Thanks in advance for your answers

  • `ping: bad address 'google.com'`: the problem isn't that you can't "ping" ([ICMP](https://www.cloudflare.com/learning/ddos/glossary/internet-control-message-protocol-icmp/)). The problem is that your pod with microk8s can't resolve the host name "google.com". Q: Can you configure your pod to use [DNS](https://www.cloudflare.com/learning/dns/what-is-dns/)? For example: `microk8s enable dns`: https://microk8s.io/docs/addon-dns – paulsm4 Jun 19 '22 at 16:27
  • @paulsm4 thank you for the answer. I tried to ping with IP addresses and it works fine I have a problem with hostname resolution even DNS addon is enabled. – BOUZIDI IDRISSI Mehdi Jun 19 '22 at 17:39
  • 1) Please review the documentation: https://microk8s.io/docs/addon-dns. 2) If you haven't explicitly configured a DNS name server, then verify the pod can ping the defaults: 8.8.8.8 and 8.8.4.4. 3) See also : https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/, https://serverfault.com/a/1078739, https://stackoverflow.com/a/62678275/421195, 4) Please post back what you find. – paulsm4 Jun 19 '22 at 20:06

0 Answers0