Wanted to communicate the pod with cluster to run some kubectl commands

1/16/2020

I am trying to run kubectl commands from inside pod to communicate with cluster to delete pod with --graceperiod=0 through a monitoring script after holding the pod in delete state through extended grace period to hold the pod deletion with prestop hook. But was not able to connect to cluster IP and neither able to ping the pod itself.

[root@pod01 /]# kubectl exec dnsutils cat /etc/resolv.conf
    Unable to connect to the server: dial tcp 196.19.0.1:443: connect: network is unreachable
[root@pod01 /]#   cat /etc/resolv.conf
    nameserver 196.19.0.2
    search namespace.svc.cluster.local svc.cluster.local cluster.local
    options ndots:5
[root@pod01 /]# kubectl exec -ti dnsutils -- nslookup kubernetes.default
    Unable to connect to the server: dial tcp 196.19.0.1:443: connect: network is unreachable
[root@pod01 /]# ping namespace.svc.cluster.local
    ping: namespace.svc.cluster.local: Name or service not known
[root@pod01 /]# ^C
[root@sailpointiiq-ilab03-task-7c69b77658-gkz5x /]# nslookup Cluster_IP
    bash: nslookup: command not found
[root@sailpointiiq-ilab03-task-7c69b77658-gkz5x /]# ping Cluster_IP port
    connect: Network is unreachable
[root@pod01 /]# cat /etc/hosts
  # Kubernetes-managed hosts file.
  127.0.0.1       localhost
  ::1     localhost ip6-localhost ip6-loopback
  fe00::0 ip6-localnet
  fe00::0 ip6-mcastprefix
  fe00::1 ip6-allnodes
  fe00::2 ip6-allrouters
  196.18.9.8    pod01
[root@pod01 /]# ping 196.18.9.8
    connect: Network is unreachable
[root@pod01 /]# nslookup 196.18.9.8
    bash: nslookup: command not found
[root@pod01 /]# ping localhost
    PING localhost (127.0.0.1) 56(84) bytes of data.
    64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.014 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.013 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.015 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.015 ms
    ^C
    --- localhost ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3065ms

any help.? I am not able to run any of these to get the pod interact outside and I am on CentOS 7

-- lucifer758
kubernetes

1 Answer

2/10/2020

The network components are down in a pod with terminated state and won't be able to communicate with cluster.

-- lucifer758
Source: StackOverflow