by default, in Kubernetes 1.13 CoreDNS is installed. Can you please tell me how to make a curl in a cluster by the name of the service?
[root@master ~]# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.233.0.1 <none> 443/TCP 24h
[root@master ~]# kubectl get services --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-system coredns ClusterIP 10.233.0.3 <none> 53/UDP,53/TCP,9153/TCP 21h
tools nexus-svc NodePort 10.233.17.152 <none> 8081:31991/TCP,5000:31111/TCP,8083:31081/TCP,8082:31085/TCP 14h
[root@master ~]# kubectl describe services nexus-svc --namespace=tools
Name: nexus-svc
Namespace: tools
Labels: tools=nexus
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"tools":"nexus"},"name":"nexus-svc","namespace":"tools"},"spec"...
Selector: tools=nexus
Type: NodePort
IP: 10.233.17.152
Port: http 8081/TCP
.....
So I get the correct answer.
[root@master ~]# curl http://10.233.17.152:8081
<!DOCTYPE >
<html lang="en">
<head>
<title>Nexus Repository Manager</title>
....
And so no.
[root@master ~]# curl http://nexus-svc.tools.svc.cluster.local
curl: (6) Could not resolve host: nexus-svc.tools.svc.cluster.local; Unknown error
[root@master ~]# curl http://nexus-svc.tools.svc.cluster.local:8081
curl: (6) Could not resolve host: nexus-svc.tools.svc.cluster.local; Unknown error
Thanks.
coredns
or kubedns
are meant to resolve the service name to its clusterIP
(normal service) or correspondent Pod IP (headless service) inside the kubernetes cluster not outside. You are trying to curl the service name on the node, not inside the pod and hence it is not able to resolve the service name to its clusterIP.
YOu can go inside the pod and try following:
kubectl exec -it <pod_name> bash
nslookup nexus-svc.tools.svc.cluster.local
It will return you cluster IP and it means coredns
is working fine. If your pod has curl utility then you can also curl it using service name (but from inside the cluster only)
If you want to access the service from outside the cluster, this service already exposed as NodePort
so you can access it using:
curl http://<node_ip>:31991
Hope this helps.