<p>I have a problem with service (DNS) discovery in <strong>kubernetes 1.14</strong> version in <strong>ubuntu bionic</strong>.</p>
<p>Right now my 2 pods communicating using IP addresses. How can I enable <strong>coredns</strong> for service (DNS) discovery?</p>
<p>Here is the output of kubectl for service and pods from kube-system namespace:</p>
<pre><code>
    kubectl get pods,svc --namespace=kube-system | grep dns
    pod/coredns-fb8b8dccf-6plz2          1/1     Running            0          6d23h
    pod/coredns-fb8b8dccf-thxh6          1/1     Running            0          6d23h
    
    service/kube-dns        ClusterIP   10.96.0.10       &lt;none&gt;        53/UDP,53/TCP,9153/TCP   6d23h

</code></pre>
<h2>I have installed kubernetes on master node(ubuntu bionic machine) using below steps</h2>
<pre><code>
    apt-get update
    apt-get install     apt-transport-https     ca-certificates     curl     gnupg-agent     software-properties-common
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
    add-apt-repository    &quot;deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable&quot;
    apt-get update
    apt-get install docker-ce docker-ce-cli containerd.io
    apt-get update &amp;&amp; apt-get install -y apt-transport-https curl
    curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
    
    cat &lt;&lt;EOF &gt;/etc/apt/sources.list.d/kubernetes.list
    deb https://apt.kubernetes.io/ kubernetes-xenial main
    EOF
    
    apt-get update
    apt-get install -y kubelet kubeadm kubectl
    kubectl version
    apt-mark hold kubelet kubeadm kubectl
    kubeadm config images pull
    swapoff -a
    kubeadm init
    
    mkdir -p $HOME/.kube
    cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    chown $(id -u):$(id -g) $HOME/.kube/config
    sysctl net.bridge.bridge-nf-call-iptables=1
    kubectl apply -f &quot;https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')&quot;
    kubectl get pods --all-namespaces

</code></pre>
<h3>This is on worker node</h3>
<pre><code>    Docker is already installed, so directly installing kubernetes on worker node
    apt-get update &amp;&amp; apt-get install -y apt-transport-https curl
    curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
    cat &lt;&lt;EOF &gt;/etc/apt/sources.list.d/kubernetes.list
    deb https://apt.kubernetes.io/ kubernetes-xenial main
    EOF
    
    apt-get update
    apt-get install -y kubelet kubeadm kubectl
    kubectl version
    apt-mark hold kubelet kubeadm kubectl
    swapoff -a
    Now joined worker node to master

</code></pre>
<h2>Answer:-</h2>
<p>I think everything was setup correctly by default, There was a misunderstanding by me that I can call a server running in one pod from another pod using the container name and port which I have specified in spec, but instead I should use service name and port.</p>
<h2>Below is my deployment spec and service spec:-</h2>
<h3>Deployment spec:-</h3>
<pre><code>    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: node-server1-deployment
    spec:
      replicas: 1
      template:
    metadata:
      labels:
        app: node-server1
    spec:
      hostname: node-server1
      containers:
      - name: node-server1
        image: bvenkatr/node-server1:1
        ports:
        - containerPort: 5551
</code></pre>
<h3>Service spec:</h3>
<pre><code>    kind: Service
    apiVersion: v1
    metadata:
      name: node-server1-service
    spec:
      selector:
         app: node-server1
      ports:
      - protocol: TCP
        port: 5551
</code></pre>

bvenkatr
<blockquote>
  <p>As of Kubernetes v1.12, CoreDNS is the recommended DNS Server, replacing kube-dns. In Kubernetes, CoreDNS is installed with the following default Corefile configuration:</p>
</blockquote>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
data:
  Corefile: |
    .:53 {
        errors
        health
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           upstream
           fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        proxy . /etc/resolv.conf
        cache 30
        loop
        reload
        loadbalance
    }
</code></pre>

<p>More info yo can find <a href="https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/" rel="nofollow noreferrer">here</a>. </p>

<p>You can verify your env by running:</p>

<pre><code>kubectl get cm coredns -n kube-system -o yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
</code></pre>

<p>and:
kubeadm config view
dns:
  type: CoreDNS</p>

<p>during kubeadm init you should noticed:</p>

<pre><code>[addons] Applied essential addon: CoreDNS
</code></pre>

<p>If you are moving from kube-dns to CoreDNS, make sure to set the CoreDNS <code>feature gate</code> to <strong>true</strong> during an upgrade. For example, here is what a v1.11.0 upgrade would look like:
<code>kubeadm upgrade apply v1.11.0 --feature-gates=CoreDNS=true</code></p>

<blockquote>
  <p>In Kubernetes version 1.13 and later the CoreDNS feature gate is removed and CoreDNS is used by default. More information <a href="https://kubernetes.io/docs/tasks/administer-cluster/coredns/" rel="nofollow noreferrer">here</a>.</p>
</blockquote>

<p>You can see if your coredns pod is working properly by running:</p>

<pre><code>kubectl logs &lt;your coredns pod&gt; -n kube-system
.:53
2019-05-02T13:32:41.438Z [INFO] CoreDNS-1.3.1
CoreDNS-1.3.1
.
.
</code></pre>
