how do i find out port on the host belongs to which port or service

7/13/2019

I setup a kubernetes by kubeadm and everything is ok. I just get a whim: how do I find out some pods or services dependent on the ports which started by kube-proxy on the localhost ?

[root@k8s-node1 ~]# netstat -tnlp|grep 80
tcp        0      0 172.19.5.38:8080        0.0.0.0:*               LISTEN      13918/kube-proxy    
tcp        0      0 172.19.5.38:80          0.0.0.0:*               LISTEN      13918/kube-proxy 

I want to know which pod or service the 80 or 8080 belongs to ? assume i already forget which yaml file i submitted to the kubernetes.

thx

-- adrian ding
kubernetes

1 Answer

7/16/2019

You can always describe objects in Kubernetes.

For example if you want to check what ports are using on your services you have to use command below.

$ kubectl get svc -o wide --all-namespaces
NAMESPACE     NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE     SELECTOR
default       kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP                  3m39s   <none>
kube-system   kube-dns     ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   3m38s   k8s-app=kube-dns

If you want to check Ports from deployment you can use kubectl describe deploy <deploymentName> and grep it for context. It will work for Pod also

$ kubectl describe deploy <deploymentName>| grep Port
    Port:         80/TCP
    Host Port:    0/TCP

In addition, if you dont remember what yaml has been used to create Pod/Deployment you can use edit to check.

$ kubectl edit deployment <deploymentName> -o yaml

It will show YAML file (in VI) which was deployment based on and some additional statuses.

Let me know if this help or if you have any additional questions.

-- PjoterS
Source: StackOverflow